how can I create this DynamoDb table group with CloudFormation?

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.


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