【发布时间】:2019-12-13 13:29:38
【问题描述】:
我正在尝试在本地测试传递我的 CloudFormation 模板文件中声明的 DynamoDB 表的表名。
从我阅读的所有文档中,我应该能够使用 !Ref 内在函数引用 DynamoDB 资源的 TableName 属性值。但是,当我在本地对此进行测试时,该属性是未定义的。
考虑以下示例:
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
我希望 TABLE_NAME 环境变量为 DynamoDBTableName 但它返回未定义。如何让模板按预期工作?
【问题讨论】:
-
我刚刚修复了您的问题以引用 CloudFormation,因为您的问题与 CloudFormation 相关,而不是 SAM。也就是说,经过简短的查看后,它应该可以按您的预期工作。您能否在尝试访问环境变量的地方添加您的 AWS Lambda 函数的代码?
-
我正在寻找如何做同样的事情并在这里找到了您的问题。你所做的事情对我有用。无论如何,谢谢你在这里问。
-
谁能提供 JSON 格式的 cloudformation 模板的答案/解决方案?
标签: amazon-cloudformation aws-sam