Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I create this DynamoDb table group with CloudFormation?

We can create, edit, delete group from AWS Console to maintain a logical grouping of DynamoDb tables. I searched over AWS documentation and forums but did not find a way on how can I create this DynamoDb table group with CloudFormation or how can I create a table inside a group with AWS .NET SDK. Is this even possible?

enter image description here

like image 751
kaushalparik27 Avatar asked Nov 01 '19 09:11

kaushalparik27


2 Answers

Table groups exist only on the AWS console UI. There is no such resource on AWS that is why they aren't available neither on CloudFormation nor on CDK.

like image 82
dmigo Avatar answered Oct 06 '22 15:10

dmigo


You can use the the resource groups API to create a resource group defined by a tag prefixed with DDBTableGroupKey- that the DynamoDB console will automatically pull it in.

E.g.

import json
import boto3

rg = boto3.client('resource-groups')
resource_query = json.dumps({
    "ResourceTypeFilters": ["AWS::DynamoDB::Table"], 
    "TagFilters": [
        {"Key": "DDBTableGroupKey-PROD", "Values": ["PROD"]}
    ]
})
rg.create_group(
    Name='PROD',
    ResourceQuery={'Type': 'TAG_FILTERS_1_0', 'Query': resource_query}
)

Then tag the relevant tables with DDBTableGroupKey-PROD, PROD.

Then they should appear in the console as a group.

In CDK you could create this by using:

const group = "lolprod"
cdk.Tag.add(this, `DDBTableGroupKey-${group}`, group)

and

new resourcegroups.CfnGroup(this, id, {
    name: group,
    resourceQuery: {query: '...', type: '...'}
})
like image 3
Randall Hunt Avatar answered Oct 06 '22 14:10

Randall Hunt