aws-sam-cli
aws-sam-cli copied to clipboard
Bug: parsing Ref in template.json is incorrect
Description:
sam can't parse the Ref key in the following Lambda definition. We expected TABLE_NAME
to be the actual DynamoDB table name, but instead got demogametable2FE33C07
.
"GameHandler295CCC0B": {
"Type": "AWS::Lambda::Function",
"Properties": {
"Code": {
"S3Bucket": {
"Fn::Sub": "cdk-hnb659fds-assets-${AWS::AccountId}-ap-northeast-1"
},
"S3Key": "2160ee90758ba745c338833566ade881a8ad5ff3693dcd6d9347e5fdb41b5da4.zip"
},
"Environment": {
"Variables": {
"TABLE_NAME": {
"Ref": "demogametable2FE33C07"
}
}
},
Steps to reproduce:
cdk python code as following
# Create the Lambda function to receive the request
api_hanlder = lambda_.Function(
self,
"GameHandler",
function_name="game_handler",
runtime=lambda_.Runtime.PYTHON_3_12,
code=lambda_.Code.from_asset("src/game"),
handler="index.handler",
vpc=vpc,
vpc_subnets=ec2.SubnetSelection(
subnet_type=ec2.SubnetType.PRIVATE_ISOLATED
),
memory_size=1024,
timeout=Duration.minutes(5),
)
# grant permission to lambda to write to demo table
demo_table.grant_write_data(api_hanlder)
api_hanlder.add_environment("TABLE_NAME", demo_table.table_name)
Run local test
cdk synth --no-staging
sam local invoke GameHandler --no-event -t ./cdk.out/GameStack.template.json -e tests/game/event.json
event.json
{
"body": "{\"year\":\"2023\",\"title\":\"kkkg\",\"id\":\"12\"}"
}
Observed result:
demogametable2FE33C07
Expected result:
real dynamodb table name
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Mac 14.6.1
-
sam --version
: SAM CLI, version 1.123.0 - AWS region: ap-northeast-1
{
"version": "1.123.0",
"system": {
"python": "3.12.5",
"os": "macOS-14.6.1-arm64-arm-64bit"
},
"additional_dependencies": {
"docker_engine": "24.0.9",
"aws_cdk": "2.154.1 (build febce9d)",
"terraform": "1.5.7"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}