amazon-web-services - 如何通过 cloudformation 将值插入 dynamodb?
问题描述
我正在 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 插入记录的正确方法。我似乎也找不到有关通过 cloudformation 插入记录的文档。我知道这是可以做到的。我可能错过了一些非常简单的东西。有任何想法吗?
解决方案
Custom::Install
是 CloudFormation 中的自定义资源。
这是一种特殊类型的资源,您必须自己开发。这主要通过 Lambda 函数(也可以是 SNS)来完成。
所以回答你的问题。要将数据添加到表中,您必须在 lambda 中编写自己的自定义资源。lambda 会将记录放入表中。
Action
并且fields
是 CloudFormation 传递给示例中的 lambda 的自定义参数Custom::Install
。参数可以是您想要的任何参数,因为您正在设计根据您的要求量身定制的自定义资源。
推荐阅读
- vue.js - 发布到后端但请求始终为空(vue 到节点)
- node.js - 如何从服务器更改我的 HTML 中的标签?
- bash - 按名称对文件使用 awk 的 gsub
- r - 在数据框上运行 T.test 并将结果按 col1 和 col3 分组
- java - 字段选择错误 thymeleaf 选择器绑定
- javascript - 试图从数组中弹出元素,但在循环中断之前只有 6 个元素被弹出
- mysql - ECS 上的 Wordpress - 无法连接到 mysql 容器
- jdeveloper - 无法连接到 Internet 以检查 JDeveloper 中的更新
- android - Android firebase:pendingDynamicLinkData 始终为空
- c# - SQLite; 是否有参数每次重写一条记录