出来合いのものがある!これは便利
https://github.com/keithrozario/Klayers
| LAMBDA_TASK_ROOT | lambda実行ディレクトリのパス。画像などもUPLOADできるので読み込みに利用できる |
| PYTHON_PATH | 実行時のライブラリ検索パス。いじった場合はlayerが読み込めなくなるので注意 |
lib/*.jarとなるようにアーカイブする
~java/lib/hoge.jar cd java zip -r /var/tmp/java_layer.zip lib/*
https://github.com/chaingng/serverless_python_tutorial
| request |
| pytz |
https://qiita.com/ekzemplaro/items/7dc187885dffe0be6341
aws lambda invoke --function-name simple_wget output.txt
aws lambda update-function-configuration --function-name simple_wget --environment "Variables={BUCKET=my-bucket,KEY=file.txt}"
aws lambda get-function-configuration --function-name simple_wget
1. イベントを定義(aws_cloudwatch_event_rule) 2. イベントに対して実行する関数をターゲット指定(aws_cloudwatch_event_target)
https://qiita.com/bowz_standard/items/c1856821be19e660f06f
https://dev.classmethod.jp/articles/terraform-lambda-deployment/
https://qiita.com/ktsujichan/items/c0804f155c2cf1962ed3
AWSLambdaVPCAccessExecutionRole
The provided execution role does not have permissions to call CreateNetworkInterface on EC2
かつてはENIをコールドスタートしたり、その分ENI&サブネットのIPを消費したりのデメリットがあったが、2019年に解消された。
https://github.com/lambci/docker-lambda
# Test a `lambda_handler` function in `lambda_function.py` with an empty event on Python 3.8 docker run --rm -v "$PWD":/var/task:ro,delegated lambci/lambda:python3.8 lambda_function.lambda_handler
CentOS7のDockerだとdelegatedオプションがサポートされてないバージョンなので外すこと!
pip install python-lambda-local
echo '{"key1": "test"}' > event.json
python-lambda-local -f lambda_handler lambda_function.py event.json
lambda以外にも対応している
http://momota.github.io/blog/2018/11/05/serverless-framework/
| S3へのput |
| SESへの着信 |
| Amazon SNS からの通知の送信 |
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:*"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": "ec2:Describe*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateSnapshot",
"ec2:DeleteSnapshot",
"ec2:CreateTags",
"ec2:ModifySnapshotAttribute",
"ec2:ResetSnapshotAttribute"
],
"Resource": [
"*"
]
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
},
{
"Effect": "Allow",
"Action": "es:ESHttpPost",
"Resource": "arn:aws:es:*:*:*"
}
]
}
https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups/ https://serverlesscode.com/post/lambda-schedule-ebs-snapshot-backups-2/
上記ページに従い実行した。backupというキーを設定したインスタンスのEBSのSnapshotを作成する。PartIIでは削除日を指定してSnapshotを作る機能が追加されている。
まずはlambdaに対しての信頼関係を定義して、lambaで実行すると ebs-backup-worker が付与されるようにする。 ebs-backup-workerには必要なポリシーを付与する。
https://qiita.com/hoto17296/items/5f17af9b5261b9f219ee