Lambda関数"handson-cli-lambda-function_basic-function"の設定(環境変数)を更新します。
手順に必要な設定値を変数に格納をします。
0. リージョンの指定
リージョンを指定します。
環境変数の設定 export AWS_DEFAULT_REGION='ap-northeast-1'
環境変数の設定
export AWS_DEFAULT_REGION='ap-northeast-1'
1. Lambda関数名
Lambda関数名を指定します。
変数の設定: LAMBDA_FUNCTION_NAME='handson-cli-lambda-function_basic-function'
変数の設定:
LAMBDA_FUNCTION_NAME='handson-cli-lambda-function_basic-function'
2. Lambda関数の環境変数の設定文字列
Lambda関数の環境変数の設定文字列を指定します。
変数の設定: STRING_LAMBDA_FUNCTION_ENVIRONMENT='Variables={ENV=product}'
STRING_LAMBDA_FUNCTION_ENVIRONMENT='Variables={ENV=product}'
各変数に正しい設定値が格納されていることを確認しながら保存します。
変数の確認: cat << END # 0. AWS_DEFAULT_REGION:"ap-northeast-1" AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" # 1. LAMBDA_FUNCTION_NAME:"handson-cli-lambda-function_basic-function" LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME}" # 2. STRING_LAMBDA_FUNCTION_ENVIRONMENT:"Variables={ENV=product}" STRING_LAMBDA_FUNCTION_ENVIRONMENT="${STRING_LAMBDA_FUNCTION_ENVIRONMENT}" END
変数の確認:
cat << END # 0. AWS_DEFAULT_REGION:"ap-northeast-1" AWS_DEFAULT_REGION="${AWS_DEFAULT_REGION}" # 1. LAMBDA_FUNCTION_NAME:"handson-cli-lambda-function_basic-function" LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME}" # 2. STRING_LAMBDA_FUNCTION_ENVIRONMENT:"Variables={ENV=product}" STRING_LAMBDA_FUNCTION_ENVIRONMENT="${STRING_LAMBDA_FUNCTION_ENVIRONMENT}" END
下段の変数が入っていない、もしくは上段と同等の値が入っていない場合は、それぞれの手順番号に戻って変数の設定を行います。
Lambda関数の環境変数を変更します。
変数の確認: cat << ETX # LAMBDA_FUNCTION_NAME:"handson-cli-lambda-function_basic-function" LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME}" # STRING_LAMBDA_FUNCTION_ENVIRONMENT:"Variables={ENV=product}" STRING_LAMBDA_FUNCTION_ENVIRONMENT="${STRING_LAMBDA_FUNCTION_ENVIRONMENT} " ETX コマンド: aws lambda update-function-configuration \ --function-name ${LAMBDA_FUNCTION_NAME} \ --environment "${STRING_LAMBDA_FUNCTION_ENVIRONMENT}" 結果(例): { "FunctionName": "handson-cli-lambda-function_basic-function", "FunctionArn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:handson-cli-lambda-function_basic-function", "Runtime": "python3.8", "Role": "arn:aws:iam::XXXXXXXXXXXX:role/handson-cli/handson-cli-lambda-role", "Handler": "handson-cli-lambda-function_basic-function.lambda_handler", "CodeSize": 256, "Description": "function for handson-cli-lambda.", "Timeout": 30, "MemorySize": 128, "LastModified": "2021-01-15T01:23:45.678+0000", "CodeSha256": "326", "Version": "$LATEST", "Environment": { "Variables": { "ENV": "product" } }, "TracingConfig": { "Mode": "PassThrough" }, "RevisionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "State": "Active", "LastUpdateStatus": "Successful", "PackageType": "Zip" }
cat << ETX # LAMBDA_FUNCTION_NAME:"handson-cli-lambda-function_basic-function" LAMBDA_FUNCTION_NAME="${LAMBDA_FUNCTION_NAME}" # STRING_LAMBDA_FUNCTION_ENVIRONMENT:"Variables={ENV=product}" STRING_LAMBDA_FUNCTION_ENVIRONMENT="${STRING_LAMBDA_FUNCTION_ENVIRONMENT} " ETX
コマンド:
aws lambda update-function-configuration \ --function-name ${LAMBDA_FUNCTION_NAME} \ --environment "${STRING_LAMBDA_FUNCTION_ENVIRONMENT}"
結果(例):
{ "FunctionName": "handson-cli-lambda-function_basic-function", "FunctionArn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:handson-cli-lambda-function_basic-function", "Runtime": "python3.8", "Role": "arn:aws:iam::XXXXXXXXXXXX:role/handson-cli/handson-cli-lambda-role", "Handler": "handson-cli-lambda-function_basic-function.lambda_handler", "CodeSize": 256, "Description": "function for handson-cli-lambda.", "Timeout": 30, "MemorySize": 128, "LastModified": "2021-01-15T01:23:45.678+0000", "CodeSha256": "326", "Version": "$LATEST", "Environment": { "Variables": { "ENV": "product" } }, "TracingConfig": { "Mode": "PassThrough" }, "RevisionId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "State": "Active", "LastUpdateStatus": "Successful", "PackageType": "Zip" }
「Lambda関数"handson-cli-lambda-function_basic-function"の設定に環境変数が存在する。」ことを確認します。
コマンド: aws lambda get-function-configuration \ --function-name ${LAMBDA_FUNCTION_NAME} \ --query 'Environment.Variables' 結果(例): { "ENV": "product" }
aws lambda get-function-configuration \ --function-name ${LAMBDA_FUNCTION_NAME} \ --query 'Environment.Variables'
{ "ENV": "product" }