Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sbstjn/go-lambda-example
Example AWS Lambda function in Go and SAM
https://github.com/sbstjn/go-lambda-example
apigateway cloudformation golang lambda sam serverless
Last synced: 3 months ago
JSON representation
Example AWS Lambda function in Go and SAM
- Host: GitHub
- URL: https://github.com/sbstjn/go-lambda-example
- Owner: sbstjn
- Created: 2018-01-19T21:17:41.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-18T02:20:22.000Z (over 6 years ago)
- Last Synced: 2024-05-02T00:55:38.646Z (10 months ago)
- Topics: apigateway, cloudformation, golang, lambda, sam, serverless
- Language: Go
- Homepage: https://sbstjn.com/golang-lambda-with-aws-sam-serverless-application-model.html
- Size: 59.6 KB
- Stars: 50
- Watchers: 2
- Forks: 16
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Lambda Go Example
## Dependecies
```bash
$ > go get github.com/aws/aws-lambda-go/events
$ > go get github.com/aws/aws-lambda-go/lambda
$ > go get github.com/stretchr/testify/assert
```## Build
```bash
# Build binary
$ > make build# Test Go Code
$ > make test
```## Deploy
### Create .env
```bash
AWS_ACCOUNT_ID=1234567890
AWS_BUCKET_NAME=your-bucket-name-for-cloudformation-package-data
AWS_STACK_NAME=your-cloudformation-stack-name
AWS_REGION=us-west-1
```### Install AWS CLI
```bash
$ > brew install awscli
```### Command
```bash
# Create S3 Bucket
$ > make configure# Upload data to S3 Bucket
$ > make package# Deploy CloudFormation Stack
$ > make deploy
```## Usage
```bash
$ > make outputs[
{
"OutputKey": "URL",
"OutputValue": "https://random-id.execute-api.us-west-1.amazonaws.com/Prod",
"Description": "URL for HTTPS Endpoint"
}
]$ > curl https://random-id.execute-api.us-west-1.amazonaws.com/Stage/people
{"data":[{"id":"d1","name":"Anton","age":31},{"id":"c2","name":"Frank","age":28},{"id":"b1","name":"Horst","age":42}]}
$ > curl https://random-id.execute-api.us-west-1.amazonaws.com/Stage/person/b1
{"data":{"id":"b1","name":"Horst","age":42}}
```