我正在尝试使用AWS CloudFormation创建一个AWS DynamoDB表,
创建相同内容时出现错误。
以前,我已经指定了想要的表的所有列,
但是似乎AttributeDefinitions和KeySchema Properties需要以某种方式匹配,但不确定。
我缩小到表中必须包含的两列,
即。 user_id and expiry
,
user_id是主键,过期是用于TTL的列。
我仍然遇到以下错误-
属性AttributeDefinitions与表的KeySchema和辅助索引不一致
以下是我的模板的摘要,根据CloudFormation StatusReason,我遇到了问题-
userExpiry:
Type: 'AWS::DynamoDB::Table'
Properties:
TableName: !Join ['_', [!Ref "prefix",'user_expiry'] ]
AttributeDefinitions:
-
AttributeName: 'expiry'
AttributeType: 'N'
-
AttributeName: 'user_id'
AttributeType: 'S'
KeySchema:
- AttributeName: "user_id"
KeyType: "HASH"
TimeToLiveSpecification:
AttributeName: "expiry"
Enabled: true
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
Tags:
-
Key: 'Project'
Value: !Ref "ProjectName"
-
Key: 'Environment'
Value: !Ref "ResourceEnvironment"
我正在关注此参考文档-
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html
答案 0 :(得分:0)
Yaml对文件使用固定的缩进模式/方案,这可能是出现错误的原因。我尝试了以下代码,并能够创建DynamoDB表。希望您可以根据最终要求进行足够的更改:
AWSTemplateFormatVersion:“ 2010-09-09” 说明:“用于创建DynamoDB表的AWS CloudFormation模板-userExpiry。” 资源:userExpiry: 类型:“ AWS :: DynamoDB :: Table”属性: TableName:NewTableName 属性定义: -- AttributeName:“ user_id” AttributeType:“ S”
KeySchema: -- AttributeName:“ user_id” 关键字类型:“哈希” TimeToLive规格: AttributeName:“到期” 启用:true 供应量: ReadCapacityUnits:1 WriteCapacityUnits:1 标签: -- 密钥:“ MyKey” 值:“ ProjectName”
(*)使用上述Yml文件创建的表(NewTableName)-仅包含“ user_id”的单个列。可以在插入记录期间放置TTL规范列“到期”。