Open5
LocalStackメモ

docker-compose.yml
version: "3.8"
services:
localstack:
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
- DEBUG=${DEBUG-}
- PERSISTENCE=${PERSISTENCE-}
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"

とりあえず起動確認
aws --endpoint-url=http://localhost:4566 lambda list-functions
{
"Functions": []
}

AWSのドキュメントに従って関数を作る
index.js
exports.handler = async function(event, context) {
console.log("ENVIRONMENT VARIABLES\n" + JSON.stringify(process.env, null, 2))
console.log("EVENT\n" + JSON.stringify(event, null, 2))
return context.logStreamName
}
デプロイの準備
zip function.zip index.js

Lambda関数を作る
aws --endpoint-url=http://localhost:4566 lambda create-function --function-name my-function \
--zip-file fileb://function.zip --handler index.handler --runtime nodejs16.x \
--role cool-stacklifter
Lambda関数ができてる
aws --endpoint-url=http://localhost:4566 lambda list-functions
{
"Functions": [
{
"FunctionName": "my-function",
"FunctionArn": "arn:aws:lambda:ap-northeast-1:000000000000:function:my-function",
"Runtime": "nodejs16.x",
"Role": "cool-stacklifter",
"Handler": "index.handler",
"CodeSize": 322,
"Description": "",
"Timeout": 3,
"LastModified": "2022-11-27T02:22:57.902+0000",
"CodeSha256": "+i8gpEvu/VXkhGnmhrSSMKxanSSdOxnBo4Bj8udS5l0=",
"Version": "$LATEST",
"VpcConfig": {},
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "2000206c-adb0-45cc-841f-1e846d97effd",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip",
"Architectures": [
"x86_64"
]
}
]
}

Lambda関数の実行
aws --endpoint-url=http://localhost:4566 lambda invoke --function-name my-function out --log-type Tail