I am trying to locally test passing the table name of a DynamoDB table as declared in my CloudFormation template file.
From all the documentation I have read, I should be able to reference the the TableName
property value of a DynamoDB resource using the !Ref
intrinsic function. However when I test this locally the property is undefined.
Consider the following example:
Transform: 'AWS::Serverless-2016-10-31'
Resources:
ServerlessFunction:
Type: AWS::Serverless::Function
Properties:
Runtime: nodejs10.x
Handler: index.handler
Environment:
Variables:
TABLE_NAME: !Ref DynamoDBTable # <- returning undefined
Events:
GetCocktails:
Type: Api
Properties:
Path: /
Method: get
DynamoDBTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: DynamoDBTableName
AttributeDefinitions:
- AttributeName: ID
AttributeType: S
KeySchema:
- AttributeName: ID
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
I expect the TABLE_NAME
environment variable to be DynamoDBTableName
however it returns undefined. How do I get the template to work as expected?
sam
, the op's original syntax is correct for getting the table name, re:!Ref DynamoDBTable
. See Ref will return the DynamoDB table name – Endodermis