Skip to main content

CDK Aspects Library - Tags

A library of AWS CDK Aspects for applying consistent tagging to AWS resources.

Features

This library provides two main aspects for tagging AWS resources:

ApplyTags

An aspect that applies a set of custom tags to all taggable resources in the given scope. This is useful for:

  • Cost allocation and tracking
  • Resource management and organization
  • Compliance and governance requirements
  • Environment identification

ApplyKmsTags

An aspect that applies CloudFormation-specific tags to KMS keys, including:

  • cfn:stack-name - The name of the CloudFormation stack
  • cfn:logical-id - The logical ID of the KMS key resource

This is particularly useful because KMS keys are not automatically tagged by CloudFormation, making them difficult to track and manage in large deployments.

It's not possible to use the same tags that CloudFormation applies to other resources, because those names are reserved for CloudFormation's internal use. As a best approximation, it uses the similar tag names listed above.

Examples

TypeScript

import { Aspects, App, Stack } from 'aws-cdk-lib';
import { aws_s3 as s3, aws_kms as kms } from 'aws-cdk-lib';
import { ApplyTags, ApplyKmsTags } from '@renovosolutions/cdk-aspects-library-tags';

const app = new App();
const stack = new Stack(app, 'MyStack');

// Create some resources
new s3.Bucket(stack, 'MyBucket');
new kms.Key(stack, 'MyKey');

// Apply custom tags to all taggable resources
const tags = {
  'Environment': 'Production',
  'Project': 'MyProject',
  'Owner': 'TeamName'
};
Aspects.of(stack).add(new ApplyTags(tags));

// Apply CloudFormation tags specifically to KMS keys
Aspects.of(stack).add(new ApplyKmsTags());

Python

from aws_cdk import (
  Aspects,
  App,
  Stack,
  aws_s3 as s3,
  aws_kms as kms,
)
from renovosolutions_aspects_tags import (
  ApplyTags,
  ApplyKmsTags,
)

app = App()
stack = Stack(app, "MyStack")

# Create some resources
s3.Bucket(stack, "MyBucket")
kms.Key(stack, "MyKey")

# Apply custom tags to all taggable resources
tags = {
    "Environment": "Production",
    "Project": "MyProject",
    "Owner": "TeamName"
}
Aspects.of(stack).add(ApplyTags(tags))

# Apply CloudFormation tags specifically to KMS keys
Aspects.of(stack).add(ApplyKmsTags())

C Sharp

using Amazon.CDK;
using Amazon.CDK.AWS.S3;
using Amazon.CDK.AWS.KMS;
using System.Collections.Generic;
using renovosolutions;

var app = new App();
var stack = new Stack(app, "MyStack");

// Create some resources
new Bucket(stack, "MyBucket");
new Key(stack, "MyKey");

// Apply custom tags to all taggable resources
var tags = new Dictionary<string, string>
{
    ["Environment"] = "Production",
    ["Project"] = "MyProject",
    ["Owner"] = "TeamName"
};
Aspects.Of(stack).Add(new ApplyTags(tags));

// Apply CloudFormation tags specifically to KMS keys
Aspects.Of(stack).Add(new ApplyKmsTags());

Scope of Application

The aspects in this library work at different scopes:

  • ApplyTags: Applies to all resources that implement the ITaggable interface (most AWS resources)
  • ApplyKmsTags: Applies specifically to AWS::KMS::Key resources

You can apply these aspects at any level in your CDK hierarchy:

  • App level: Tags all resources across all stacks
  • Stack level: Tags all resources within a specific stack
  • Construct level: Tags resources within a specific construct

API Reference

For detailed API documentation, see API.md.

Contributing

Contributions are welcome! Please see our contributing guidelines for more details.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Metadata

Release files for renovosolutions.aws-cdk-aspects-tags 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for renovosolutions.aws-cdk-aspects-tags 0.0.0
File Size Uploaded
renovosolutions_aws_cdk_aspects_tags-0.0.0.tar.gz 31.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for renovosolutions.aws-cdk-aspects-tags 0.0.0
File Interpreter ABI Platform
renovosolutions_aws_cdk_aspects_tags-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 63.5 kB

Release files / renovosolutions_aws_cdk_aspects_tags-0.0.0.tar.gz

Download URL renovosolutions_aws_cdk_aspects_tags-0.0.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5097dfbb49805ccc15fb0695fc35b178f20695e3de243a4d465b9707a49127b2
BLAKE2b-256 checksum
How to use checksums
ff64a4cbb4a28411dbc7df2a3a551af5168a38a27d72105a5f19e58c891c1f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / renovosolutions_aws_cdk_aspects_tags-0.0.0-py3-none-any.whl

Download URL renovosolutions_aws_cdk_aspects_tags-0.0.0-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1613627941984877aa0195b71ae870f56d039b76fea7f9748e6648d90ffbbd43
BLAKE2b-256 checksum
How to use checksums
50757e5e6f6a99ce04f97e91ddb709ceef794dee7d7407ecb695f2c3e1c2d8e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page