项目作者: techjacker

项目描述 :
Boilerplate Golang API with AWS Severless Application Model (SAM) Deployment to AWS Lambda & API Gateway
高级语言: Go
项目地址: git://github.com/techjacker/go-serverless-api.git
创建时间: 2018-04-15T14:01:51Z
项目社区:https://github.com/techjacker/go-serverless-api

开源协议:MIT License

下载


Build Status
Go Report Card

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

  1. $ make bundle-lambda

2. Upload zip to AWS S3 & create updated SAM template (packaged-template.yaml)

  1. $ aws s3 mb s3://my-bucket
  2. $ aws cloudformation package \
  3. --template-file template.yaml \
  4. --s3-bucket my-bucket \
  5. --output-template-file packaged-template.yaml

2. Deploy to AWS Lambda & API Gateway with updated SAM template

  1. $ aws cloudformation deploy \
  2. --template-file packaged-template.yaml \
  3. --stack-name go-serverless-api-stack \
  4. --capabilities CAPABILITY_IAM

3. Test

AWS API Gateway addresses take the following format.

  1. https://<api-rest-id>.execute-api.<your-aws-region>.amazonaws.com/<api-stage>
  1. $ aws apigateway get-rest-apis
  2. {
  3. "items": [
  4. {
  5. "id": "0qu18x8pyd",
  6. "name": "go-serverless-api-stack",
  7. "createdDate": 1523987269,
  8. "version": "1.0",
  9. "apiKeySource": "HEADER",
  10. "endpointConfiguration": {
  11. "types": [
  12. "EDGE"
  13. ]
  14. }
  15. }
  16. ]
  17. }
  1. $ curl -s https://0qu18x8pyd.execute-api.eu-west-1.amazonaws.com/Stage/healthz
  2. ok
  3. $ curl -s https://0qu18x8pyd.execute-api.eu-west-1.amazonaws.com/Prod/healthz
  4. ok

4. Delete Stack

  1. $ aws cloudformation delete-stack \
  2. --stack-name go-serverless-api-stack

Local Development

Build & Run API

  1. $ make run

Manually call APi

  1. $ make test-run

Tests

  1. $ go test ./...