A preliminary setup & skeleton to kickstart with local AWS Lambda development in Go.
It's a mixture of Serverless and SAM Local. Using the former as deployment framework due to its wider range of features, bigger community and its language/provider agnostic nature. And the latter only for offline Lambda + API Gateway simulation using a docker container.
- Working Golang environment, preferably with
dep
- Working Node environment to install dependencies
- Working Docker machine to invoke lambdas locally
# Install npm dependencies
npm install -g serverless aws-sam-local
# Clone the skeleton
git clone https://github.com/sepehr/serverless-offline-go.git golambda
# Compile the sample lambdas
cd golambda/
make
# Invoke the "apigw" sample lambda locally at localhost:3000
sam local start-api
# Invoke the "Vanilla" sample lambda locally using a custom event payload file
sam local invoke "Vanilla" -e path/to/event.json
# Or using an event payload from the stdin
echo '{"message": "Hey, are you there?" }' | sam local invoke "Vanilla"
# Deploy to AWS
# Requires authenticated aws-cli setup in place
sls deploy -s dev
- Renaming lambdas requires you to update the names in
Makefile
,serverless.yml
andtemplate.yml
. - Updating APIGW endpoints requires you to update both
serverless.yml
andtemplate.yml
(if you want it offline).
- Included
serverless.yml
definition is originated from the officialaws-go-dep
template provided by the serverless framework with just a minimal update to add a APIGW endpoint. - One of the template sample lambdas has been replaced by a more useful one that can work with APIGW.
- Sample lambdas have been organized into
cmd/
directory as per common practice.