Creating, Mapping Tags for the resources in AWS

There are various reasons we create or map the tags for the resources in the AWS Cloud. One main reason is for doing a Cost optimization and to isolate, which resources belong to which business domain or which project. 

Tags can be well assigned and well organized in an effective way with the various ways as below.

  • AWS Resource Groups
  • AWS CLI 
  • Terraform

AWS Resource Groups: (Option 1)

  • In the AWS Console search for a service, "AWS Resource Group"   à Tagging à Tag Editor and then select the required options from the drop down as shown below.
  • Click on search resource which will populate all the resources created in the AWS Cloud infrastructure.
  • Select all the resources or required resources
  • Click on "Manage tags of selected resources"
  • then using the Add Tag option add the required tags



AWS CLI: (Option 2)

Using the "resourcegroupstaggingapi", this can be easily done via following the below steps
  • Create a JSON file with the tags and ARN for each of the resources the tags need to be assigned.
  • Below is the sample tags.json, in the "ResourceARNList" mention the ARN for the resources.
{
  "Tags": {
    "AppName": "WebsiteApp",
    "APPID": "12345678",
    "Architecture": "MultiTrier",
    "ENV": "Production",
    "Severity": "SEV1"
       },
  "ResourceARNList": [
    "arn:aws:dms:us-east-1:4675541064:task:QX52XKDYZZAMPCMASELPU7U",
    "arn:aws:dms:us-east-1:4675541064:rep:EBZK6XS2SVDDBOCFGXH2QOQM"
   "arn:aws:dms:us-east-1:4675541064:endpoint:FEXKWMGOU5DH3KBGYBSQ",
   "arn:aws:dms:us-east-1:4675541064:endpoint:UOXXUACPXBFYFJIZ7ZX3OR",
   "arn:aws:dms:us-east-1:4675541064:endpoint:GHXOLNW2E5BFXIYR766EZE"
  ]
}
    • Once the above tags.json is created, execute the below CLI
             aws resourcegroupstaggingapi tag-resources --cli-input-json file://tags.json 


Terraform: (Option 3)

Terraform provides an option under default_tags block which applies tags to all resources managed by this aws provider.

provider "aws" {
  profile = "default"
  region  = "us-east-1"

  default_tags {
    tags = {
    "AppName": "WebsiteApp",
    "APPID": "12345678",
    "Architecture": "MultiTrier",
    "ENV": "Production",
    "Severity": "SEV1"
    }
  }
}



 

No comments:

Post a Comment

Featured Post

Cloud : A Trendsetter Technology