処理の実行
最新のLambda関数のハッシュ値(SHA256)を取得します。
コマンド:
LAMBDA_FUNCTION_CODE_SHA256=$( \
aws lambda get-function \
--function-name ${LAMBDA_FUNCTION_NAME} \
--query 'Configuration.CodeSha256' \
--output text \
) \
&& echo ${LAMBDA_FUNCTION_CODE_SHA256}
結果(例):
kvDJwZXAa523hRVRcBZ04vGafGj8eKQN8u3uzNHtHW0=
Lambda関数のバージョンを作成します。
変数の確認:
cat << END
# LAMBDA_FUNCTION_NAME:"handson-cli-lambda-version-function"
LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME}"
# LAMBDA_FUNCTION_VERSION_DESCRIPTION:"first version of handson-cli-lambda-version-function"
LAMBDA_FUNCTION_VERSION_DESCRIPTION="${LAMBDA_FUNCTION_VERSION_DESCRIPTION}"
END
コマンド:
aws lambda publish-version \
--function-name ${LAMBDA_FUNCTION_NAME} \
--description "${LAMBDA_FUNCTION_VERSION_DESCRIPTION}"
結果(例):
{
"FunctionName": "handson-cli-lambda-version-function",
"FunctionArn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:handson-cli-lambda-version-function",
"Runtime": "python3.8",
"Role": "arn:aws:iam::XXXXXXXXXXXX:role/handson-cli-lambda-version-role",
"Handler": "handson-cli-lambda-version-function.handler",
"CodeSize": 256,
"Description": "function for handson-cli-lambda-version."
"Timeout": 3,
"MemorySize": 128,
"LastModified": "2021-01-29T01:23:45.678+0000",
"CodeSha256": "kvDJwZXAa523hRVRcBZ04vGafGj8eKQN8u3uzNHtHW0=",
"Version": "1",
"TracingConfig": {
"Mode": "PassThrough"
},
"RevisionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"State": "Active",
"LastUpdateStatus": "Successful",
"PackageType": "Zip"
}
完了確認
「Lambda関数"handson-cli-lambda-version-function"に最新版と同じハッシュ値のバージョンが存在する。」ことを確認します。
コマンド:
aws lambda list-versions-by-function \
--function-name ${LAMBDA_FUNCTION_NAME} \
--query "Versions[? CodeSha256 == \`${LAMBDA_FUNCTION_CODE_SHA256}\`
&& Version != \`\$LATEST\` \
].Version" \
--output text
結果(例):