I am trying to create a GlobalTable in AWS DynamoDB with the below Cloud formation template script. 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? or AWS API handles it automatically from the way it is defined above. Any guidance is much appreciated.
Indeed, you actually need to have a Lambda function that does the actual creation/update/deletion of the 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/ .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.