Bug: Sam deploy Fails TypeError: unhashable type: 'dict' When passing !Ref or !Sub values into AWS::Serverless::Function Environment Variables
Description:
When passing in string substitution for AWS::Serverless::Function into the Environment Variables config SAM init throws a stack trace for YAML helper.
Steps to reproduce:
sam deploy --resolve-s3 --template-file template.yaml --region us-east-1 --force-upload --config-env dev
LambdaFunction: Type: AWS::Serverless::Function Properties: FunctionName: !Sub "lambda-${Environment}" Environment: Variables: !Ref DynamoCacheDBTable: "7" Architectures: - !Ref LambdaArchitecture
This configuration does not work and also using !Sub throws the same result: LambdaFunction: Type: AWS::Serverless::Function Properties: FunctionName: !Sub "lambda-${Environment}" Environment: Variables: !Sub "dynamo_cache_table_${Environment": 7 Architectures: - !Ref LambdaArchitecture
The dynamo db table is defined as: DynamoCacheDBTable: Type: AWS::DynamoDB::Table Properties: TableName: !Sub "dynamo_table_${Environment}"
When explicitly setting the values for the environment variable to the table name: dynamo_table_dev
The build succeeds without issue
There was a similar issue fixed here with the same result: https://github.com/aws/serverless-application-model/issues/1094
Observed result:
sam deploy --resolve-s3 --template-file template.yaml --region us-east-1 --force-upload --config-env dev --debug Traceback (most recent call last): File "samcli/yamlhelper.py", line 122, in yaml_parse File "json/init.py", line 361, in loads File "json/decoder.py", line 337, in decode File "json/decoder.py", line 355, in raw_decode json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "samcli/main.py", line 12, in
Expected result:
Expected the lambda to deployed with the correct environment variable key/values using substitution or Reference
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: lambda architecture is x86_64
sam --version: SAM CLI, version 1.59.0- AWS region: us-east-1
Add --debug flag to command you are running
sam deploy --resolve-s3 --template-file template.yaml --region us-east-1 --force-upload --config-env dev --debug
Traceback (most recent call last):
File "samcli/yamlhelper.py", line 122, in yaml_parse
File "json/init.py", line 361, in loads
File "json/decoder.py", line 337, in decode
File "json/decoder.py", line 355, in raw_decode
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "samcli/main.py", line 12, in
I was able to reproduce this, the stack trace is due to the fact that the intrinsics to be resolved in the present in the "Key" section of the environment variables, switching it so that its present in the values makes the error message more direct.
eg:
Error: Failed to create changeset for the stack: myapp-4285, ex: Waiter ChangeSetCreateComplete failed: Waiter encountered a terminal failure state: For expression "Status" we matched expected path: "FAILED" Status: FAILED. Reason: Template format error: Unresolved resource dependencies [Environment] in the Resources block of the template
any update on this issue?