When to use
- Run for up to 15 mins per invocation β short program, such as event-driven workloads
- Donβt want to manage servers and donβt need to manager servers
Other alternatives: but you need to manage your own instance: EC2, ELB
Cost
- Based on compute time
How to deploy
Two types of deployment packages: zip and image. Here, I only care about scalable solutions.
zip
AWS CLI to Lambda
go get github.com/aws/aws-lambda-go/lambda
GOOS=linux CGO_ENABLED=0 go build main.go
zip function.zip main
aws lambda update-function-code --function-name my-function --zip-file fileb://function.zip
AWS CLI β S3 β Lambda
go get github.com/aws/aws-lambda-go/lambda
GOOS=linux CGO_ENABLED=0 go build main.go
aws s3 cp local_path s3_uri
aws lambda update-function-code --function-name my-function --s3-bucket s3_bucket --s3-key s3_key
Most of the time, you will use the build tool, but underlying steps should look like the codes above.
Container image
TBD
How to test
Sync
aws lambda invoke --function-name my-function --payload '{ "key": "value" }' response.json
Async
aws lambda invoke \
--function-name my-function \
--invocation-type Event \
--cli-binary-format raw-in-base64-out \
--payload '{ "key": "value" }' response.json
InvocationConcurrencyError Handling