0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Amazon Lambda デプロイ&アップデート用のスクリプト(PowerShell)のテンプレ作ってみた

Last updated at Posted at 2022-05-27
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の方が簡単そうなのでそっちに切り替える。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?