Skip to main content

Avatar

Build Status Code Scanning Status Dependencies Status Security Status Published Version

Awstaga

Awstaga is a Python CLI for batch tagging AWS resources.

This package is intended as a companion for AWS Tag Editor. While AWS Tag Editor is useful for tagging multiple resources in one go, it has no easy way to re-run the tagging since you have to use the AWS console UI, and its resource filtering capability is quite limited, making it hard to select resources with-more-than basic logic.

Using Awstaga, you can easily re-run the resource tagging by running the CLI again. And with its YAML configuration support, it allows you to define multiple tagsets which you can mix and match with the AWS resources. You can construct your own mapping between the resources and the relevant tags and tagsets. You can generate the YAML configuration using your own script, allowing you to construct a more complex filtering logic.

Installation

pip3 install awstaga

Usage

Create a configuration file, e.g. awstaga.yaml:

---
tagsets:
  - name: common
    tags:
      - key: CostCentre
        value: FIN-123
      - key: Organisation
        value: World Enterprise
      - key: Description
        value: AWS Resource
  - name: prod
    tags:
      - key: EnvType
        value: prod
      - key: Availability
        value: 24x7
  - name: nonprod
    tags:
      - key: EnvType
        value: non-prod
      - key: Availability
        value: on-demand
resources:
  - arn: 'arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail'
    tags:
      - key: Description
        value: High availability SSM document
    tagsetnames:
      - common
      - prod
  - arn: 'arn:aws:s3:::world-enterprise/development/logo.jpg'
    tags:
      - key: Description
        value: World Enterprise logo
    tagsetnames:
      - common
      - nonprod

And then run awstaga CLI and pass the configuration file path:

awstaga --conf-file awstaga.yaml

It will write the log messages to stdout:

[awstaga] INFO Loading configuration file awstaga.yaml
[awstaga] INFO Loading 3 tagset(s)...
[awstaga] INFO Loading 2 resource(s)...
[awstaga] INFO Adding resource arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail to a batch with tags {'CostCentre': 'FIN-123', 'Organisation': 'World Enterprise', 'Description': 'AWS Resource', 'EnvType': 'prod', 'Availability': '24x7', 'Description': 'High availability SSM document'}
[awstaga] INFO Adding resource arn:aws:s3:::world-enterprise/development/logo.jpg to a batch with tags {'CostCentre': 'FIN-123', 'Organisation': 'World Enterprise', 'Description': 'AWS Resource', 'EnvType': 'prod', 'Availability': '24x7', 'Description': 'World Enterprise logo'}

And if the tagging failed (e.g. due to rate exceeded), it will log the following error messages:

[awstaga] ERROR Failed to apply tags to 1 resource(s):
[awstaga] ERROR arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail: 400 - Throttling - Rate exceeded
[awstaga] ERROR arn:aws:s3:::world-enterprise/development/logo.jpg: 400 - Throttling - Rate exceeded

YAML includes

Awstaga supports YAML includes using , so you can split your configuration into multiple files:

---
tagsets:
  - !include include.d/tagset.yaml
resources: !include include.d/resources.yaml

Include files should be put under `include.d/`` folder relative to the configuration file.

The included tagset file include.d/tagset.yaml:

---
name: common
tags:
  - key: CostCentre
    value: FIN-123
  - key: Organisation
    value: World Enterprise
  - key: Description
    value: AWS Resource

The included resources file include.d/resources.yaml:

---
- arn: 'arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail'
  tags:
    - key: Description
      value: High availability SSM document
  tagsetnames:
    - common
    - prod
- arn: 'arn:aws:s3:::world-enterprise/development/logo.jpg'
  tags:
    - key: Description
      value: World Enterprise logo
  tagsetnames:
    - common
    - nonprod

Dry run

You can also run Awstaga in dry-run mode by adding --dry-run flag:

awstaga --conf-file awstaga.yaml --dry-run

During dry-run mode, Awstaga log messages will be labeled with [dry-run]:

[dry-run] [awstaga] INFO Loading configuration file awstaga.yaml
[dry-run] [awstaga] INFO Loading 3 tagset(s)...
[dry-run] [awstaga] INFO Loading 2 resource(s)...
[dry-run] [awstaga] INFO Adding resource arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail to a batch with tags {'CostCentre': 'FIN-123', 'Organisation': 'World Enterprise', 'Description': 'AWS Resource', 'EnvType': 'prod', 'Availability': '24x7', 'Description': 'High availability SSM document'}

Batch size

In order to optimise the number of API calls, resources with identical tags are put into batches. By default, the batch size is 5. You can run Awstaga with a custom batch size --batch-size <number> flag:

awstaga --conf-file awstaga.yaml --batch-size 10

Delay

In order to avoid rate exceeded error, you can run Awstaga with a custom delay --delay <number> flag:

awstaga --conf-file awstaga.yaml --delay 5

By default, the delay is 2 seconds. The delay is applied between each batch of tagging API calls.

Please note that AWS limits the number of tagging API (tag_resources) calls to maximum of 5 calls per second.

Configuration

These are the configuration properties that you can use with awstaga CLI. Some example configuration files are available on examples folder.

Property Type Description Example
tagsets[] Array A list of one or more tagsets. Any tagset can be associated with any resource, and the resource will include the tags specified in the tagset.
tagsets[].name String The name of the tagset. common
tagsets[].tags[] Array A list of one or more key-value pair tags within the tagset.
tagsets[].tags[].key String The tag key. CostCentre
tagsets[].tags[].value String The tag value. FIN-123
resources[] Array A list of one or more AWS resources. Each of the resource has a corresponding list of tags, along with the tags from tagsets.
resources[].arn String AWS resource ARN. arn:aws:s3:::world-enterprise/development/logo.jpg
resources[].tags[] Array A list of one or more key-value pair tags of the resource.
resources[].tags[].key String The tag key. Description
resources[].tags[].value String The tag value. Some description
resources[].tagsetnames[] Array A list of one or more tagset names. All tags within the tagsets specified are included in the resource.

Permissions

The AWS credentials used to run awstaga CLI must have the following permissions:

  • Permission to use AWS Resource Groups API
  • Permission to tag resources for individual AWS services that you want to tag

Colophon

Developer's Guide

Build reports:

Related projects:

  • Packer Awstaga - Packer builder of machine image for running Awstaga configuration-based AWS resource tagging tool

Metadata

Release files for awstaga 2.2.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 awstaga 2.2.0
File Size Uploaded
awstaga-2.2.0.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for awstaga 2.2.0
File Interpreter ABI Platform
awstaga-2.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / awstaga-2.2.0.tar.gz

Download URL awstaga-2.2.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
20d4c591481bdcf3bbe82969689169e7618b3a34c459eacdc0415152612cd102
BLAKE2b-256 checksum
How to use checksums
c6c2c5e095536dc1496323c50f2186a5db82cabea2fd9700b3ac316b9243762f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.5 Linux/6.17.0-1013-azure

Release files / awstaga-2.2.0-py3-none-any.whl

Download URL awstaga-2.2.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ad2bcefeeb8236157782b9707583952f32138e2b873e200f206205d54070e65
BLAKE2b-256 checksum
How to use checksums
bf880c9b4c74f9074e187bc7db7640ecba97e4010bc4162d30fec47d8b00f17c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.1 CPython/3.14.5 Linux/6.17.0-1013-azure

Release history Release notifications | RSS feed

This release

2.2.0 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.12.0

2 release files

0.11.0

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