Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/techjacker/go-serverless-api
Boilerplate Golang API with AWS Severless Application Model (SAM) Deployment to AWS Lambda & API Gateway
https://github.com/techjacker/go-serverless-api
aws-lambda aws-sam golang serverless
Last synced: 4 months ago
JSON representation
Boilerplate Golang API with AWS Severless Application Model (SAM) Deployment to AWS Lambda & API Gateway
- Host: GitHub
- URL: https://github.com/techjacker/go-serverless-api
- Owner: techjacker
- License: mit
- Created: 2018-04-15T14:01:51.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-18T09:27:45.000Z (almost 7 years ago)
- Last Synced: 2024-06-19T23:10:20.712Z (8 months ago)
- Topics: aws-lambda, aws-sam, golang, serverless
- Language: Go
- Homepage: https://andrewgriffithsonline.com/blog/180412-migrate-go-api-to-serverless-under-10-mins
- Size: 15.6 KB
- Stars: 10
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/techjacker/go-serverless-api)
[](https://goreportcard.com/report/github.com/techjacker/go-serverless-api)# go-serverless-api
- Boilerplate Golang API
- AWS Severless Application Model (SAM) Deployment to AWS Lambda & API Gateway-----------------------------------------------------------
## Deploy to AWS#### 1. Build and package into a zip
```Shell
$ make bundle-lambda
```#### 2. Upload zip to AWS S3 & create updated SAM template (`packaged-template.yaml`)
```shell
$ aws s3 mb s3://my-bucket$ aws cloudformation package \
--template-file template.yaml \
--s3-bucket my-bucket \
--output-template-file packaged-template.yaml
```#### 2. Deploy to AWS Lambda & API Gateway with updated SAM template
```shell
$ aws cloudformation deploy \
--template-file packaged-template.yaml \
--stack-name go-serverless-api-stack \
--capabilities CAPABILITY_IAM
```#### 3. Test
AWS API Gateway addresses take the following format.
```
https://.execute-api..amazonaws.com/
``````Shell
$ aws apigateway get-rest-apis
{
"items": [
{
"id": "0qu18x8pyd",
"name": "go-serverless-api-stack",
"createdDate": 1523987269,
"version": "1.0",
"apiKeySource": "HEADER",
"endpointConfiguration": {
"types": [
"EDGE"
]
}
}
]
}
``````Shell
$ curl -s https://0qu18x8pyd.execute-api.eu-west-1.amazonaws.com/Stage/healthz
ok
$ curl -s https://0qu18x8pyd.execute-api.eu-west-1.amazonaws.com/Prod/healthz
ok
```#### 4. Delete Stack
```shell
$ aws cloudformation delete-stack \
--stack-name go-serverless-api-stack
```----------------------------- ------------------------------
## Local Development
#### Build & Run API
```shell
$ make run
```#### Manually call APi
```shell
$ make test-run
```-----------------------------------------------------------
## Tests
```
$ go test ./...
```