[英]Create DynamoDB through custom resources Cloud Formation Template
I am trying to create a GlobalTable in AWS DynamoDB with the below Cloud formation template script. 我正在尝试使用以下Cloud Formation模板脚本在AWS DynamoDB中创建GlobalTable。 However I am not sure if I have all things required.
但是我不确定我是否需要所有的东西。 My Custom Resource section looks like below.
我的自定义资源部分如下所示。
"CreateGlobalTable":{
"Type":"Custom::CreateGlobalTable",
"Properties":{
"ServiceToken":{
"Fn::GetAtt":[
"SolutionHelper",
"Arn"
]
},
"GlobalTableName": "myglobaltable",
"ReplicationGroup": [
{
"RegionName": "eu-west-1"
}
]
}
},
When the stack is generated I see an entry for the same in the logs, however no Global table is created. 生成堆栈时,我在日志中看到相同的条目,但是没有创建全局表。 Does it need a backing lamda function which will actually create the global table?
它是否需要一个支持lamda函数,它实际上会创建全局表? or AWS API handles it automatically from the way it is defined above.
或AWS API从上面定义的方式自动处理它。 Any guidance is much appreciated.
任何指导都非常感谢。
Indeed, you actually need to have a Lambda function that does the actual creation/update/deletion of the GlobalTable. 实际上,您实际上需要一个Lambda函数来实际创建/更新/删除GlobalTable。
Here's a basic guidance on how to proceed: 以下是如何进行的基本指导:
GlobalTableCustomResourceLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Handler: global_table_custom_resource.lambda_handler
Role: !GetAtt CustomResourceRole.Arn
Code: cloudformation/custom-resource/global_table_custom_resource.py
Runtime: python3.6
Timeout: '25'
CustomResourceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: ''
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Action: sts:AssumeRole
Path: "/"
Policies:
- PolicyName: GlobalTableCustomResourceLambdaPolicy
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- dynamodb:CreateTable
- dynamodb:UpdateTable
- dynamodb:DeleteTable
Resource: "*"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
For the Python code, I think it's beyond the scope of a StackOverflow answer, I'll refer you to this article which goes through the whole process: https://serverlesscode.com/post/python-custom-resource-cloudformation/ . 对于Python代码,我认为它超出了StackOverflow答案的范围,我将向您介绍贯穿整个过程的本文: https : //serverlesscode.com/post/python-custom-resource-cloudformation/ 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.