sigh-man / go-lambda-example

Example AWS Lambda function in Go and SAM

Home Page:https://sbstjn.com/golang-lambda-with-aws-sam-serverless-application-model.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lambda Go Example

Dependecies

$ > 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

# Build binary
$ > make build

# Test Go Code
$ > make test

Deploy

Create .env

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

$ > brew install awscli

Command

# Create S3 Bucket
$ > make configure

# Upload data to S3 Bucket
$ > make package

# Deploy CloudFormation Stack
$ > make deploy

Usage

$ > 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}}

About

Example AWS Lambda function in Go and SAM

https://sbstjn.com/golang-lambda-with-aws-sam-serverless-application-model.html


Languages

Language:Go 74.3%Language:Makefile 23.5%Language:Shell 2.3%