kaushalparik27
kaushalparik27

Reputation: 804

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

Upvotes: 11

Views: 2251

Answers (2)

Randall Hunt
Randall Hunt

Reputation: 12572

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: '...'}
})

Upvotes: 3

dmigo
dmigo

Reputation: 3029

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.

Upvotes: 6

Related Questions