DEV Community

Yvonne
Yvonne

Posted on

2

Add or Update a Tag on an EC2 Instance Using AWS CLI

When you're managing AWS resources like EC2 instances, keeping things organized is key especially as your environment grows. One of the easiest and most effective ways to stay organized is by using tags. Tags let you add key-value pairs to your resources, making it easier to track, sort, and manage everything.

Today, I’ll show you how to quickly add or update a tag on an EC2 instance using a simple AWS CLI command. It's quick and a habit that will make your cloud life a lot easier down the road.

1. Add or Update a Tag on an EC2 Instance
2. Business Use Case
3. Summary

1. Add or Update a Tag on an EC2 Instance

This command adds or updates a tag on an EC2 instance using AWS CLI.

Command:
aws ec2 create-tags\
--resources i-0123456789abcdef0 \
--tags Key=Environment,Value=Production \
--region us-east-1

Image description

  • Just replace the instance ID and region with your own.

Explanation:
aws ec2 create-tags - Main AWS CLI command to add or update tags
--resources - Specifies the EC2 instance (or multiple instances) you want to tag
--tags - Defines the key and value for the tag
--region - sets which AWS region you're working in

Image description

✅ If the tag already exists, this command updates it to the new value.
✅ If the tag doesn't exist, it creates it.

2. Business Use Case

By tagging EC2 instances with keys like Environment=Production or Owner=DevTeam, companies can easily generate cost reports, enforce automation scripts, or quickly identify critical systems during incidents. Without proper tagging, cloud environments can quickly become chaotic and expensive.

3. Summary

In real-world cloud environments, tagging resources isn’t just a nice-to-have; it's a best practice. Tags help teams track costs, manage environments, enforce security policies, and even automate processes across hundreds or thousands of resources. Tagging may seem like a small detail, but it really adds up once you're managing dozens or hundreds of AWS resources.

Connect with me on LinkedIn to comment or share your experiences with Linux.

#30DaysLinuxChallenge #RedHatEnterpriseLinux
#CloudWhistler #CloudEngineer #Linux
#DevOps #RedHat #OpenSource
#CloudComputing #WomenInTech

ACI image

ACI.dev: The Only MCP Server Your AI Agents Need

ACI.dev’s open-source tool-use platform and Unified MCP Server turns 600+ functions into two simple MCP tools on one server—search and execute. Comes with multi-tenant auth and natural-language permission scopes. 100% open-source under Apache 2.0.

Star our GitHub!

Top comments (3)

Collapse
 
nevodavid profile image
Nevo David

Neat article, tagging is a smart way to organize resources effectively. What strategies do you suggest for consistently applying naming conventions across a large number of resources?

Collapse
 
youngtech profile image
Yvonne

Yes. I showed a simple example, but I know you can write a script for this to automate it. Also, you agree with your team as to the naming convention of the resources, so everyone is on board with naming resources. Then when you search for a resource using a tag, everyone is on the same page regarding key tag names to search for. You want to be able to quickly find a resource.

Collapse
 
braingames profile image
Brain Games

nice!

ACI image

ACI.dev: Fully Open-source AI Agent Tool-Use Infra (Composio Alternative)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Check out our GitHub!

Join the Runner H "AI Agent Prompting" Challenge: $10,000 in Prizes for 20 Winners!

Runner H is the AI agent you can delegate all your boring and repetitive tasks to - an autonomous agent that can use any tools you give it and complete full tasks from a single prompt.

Check out the challenge

DEV is bringing live events to the community. Dismiss if you're not interested. ❤️