Service |
Command |
Purpose |
EC2 |
aws ec2 describe-regions |
Describes one or more regions that are currently available to you |
EC2 |
aws ec2 start-instances --instance-ids instance_id |
|
EC2 |
aws ec2 stop-instances --instance-ids instance_id |
|
EC2 |
aws ec2 terminante-instances --dry-run --instance-ids instance_id |
|
EC2 |
aws ec2 create-tags --resources instance_id --tags Key=Department,Value=Finance |
|
EC2 |
aws ec2 describe-volumes |
|
EC2 |
aws ec2 attach-volume --volume-id vol-1d5cc8cc --instance-id instance_id --device /dev/sdh |
|
EC2 |
aws ec2 run-instances
--dry-run
--image-id ami-08111162
--count 1
--instance-type t1.micro
--key-name MyKeyPair
--security-groups my-ami-security-group |
|
EC2 |
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
|
|
EC2 |
aws ec2 reboot-instances --instance-ids instance_id |
|
EC2 |
aws ec2 modify-instance-attribute --instance-id instance_id --instance-type "{\"Value\": \"m1.small\"}" |
|
EC2 |
aws ec2 create-image --instance-id instance_id --name "Dev AMI" --description "AMI for development server" |
|
EC2 |
aws ec2 describe-images --image-ids ami-2d574747 |
|
EC2 |
aws ec2 deregister-image --image-id ami-2d574747 && aws ec2 delete-snapshot --snapshot-id snap-4e665454 |
|
EC2 |
aws ec2 delete-snapshot --snapshot-id snap-4e665454 |
|
EC2 |
aws ec2 modify-instance-attribute --instance-id instance_id --disable-api-termination |
|
EC2 |
aws ec2 modify-instance-attribute --instance-id instance_id --no-disable-api-termination |
|
EC2 |
aws ec2 get-console-output --instance-id instance_id |
|
EC2 |
aws ec2 monitor-instances --instance-ids instance_id |
|
EC2 |
aws ec2 unmonitor-instances --instance-ids instance_id |
|
EC2 |
aws ec2 describe-key-pairs |
|
EC2 |
aws ec2 create-key-pair --key-name dev-servers |
|
EC2 |
aws ec2 delete-key-pair --key-name dev-servers |
|
EC2 |
aws ec2 describe-instances --query 'Reservations[].Instances[?!not_null(Tags[?Key == `Environment`].Value)] | [].InstanceId' --output text
for i in `aws ec2 describe-instances --query 'Reservations[].Instances[?!not_null(Tags[?Key == \`Environment\`].Value)] | [].InstanceId' --output text`;do aws ec2 stop-instances --instance-ids $i;done;
|
List InstanceId that does not have Environment tag
Loop through ech instance_id and stop the instance
|
EC2 (security group) |
aws ec2 authorize-security-group-ingress --group-name "Bastion" --protocol tcp --port 22 --cidr YOUR-PUBLIC-IP-ADDRESS/32 |
edit ec2 security group to add ingress rule of tcp port 22 for a specified source cidr |
EC2 |
aws ec2 revoke-security-group-ingress --group-name "Bastion" --protocol tcp --port 22 --cidr YOUR-PUBLIC-IP-ADDRESS/32 |
edit ec2 security group to remove ingress rule of tcp port 22 for a specified source cidr |
EC2 |
aws ec2 run-instances --launch-template LaunchTemplateId=template-id,Version=2
or
:: when launching template that is using non default VPC, should specify the subnet id that is in the non-default VPC
aws ec2 run-instances --launch-template LaunchTemplateId=template-id,Version=1 --subnet-id=subnet-xxx
|
launch ec2 instance from launch template specified |
EC2 |
For all instances
aws ec2 describe-instance-status
For specific instance
aws ec2 describe-instance-status --instance-ids i-1234567890abcdef0
|
To view the instance(s) status |
EC2 |
aws ec2 describe-instance-status --filters Name=instance-status.status,Values=impaired
|
To get the status of all instances with an instance status of impaired |