Skip to main content

Python CLI for tagging AWS resources based on a YAML configuration

Project description

Avatar

Build Status Security Status Published Version

Awstaga

Awstaga is a Python CLI for tagging AWS resources based on a YAML configuration.

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 Updating resource arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail with tags {'CostCentre': 'FIN-123', 'Organisation': 'World Enterprise', 'Description': 'AWS Resource', 'EnvType': 'prod', 'Availability': '24x7', 'Description': 'High availability SSM document'}
[awstaga] INFO Updating resource arn:aws:s3:::world-enterprise/development/logo.jpg with tags {'CostCentre': 'FIN-123', 'Organisation': 'World Enterprise', 'Description': 'AWS Resource', 'EnvType': 'prod', 'Availability': '24x7', 'Description': 'World Enterprise logo'}

You can 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 Updating resource arn:aws:ssm:ap-southeast-2:123456789012:document/high-avail with tags {'CostCentre': 'FIN-123', 'Organisation': 'World Enterprise', 'Description': 'AWS Resource', 'EnvType': 'prod', 'Availability': '24x7', 'Description': 'High availability SSM document'}

Awstaga supports YAML-include, 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

Configuration

Configuration properties:

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.

Colophon

Developer's Guide

Build reports:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awstaga-1.0.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

awstaga-1.0.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file awstaga-1.0.0.tar.gz.

File metadata

  • Download URL: awstaga-1.0.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.2.0-1016-azure

File hashes

Hashes for awstaga-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8b358fed39d4e078ccd9c0130bd059c59589f8e4a34c7fbcfe8e13edc83f2c72
MD5 853baec606ffc09b11a652196a026103
BLAKE2b-256 ce1d00d1457918774f08fe40520f69e4613a90c160291ccb80e19d841d7acf27

See more details on using hashes here.

File details

Details for the file awstaga-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: awstaga-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.2.0-1016-azure

File hashes

Hashes for awstaga-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cd792efa6b4a9b5f396f57a0be0406fae59e4483324ab1afae26757c3210b54
MD5 23e39971ebecfc3b7d625bc1e7977750
BLAKE2b-256 f6dfd2b4a685d7fdffeb51b38b36de5e563d6f7636e4a48121e5ded4c760d92a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page