【发布时间】:2022-01-25 18:20:38
【问题描述】:
我需要为我的 dynamodb 创建一个 cloudformation 模板,但我需要其中一个索引自动递增。 CloudFormation 模板如下所示:
TestTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: test-event-records
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: “UniqueId”
AttributeType: “N”
- AttributeName: “IsRestored”
AttributeType: “B”
- AttributeName: “EventName”
AttributeType: “S”
KeySchema:
- AttributeName: “UniqueId”
KeyType: “HASH”
- AttributeName: “IsRestored”
KeyType: “HASH”
- AttributeName: “EventName”
KeyType: “HASH”
Tags:
- Key: “AppGroup”
Value: !Ref “AppGroup”
- Key: “AppRole”
Value: “database”
- Key: “Environment”
Value: !Ref “Environment”
- Key: “Name”
Value: “test-event-records”
StreamSpecification:
StreamViewType: NEW_IMAGE
这里的 UniqueId (是数字类型,不能是 UUID)必须是一个自动递增的值。我需要在我的 .net 核心应用程序的这个新表中添加新项目。
【问题讨论】:
-
我已经看过这篇文章:stackoverflow.com/questions/37072341/…。但是它没有回答我的问题
-
不相关,但请小心使用任何类型的编辑器,使那些“弯引号”。这些不是真正的引号字符,我希望如果您将其复制/粘贴到 yaml 文件中并尝试部署它,它将失败。
-
感谢您的提醒,我从 Brackets 复制了它。我需要更改它的设置。
-
@Marcin 我想我找到了答案。从 cloudformation 无法做到这一点。但是可以在代码中自动增加它(在我的例子中是.netcore)。我发现这篇文章很有帮助andrewchaa.me.uk/technical/auto-increment-counter-in-dynamodb
标签: amazon-web-services amazon-dynamodb amazon-cloudformation amazon-dynamodb-index