AWS Lambda Beginner

AWS Lambda Beginner

Tags
AWS
Engineering
Lambda
Created
Nov 8, 2022 01:44 AM
Edited
Nov 7, 2022
Description
Some basic notes of AWS Lambda

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

Source