. How to Create an EC2 Instance with a Tag Using the AWS CLI

How to Create an EC2 Instance with a Tag Using the AWS CLI

Ali Asgar Hussain
0


Learn how to create an Amazon Elastic Compute Cloud (EC2) instance with a tag using the AWS Command Line Interface (CLI). A comprehensive guide to help you streamline your AWS setup.
 
How to Create an EC2 Instance with a Tag Using the AWS CLI
How to Create an EC2 Instance with a Tag Using the AWS CLI

To create an EC2 instance with a tag using the AWS Command Line Interface (CLI), you can use the following command

aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-xxxxxxxx --subnet-id subnet-xxxxxxxx --tag-specifications ‘ResourceType=instance,Tags=[{Key=Name,Value=MyInstance}]’

In the above command, replace the ami-xxxxxxxx with the ID of the Amazon Machine Image (AMI) you want to use, replace MyKeyPair with the name of your Key Pair, replace sg-xxxxxxxx with the ID of your security group, replace subnet-xxxxxxxx with the ID of your subnet, and replace MyInstance with the desired name for your instance.

The tag-specifications argument allows you to specify tags for the instance, in this case, a tag with the key "Name" and value "MyInstance". You can add additional tags by adding more items to the tags array.

Reference Links:

AWS Command Line Interface (AWS CLI): https://aws.amazon.com/cli/

AWS EC2 User Guide: https://aws.amazon.com/ec2/user-guide/

AWS EC2 Instance creation using CLI: https://aws.amazon.com/getting-started/hands-on/run-instance-cli/

AWS EC2 Instance Tagging: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html




Tags

Post a Comment

0 Comments
Post a Comment (0)