{"id":22111687,"url":"https://github.com/phx/autotags","last_synced_at":"2025-03-24T04:34:09.006Z","repository":{"id":121578112,"uuid":"254411261","full_name":"phx/autotags","owner":"phx","description":"Automatically tag AWS resources using awscli based on key/value pairs in a spreadsheet.","archived":false,"fork":false,"pushed_at":"2020-04-15T21:53:20.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T10:33:58.395Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phx.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-09T15:36:46.000Z","updated_at":"2020-04-15T21:53:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"fbb0a24f-e57a-483d-9d10-93b41ff760f3","html_url":"https://github.com/phx/autotags","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phx%2Fautotags","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phx%2Fautotags/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phx%2Fautotags/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phx%2Fautotags/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phx","download_url":"https://codeload.github.com/phx/autotags/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245211861,"owners_count":20578437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T10:50:33.886Z","updated_at":"2025-03-24T04:34:08.989Z","avatar_url":"https://github.com/phx.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AWS Auto Tags\n\nThis is a simple script I created in order to simplify the tagging of AWS resources.\nThere isn't a global top-level command for tagging in `awscli` since each service uses their own API.\nThis means some commands to create tags are a bit different.\n\nThis script is extremely simple and is by no means full-featured or even complete.\nI'm just updating it as I go along.\nI'm using it for work, but there is nothing organization-specific about it, so I figured I would share it in case others could benefit from it or wanted to contribute.\n\n---\n\n## Usage\n\n```\n\nUsage: ./autotags.sh [API] [RESOURCES]\n\n$API and $RESOURCES can also be specified as environment variables.\n\nNote: If $API is specified as an environment variable,\n      the first argument must include the word 'resource' or 'arn',\n      followed by the resources you wish to tag.\n\nBy default, ./autotags.sh looks for 'tags.csv' in the current directory.\nIf you wish to use a different CSV file, you can specify it at runtime\nby passing it as the $FILE environment variable.\n\nExamples:\n\n1) FILE=/home/ubuntu/my_tags.csv ./autotags.sh ec2 [instance-id] [instance-id] [instance-id]\n2) RESOURCES='instance-1-id instance-2-id instance-3-id' API=ec2 ./autotags.sh\n3) API=ec2 ./autotags.sh resources [instance-id] [intance-id] [instance-id]\n4) ./autotags.sh acm [certificate-arn]\n\nTested APIs:\nacm\ncloudfront\nec2\nelb\nelbv2\ns3api\n```\n\nScript variables can be passed in as both command line parameters, as well as environment variables.\n\n**It's only looking for 3 things:**\n- `$API` (or first argument)\n- `$RESOURCES` (or every argument after `$1` unless `$API` is defined *AND* `resources` or `arns` is passed as `$1`)\n- `$FILE` (or a file in the same directory named `tags.csv`)\n\n**Caveats:**\n- This script does not work with `.xlsx` or Excel-specific filetypes -- **ONLY CSV!**\n- `mlr` (miller) and `jq` are required for tagging S3 resources.\n\n---\n\n### Example one-liner with command line arguments\n\n`./autotags.sh ec2 instance-1-id instance-2-id instance-3-id`\n\nThis will apply the key/value pairs listed in `tags.csv` to the 3 instances passed on the command line.\n\n### Example one-liner with environment variables\n\n`FILE='/home/ubuntu/Downloads/my_spreadsheet.csv' API=ec2 RESOURCES='instance-1-id instance-2-id instance-3-id' ./autotags.sh`\n\nThis will apply the key/value pairs listed in `/home/ubuntu/Downloads/my_spreadsheet.csv` to the 3 EC2 instances that are separated by spaces in the `$RESOURCES` variable.\n\nVariables *must be passed on the same command line when running the script* unless you `export` them first.\n\n---\n\n### Other information\n\n`awscli` supports multiple resources in API calls, and I believe in some cases can support up to 1,000 resource IDs or ARNs.\n\nSince AWS APIs are optimized for this, if you need to tag 1,000 EC2 instances, it would be much quicker to get a list of those instances and pass them all at once, rather than making a separate API call to tag\neach instance.  See examples below.\n\n**Rather than doing this:**\n\n```sh\nfor i in $(aws ec2 describe-instances --query \"Reservations[*].Instances[*].InstanceId\" --output text); do\n  ./autotags.sh ec2 \"$i\"\ndone\n```\n\n**It would probably be more efficient to do this:**\n\n`RESOURCES=\"$(aws ec2 describe-instances --query \"Reservations[*].Instances[*].InstanceId\" --output text | tr '\\n' ' ')\" ./autotags.sh ec2`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphx%2Fautotags","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphx%2Fautotags","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphx%2Fautotags/lists"}