aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(dynamodb): Tags not replicated when creating Table replicas

Open ccicchitelli opened this issue 5 years ago • 11 comments

When creating a Global Table in DynamoDB with CDK, tags are not propagated to the replication regions and there is no ability to define tags for those replication regions. As a result, our resources are remediated by internal tools due to missing tags.

Reproduction Steps

When creating a Global Table via CDK, I add the following prop to my Table Construct: replicationRegions: ["us-east-2"]

Additionally, I have tags defined for the whole the stack: new AppStack(app, 'DigitalAccountDynamoStack', { tags: { ['deployment_guid']: process.env.bamboo_forge_deployment_guid as string, }});

I have also tried: Tags.of(app).add('deployment_guid', process.env.bamboo_forge_deployment_guid as string); As well as: Tag.add(appStack, 'deployment_guid', process.env.bamboo_forge_deployment_guid as string);

All result in the same: missing tags.

What did you expect to happen?

Tags from the core region should be replicated to the replication regions or there should be a property to manually set the tags.

What actually happened?

Tags are empty in replication regions.

Environment

  • **CDK CLI Version :**1.106.1
  • Framework Version:
  • **Node.js Version:**14.6.0
  • **OS :**Mac OS
  • Language (Version): TypeScript

Other


This is :bug: Bug Report

ccicchitelli avatar Jun 01 '21 15:06 ccicchitelli

Hey @ccicchitelli ,

thanks for opening the issue. You can try applying the Tags this way:

        const table = new dynamodb.Table(this, 'Table', {
            partitionKey: {
                name: 'Id',
                type: dynamodb.AttributeType.STRING,
            },
            replicationRegions: ['us-west-1'],
        });
        const nestedStack = this.node.findChild('@aws-cdk/aws-dynamodb.ReplicaProvider') as NestedStack;
        Tags.of(nestedStack).add('abc', 'xyz');

skinny85 avatar Jun 01 '21 18:06 skinny85

Thanks @skinny85 ! That did not have any effect for me, I tested both with an existing table and a new test table. I also tried to find a workaround by running a post-deploy CLI command to tag the relication region by ARN, but my organization doesn't allow that unfortunately.

ccicchitelli avatar Jun 02 '21 01:06 ccicchitelli

@ccicchitelli, thanks for opening this. I actually just experienced this for the first time today myself. I also tried the workaround @skinny85 suggested, and it didn't work for me either.

chrisjgray avatar Jun 02 '21 23:06 chrisjgray

Hey all,

I believe this is a DynamoDB limitation.

The CDK uses the UpdateTable DynamoDB API to create the replica. If you look at the documentation of that call, it doesn't allow passing Tags to the created replica, so there's no way for us to tag the created replica.

Note that there is a new resource, AWS::DynamoDB::GlobalTable. Hopefully, that resource supports tagging (although I don't see it in the definition of the resource...).

skinny85 avatar Jun 03 '21 19:06 skinny85

@skinny85 The CDK page for AWS::DynamoDB::GlobalTable is marked as deprecated, but the issue with the lack of tags in dynamodb replicated regions has not yet been resolved. When can we expect this functionality to be implemented? Thanks!

harrilu96 avatar Oct 07 '21 15:10 harrilu96

@skinny85 The CDK page for AWS::DynamoDB::GlobalTable is marked as deprecated

Sorry, which page is marked as deprecated?

skinny85 avatar Oct 07 '21 18:10 skinny85

The CDK for global tables is marked as deprecated here: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb-global.GlobalTable.html

It asks us to use @aws-cdk/aws-dynamodb.Table.replicationRegions instead, which does not replicate tags

harrilu96 avatar Oct 07 '21 18:10 harrilu96

Ah, I see. This is a little confusing, so let me explain 🙂.

The page you linked to (https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb-global.GlobalTable.html) is not for the AWS::DynamoDB::GlobalTable resource. It's actually for the "old" DynamoDB global support (version 2017.11.29), which has been deprecated by DynamoDB.

When I say the CDK class for the AWS::DynamoDB::GlobalTable, I mean this class. As you can see, it's definitely not deprecated 🙂. This is an example of a Layer 1 construct, as we don't have support for on the higher-level Layer 2 for the AWS::DynamoDB::GlobalTable resource yet.

Hope this clears this up!

Thanks, Adam

skinny85 avatar Oct 07 '21 21:10 skinny85

I recommend creating an issue on the CloudFormation coverage roadmap so that we can see direct support of this feature

peterwoodworth avatar Jun 21 '22 23:06 peterwoodworth

This issue indicates it is possible to use CloudFormation to specify the tags using ReplicaSpecification object. https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/1074

It is possible to specify tags on a AWS::DynamoDB::GlobalTable resource via the Tags field in each ReplicaSpecification object.

For more details, see: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-globaltable-replicaspecification.html#cfn-dynamodb-globaltable-replicaspecification-tags.

deandalm avatar May 04 '23 18:05 deandalm

It seems to me that this issue is describing two different issues:

  1. Tags are not propagated to replicas when using our L2 Table construct to create replicas. This is because updateTable does not provide a way to manage tags. However, we could also use the TagResource API call in the custom resource to bridge this gap

  2. Tags are not propagated to CfnGlobalTable. This is because setting the tags on this resource is on a per-replica basis. In other words, Tags is not a first level prop in the CloudFormation specification, so we aren't detecting it as taggable. I've created a separate issue for this here

peterwoodworth avatar May 04 '23 18:05 peterwoodworth