処理の実行
LambdaレイヤーバージョンのARNを取得します。
コマンド:
LAMBDA_LAYER_VERSION_ARN=$( \
aws lambda list-layer-versions \
--layer-name ${LAMBDA_LAYER_NAME} \
--query "LayerVersions[?Version == \`${LAMBDA_LAYER_VERSION}\`].LayerVersionArn" \
--output text \
) \
&& echo ${LAMBDA_LAYER_VERSION_ARN}
結果(例):
arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:layer:handson-cli-lambda-basic-layer:1
レイヤー文字列を生成します。
変数の設定:
ARRAY_LAMBDA_LAYER_VERSION_ARNS="${LAMBDA_LAYER_VERSION_ARN}" \
&& echo ${ARRAY_LAMBDA_LAYER_VERSION_ARNS}
結果(例):
arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:layer:handson-cli-lambda-basic-layer:1
Lambda関数のレイヤー設定を変更します。
変数の確認:
cat << ETX
# LAMBDA_FUNCTION_NAME:"handson-cli-lambda-basic-layer-function"
LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME}"
# ARRAY_LAMBDA_LAYER_VERSION_ARNS:"arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:layer:handson-cli-lambda-basic-layer:1"
ARRAY_LAMBDA_LAYER_VERSION_ARNS="${ARRAY_LAMBDA_LAYER_VERSION_ARNS}"
ETX
コマンド:
aws lambda update-function-configuration \
--function-name ${LAMBDA_FUNCTION_NAME} \
--layers ${ARRAY_LAMBDA_LAYER_VERSION_ARNS}
結果(例):
{
"Layers": [
{
"CodeSize": 459,
"Arn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:layer:handson-cli-lambda-basic-layer:1"
}
],
"FunctionName": "handson-cli-lambda-basic-layer-function",
"FunctionArn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:handson-cli-lambda-basic-layer-function",
"Runtime": "python3.8",
"Role": "arn:aws:iam::XXXXXXXXXXXX:role/handson-cli/handson-cli-lambda-role",
"Handler": "handson-cli-lambda-basic-layer-function.lambda_handler",
"CodeSize": 280,
"Description": "function for handson-cli-lambda.",
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-02-18T01:23:45.678+0000",
"CodeSha256": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Version": "$LATEST",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
完了確認
「Lambda関数"handson-cli-lambda-basic-layer-function"の更新に成功している。」ことを確認します。
コマンド:
aws lambda get-function \
--function-name ${LAMBDA_FUNCTION_NAME} \
--query 'Configuration.LastUpdateStatus' \
--output text
結果(例):
「Lambda関数"handson-cli-lambda-basic-layer-function"の設定にレイヤー設定が存在する。」ことを確認します。
コマンド:
aws lambda get-function \
--function-name ${LAMBDA_FUNCTION_NAME} \
--query "Configuration.Layers[].Arn" \
--output text
結果(例):
arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:layer:handson-cli-lambda-basic-layer:1