trust-policy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
deploy.ps1
deploy.ps1
#メモリはデフォルト
#Layer不要の場合
$NAME = "LAMBDANAME"
#Deploy用
Write-Output "-------------------------------------------------------------"
$TIMEOUT = 60
$REGION = "us-east-1"
$ROLENAME = "ROLLNAME"
$HANDLERPATH = "main.FUNCTIONNAME"
$PERMISSIONARN = "Copy&Paste permission arn"
$compress = @{
Path = ".\main.py"
CompressionLevel = "Fastest"
DestinationPath = ".\$NAME.zip"
}
Compress-Archive @compress
$ARN = (aws iam create-role --role-name $ROLENAME -assume-role-policy-document file://.\trust-policy.json --permissions-boundary $PERMISSIONARN| ConvertFrom-Json).Role.Arn
aws lambda create-function `
--function-name $NAME `
--runtime python3.9 `
--role $ARN `
--handler $HANDLERPATH `
--timeout $TIMEOUT `
--zip-file fileb://.\$NAME.zip `
--region $REGION `
--output json
Write-Output "-------------------------------------------------------------"
#Update用
# aws lambda update-function-code -function-name $NAME --zip-file fileb://.\$NAME.zip `
#確認PAUSE
PAUSE
Remove-Item .\$NAME.zip
レイヤーもCLIで追加できるようにしたら、次はlambda-uploader
の方が簡単そうなのでそっちに切り替える。