michimani.net

AWS CLI で Lambda 関数のランタイムを一括で更新する

2022-04-16

AWS からとあるメールが届いていました。

We are contacting you as we have identified that your AWS Account currently has one or more Lambda functions using Python 3.6 runtime.

We are ending support for Python 3.6 in AWS Lambda. This follows Python 3.6 End-Of-Life (EOL) reached on December 23, 2021 [1].

As described in the Lambda runtime support policy [2], end of support for language runtimes in Lambda happens in two stages. Starting July 18, 2022, Lambda will no longer apply security patches and other updates to the Python 3.6 runtime used by Lambda functions, and functions using Python 3.6 will no longer be eligible for technical support. In addition, you will no longer be able to create new Lambda functions using the Python 3.6 runtime. Starting August 17, 2022, you will no longer be able to update existing functions using the Python 3.6 runtime.

We recommend that you upgrade your existing Python 3.6 functions to Python 3.9 before August 17, 2022.

Python 3.6 の EOL に従って、 Lambda でランタイムに Python 3.6 を使っている関数は 2022年8月17日 以降は更新できなくなるというものです。
個人の環境なので特に問題ないが更新できなくなると困るので、とりあえず全部 Python 3.9 に更新してしまいます。

Python 3.6 を使っている Lambda 関数を特定する

まずは Python 3.6 をランタイムに使っている Lambda 関数を特定します。下記 AWS CLI のコマンドを実行して、各リージョンに対して対象の Lambda 関数が存在するかどうか調べます。

for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
    echo "Lambda function in ${region} with Python 3.6 runtime"
    aws lambda list-functions \
        --query 'Functions[?contains(to_string(Runtime),`python3.6`)].FunctionArn' \
        --region "${region}"
done

結果。

Lambda function in eu-north-1 with Python 3.6 runtime
[]
Lambda function in ap-south-1 with Python 3.6 runtime
[]
Lambda function in eu-west-3 with Python 3.6 runtime
[]
Lambda function in eu-west-2 with Python 3.6 runtime
[]
Lambda function in eu-west-1 with Python 3.6 runtime
[]
Lambda function in ap-northeast-3 with Python 3.6 runtime
[]
Lambda function in ap-northeast-2 with Python 3.6 runtime
[]
Lambda function in ap-northeast-1 with Python 3.6 runtime
[
    "arn:aws:lambda:ap-northeast-1:000000000000:function:StartStopEc2",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:KeyakizakaBlogUpdateCheck",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:ResizeS3BacketOperation",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:DeployTestDev",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:toSlack",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:iot1click_onclick_sms_20190710142349",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:HinatazakaBlogUpdateCheck",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:DeployTest",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:PutItemToDynamoDbFromJson",
    "arn:aws:lambda:ap-northeast-1:000000000000:function:iot1click_onclick_sms_20190710143217"
]
Lambda function in sa-east-1 with Python 3.6 runtime
[]
Lambda function in ca-central-1 with Python 3.6 runtime
[]
Lambda function in ap-southeast-1 with Python 3.6 runtime
[]
Lambda function in ap-southeast-2 with Python 3.6 runtime
[]
Lambda function in eu-central-1 with Python 3.6 runtime
[]
Lambda function in us-east-1 with Python 3.6 runtime
[]
Lambda function in us-east-2 with Python 3.6 runtime
[]
Lambda function in us-west-1 with Python 3.6 runtime
[]
Lambda function in us-west-2 with Python 3.6 runtime
[
    "arn:aws:lambda:us-west-2:000000000000:function:iot1click_onclick_email_20190710142349",
    "arn:aws:lambda:us-west-2:000000000000:function:iot1click_onclick_email_20190710143217",
    "arn:aws:lambda:us-west-2:000000000000:function:iot1click_onclick_sms_20190705234051"
]

そこそこありました。

まとめて更新する

3.6 → 3.9 のアップデートなので特に気にするところはなさそうなので、且つ個人の環境なのでとりあえず動作確認は置いておいてランタイムだけ更新します。

下記 AWS CLI コマンドでまとめて更新します。

for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
    for arn in $(aws lambda list-functions \
        --query 'Functions[?contains(to_string(Runtime),`python3.6`)].FunctionArn' \
        --region "${region}" \
        --output text); do
        echo "update ${arn}..."
        aws lambda update-function-configuration \
            --function-name "${arn}" \
            --runtime 'python3.9' \
            --region "${region}" \
            --query 'Runtime'
    done
done

結果。

update arn:aws:lambda:ap-northeast-1:000000000000:function:StartStopEc2...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:KeyakizakaBlogUpdateCheck...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:ResizeS3BacketOperation...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:DeployTestDev...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:toSlack...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:iot1click_onclick_sms_20190710142349...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:HinatazakaBlogUpdateCheck...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:DeployTest...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:PutItemToDynamoDbFromJson...
"python3.9"
update arn:aws:lambda:ap-northeast-1:000000000000:function:iot1click_onclick_sms_20190710143217...
"python3.9"
update arn:aws:lambda:us-west-2:000000000000:function:iot1click_onclick_email_20190710142349...
"python3.9"
update arn:aws:lambda:us-west-2:000000000000:function:iot1click_onclick_email_20190710143217...
"python3.9"
update arn:aws:lambda:us-west-2:000000000000:function:iot1click_onclick_sms_20190705234051...
"python3.9"

一応再確認

for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
    echo "Lambda function in ${region} with Python 3.6 runtime"
    aws lambda list-functions \
        --query 'Functions[?contains(to_string(Runtime),`python3.6`)].FunctionArn' \
        --region "${region}"
done

結果。

Lambda function in eu-north-1 with Python 3.6 runtime
[]
Lambda function in ap-south-1 with Python 3.6 runtime
[]
Lambda function in eu-west-3 with Python 3.6 runtime
[]
Lambda function in eu-west-2 with Python 3.6 runtime
[]
Lambda function in eu-west-1 with Python 3.6 runtime
[]
Lambda function in ap-northeast-3 with Python 3.6 runtime
[]
Lambda function in ap-northeast-2 with Python 3.6 runtime
[]
Lambda function in ap-northeast-1 with Python 3.6 runtime
[]
Lambda function in sa-east-1 with Python 3.6 runtime
[]
Lambda function in ca-central-1 with Python 3.6 runtime
[]
Lambda function in ap-southeast-1 with Python 3.6 runtime
[]
Lambda function in ap-southeast-2 with Python 3.6 runtime
[]
Lambda function in eu-central-1 with Python 3.6 runtime
[]
Lambda function in us-east-1 with Python 3.6 runtime
[]
Lambda function in us-east-2 with Python 3.6 runtime
[]
Lambda function in us-west-1 with Python 3.6 runtime
[]
Lambda function in us-west-2 with Python 3.6 runtime
[]

さようなら、 Python 3.6 👋

注意点


comments powered by Disqus