Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Archives for tags

May 7, 2020

AWS EC2 Describe Snapshots

Here’s how to describe snapshots using query with tags.

aws ec2 describe-snapshots \
--owner-ids xxxxxxxxxxx \
--profile default \
--region us-east-2 \
--output text \
--query "Snapshots[*].[SnapshotId,Tags[?Key=='Name'].Value[] | [0]]"

aws ec2 describe-snapshots \ --owner-ids xxxxxxxxxxx \ --profile default \ --region us-east-2 \ --output text \ --query "Snapshots[*].[SnapshotId,Tags[?Key=='Name'].Value[] | [0]]"

Result.

snap-xxxxxxxxxxxxxxxxx	Server1
snap-xxxxxxxxxxxxxxxxx	Server2

snap-xxxxxxxxxxxxxxxxx Server1 snap-xxxxxxxxxxxxxxxxx Server2

January 15, 2020

AWS IAM Tag User

Here’s how to add tags to an existing user.

aws iam tag-user \
--user-name ulysses \
--tags "Key"="dept","Value"="it" "Key"="role","Value"="admin"

aws iam tag-user \ --user-name ulysses \ --tags "Key"="dept","Value"="it" "Key"="role","Value"="admin"

Tags with identical keys are overwritten. New keys are added.

August 26, 2019

AWS CLI EC2 Describe Tags

Here’s how to get a list of EC2 tags.

aws ec2 describe-tags \
--filters "Name=resource-id,Values=i-xxxxxxxxxxxxx" \
--query 'Tags[][Key,Value]'  \
--profile default \
--region us-east-1 \
--output text

aws ec2 describe-tags \ --filters "Name=resource-id,Values=i-xxxxxxxxxxxxx" \ --query 'Tags[][Key,Value]' \ --profile default \ --region us-east-1 \ --output text

August 2, 2019

Terraform Launch EC2 Instance

Here’s the template for launching an EC2 instance via Terraform.

provider "aws" {
  region                  = "us-east-1"
  shared_credentials_file = "/home/username/.aws/credentials"
  profile                 = "default"
}
resource "aws_security_group" "hostname-sg" {
	name = "allow ssh"
	vpc_id = ""
	ingress {
		cidr_blocks = [ "10.0.0.0/8" ]
		from_port = 22
		to_port = 22
		protocol = "tcp"
	}
	egress {
		from_port = 0
		to_port = 0
		protocol = "-1"
		cidr_blocks = [ "0.0.0.0/0" ]
	}
}
resource "aws_instance" "hostname" {
	ami = "ami-xxxxxxxxxx"
	key_name = "your-key"
	instance_type = "t2.large"
	subnet_id = "subnet-xxxxxxxx"
	security_groups	= ["${aws_security_group.hostname-sg.id}"]
	tags {
		Name = "hostname"
		Environment = "development"
	}
}

provider "aws" { region = "us-east-1" shared_credentials_file = "/home/username/.aws/credentials" profile = "default" } resource "aws_security_group" "hostname-sg" { name = "allow ssh" vpc_id = "" ingress { cidr_blocks = [ "10.0.0.0/8" ] from_port = 22 to_port = 22 protocol = "tcp" } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = [ "0.0.0.0/0" ] } } resource "aws_instance" "hostname" { ami = "ami-xxxxxxxxxx" key_name = "your-key" instance_type = "t2.large" subnet_id = "subnet-xxxxxxxx" security_groups = ["${aws_security_group.hostname-sg.id}"] tags { Name = "hostname" Environment = "development" } }

July 22, 2019

AWS CLI Add Tags to IAM User

How to add tags to an existing IAM user via AWS CLI.

aws iam tag-user \
--user-name john.doe \
--tags '{"Key": "Department", "Value": "Accounting"}'

aws iam tag-user \ --user-name john.doe \ --tags '{"Key": "Department", "Value": "Accounting"}'

Multiple tags.

aws iam tag-user \
--user-name john.doe \
--tags '[{"Key": "Department", "Value": "Accounting"},{"Key": "Manager", "Value": "jane.doe"}]'

aws iam tag-user \ --user-name john.doe \ --tags '[{"Key": "Department", "Value": "Accounting"},{"Key": "Manager", "Value": "jane.doe"}]'

  • « Previous Page
  • 1
  • 2
  • 3
  • Next Page »
  • Cloud
  • Linux
  • Git

Copyright © 2012–2021