我在cloudformation中创建一个表。
"MyStuffTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"TableName": "MyStuff"
"AttributeDefinitions": [{
"AttributeName": "identifier",
"AttributeType": "S"
]},
"KeySchema": [{
"AttributeName": "identifier",
"KeyType": "HASH",
}],
"ProvisionedThroughput": {
"ReadCapacityUnits": "5",
"WriteCapacityUnits": "1"
}
}
}
然后在cloudformation中,我想把记录插入到那个表中,就像这样。
identifier: Stuff1
data: {My list of stuff here}
然后插入到下面的代码中的值中去 我曾在某处看到一个例子,用 Custom::Install
但我现在找不到它,也找不到任何关于它的文档。 所以这是我的。
MyStuff: {
"Type": "Custom::Install",
"DependsOn": [
"MyStuffTable"
],
"Properties": {
"ServiceToken": {
"Fn::GetAtt": ["MyStuffTable","Arn"]
},
"Action": "fields",
"Values": [{<insert records into this array}]
}
};
当我运行它的时候,我得到这样的信息 Invalid service token
.所以我在尝试引用表来插入记录时做得不对。我似乎找不到任何关于Custom::Install的文档,所以我不确定它是否是通过云表单插入记录的正确方法。我似乎也找不到关于通过cloudformation插入记录的文档。我知道是可以做到的。我可能漏掉了一些很简单的东西。有什么想法吗?
Custom::Install
是一个 自定义资源 在CloudFormation中。
这是一种特殊类型的资源,您必须自行开发。这主要是通过Lambda函数(也可以是SNS)来实现的。
因此,为了回答您的问题。要将数据添加到您的表格中,您将必须 用lambda编写自己的自定义资源. lambda会把记录放入表中。
Action
和 fields
的例子中,CloudForm将自定义参数传递给lambda。Custom::Install
. 参数可以是任何你想要的,因为你是根据你的要求设计定制的资源。