-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
DynamoDB: Support Adding Tags #6347
Labels
feature-request
A feature should be added or improved.
needs-triage
This issue or PR still needs to be triaged.
Comments
diepjy
added
feature-request
A feature should be added or improved.
needs-triage
This issue or PR still needs to be triaged.
labels
Feb 18, 2020
Here is how I apply tags to all the resources within a stack that are supported by CloudFormation. Contents of #!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import { DemoStack } from '../lib/demo-stack';
const account: string = process.env.CDK_DEFAULT_ACCOUNT || cdk.Aws.ACCOUNT_ID;
const env = { account, region: process.env.CDK_DEFAULT_REGION };
const app = new cdk.App();
const demoStack = new DemoStack(app, 'DemoStack', { env } );
// Stack tagging section
[
demoStack
].forEach((resource) => {
resource.node.applyAspect(new cdk.Tag("poc", "john.doe@acme.com"));
resource.node.applyAspect(new cdk.Tag("team", "acme"));
resource.node.applyAspect(new cdk.Tag("foo", "bar"));
}); Contents of import * as cdk from '@aws-cdk/core';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
export class DemoStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new dynamodb.Table(this, 'Table', {
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING }
});
}
} Resulting CloudFormation template: Resources:
TableCD117FA1:
Type: AWS::DynamoDB::Table
Properties:
KeySchema:
- AttributeName: id
KeyType: HASH
AttributeDefinitions:
- AttributeName: id
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Tags:
- Key: poc
Value: john.doe@acme.com
- Key: team
Value: acme
- Key: foo
Value: bar
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: DemoStack/Table/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Modules: aws-cdk=1.24.0,@aws-cdk/assets=1.24.0,@aws-cdk/aws-applicationautoscaling=1.24.0,@aws-cdk/aws-autoscaling=1.24.0,@aws-cdk/aws-autoscaling-common=1.24.0,@aws-cdk/aws-autoscaling-hooktargets=1.24.0,@aws-cdk/aws-cloudformation=1.24.0,@aws-cdk/aws-cloudwatch=1.24.0,@aws-cdk/aws-dynamodb=1.24.0,@aws-cdk/aws-ec2=1.24.0,@aws-cdk/aws-ecr=1.24.0,@aws-cdk/aws-ecr-assets=1.24.0,@aws-cdk/aws-ecs=1.24.0,@aws-cdk/aws-elasticloadbalancingv2=1.24.0,@aws-cdk/aws-events=1.24.0,@aws-cdk/aws-iam=1.24.0,@aws-cdk/aws-kms=1.24.0,@aws-cdk/aws-lambda=1.24.0,@aws-cdk/aws-logs=1.24.0,@aws-cdk/aws-s3=1.24.0,@aws-cdk/aws-s3-assets=1.24.0,@aws-cdk/aws-servicediscovery=1.24.0,@aws-cdk/aws-sns=1.24.0,@aws-cdk/aws-sns-subscriptions=1.24.0,@aws-cdk/aws-sqs=1.24.0,@aws-cdk/aws-ssm=1.24.0,@aws-cdk/aws-stepfunctions=1.24.0,@aws-cdk/aws-stepfunctions-tasks=1.24.0,@aws-cdk/core=1.24.0,@aws-cdk/custom-resources=1.24.0,@aws-cdk/cx-api=1.24.0,@aws-cdk/region-info=1.24.0,jsii-runtime=node.js/v13.8.0 |
Here is the case if you want to apply (or override) tags to only specific resource(s)... Contents of import * as cdk from '@aws-cdk/core';
import * as dynamodb from '@aws-cdk/aws-dynamodb';
export class DemoStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const table = new dynamodb.Table(this, 'Table', {
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING }
});
table.node.applyAspect(new cdk.Tag("poc", "jane.doe@acme.com"));
}
} Resulting CloudFormation template: Resources:
TableCD117FA1:
Type: AWS::DynamoDB::Table
Properties:
KeySchema:
- AttributeName: id
KeyType: HASH
AttributeDefinitions:
- AttributeName: id
AttributeType: S
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Tags:
- Key: poc
Value: jane.doe@acme.com
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Metadata:
aws:cdk:path: DemoStack/Table/Resource
CDKMetadata:
Type: AWS::CDK::Metadata
Properties:
Modules: aws-cdk=1.24.0,@aws-cdk/assets=1.24.0,@aws-cdk/aws-applicationautoscaling=1.24.0,@aws-cdk/aws-autoscaling=1.24.0,@aws-cdk/aws-autoscaling-common=1.24.0,@aws-cdk/aws-autoscaling-hooktargets=1.24.0,@aws-cdk/aws-cloudformation=1.24.0,@aws-cdk/aws-cloudwatch=1.24.0,@aws-cdk/aws-dynamodb=1.24.0,@aws-cdk/aws-ec2=1.24.0,@aws-cdk/aws-ecr=1.24.0,@aws-cdk/aws-ecr-assets=1.24.0,@aws-cdk/aws-ecs=1.24.0,@aws-cdk/aws-elasticloadbalancingv2=1.24.0,@aws-cdk/aws-events=1.24.0,@aws-cdk/aws-iam=1.24.0,@aws-cdk/aws-kms=1.24.0,@aws-cdk/aws-lambda=1.24.0,@aws-cdk/aws-logs=1.24.0,@aws-cdk/aws-s3=1.24.0,@aws-cdk/aws-s3-assets=1.24.0,@aws-cdk/aws-servicediscovery=1.24.0,@aws-cdk/aws-sns=1.24.0,@aws-cdk/aws-sns-subscriptions=1.24.0,@aws-cdk/aws-sqs=1.24.0,@aws-cdk/aws-ssm=1.24.0,@aws-cdk/aws-stepfunctions=1.24.0,@aws-cdk/aws-stepfunctions-tasks=1.24.0,@aws-cdk/core=1.24.0,@aws-cdk/custom-resources=1.24.0,@aws-cdk/cx-api=1.24.0,@aws-cdk/region-info=1.24.0,jsii-runtime=node.js/v13.8.0 |
@robertd that works well - thanks for the help! |
seems like it has not fixed in cdk@1.144.0 |
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Labels
feature-request
A feature should be added or improved.
needs-triage
This issue or PR still needs to be triaged.
Currently you cannot add tags to DynamoDB tables using the DynamoDB CDK module but you can add them using the AWS CLI using
aws resourcegroupstaggingapi tag-resources
or manually using the AWS DynamoDB console.Use Case
For example I would like to add billing tags to to my DynamoDB tables.
Other
This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: