Skip to main content

ami

create AMI

aws ec2 create-image --description 'backup ami of test server' --instance-id i-xxxx --name 'backup ami of test server' --no-reboot
aws ec2 deregister-image --image-id ami-xxxx 
aws ec2 describe-snapshots --owner-id xxxx --query 'Snapshots[?contains(Description, `ami-xxxx`)]'

create an instance with AMI

aws ec2 run-instances \
--image-id ami-xxxx \
--instance-type t4g.nano \
--key-name testkey \
--security-group-ids sg-xxxx \
--subnet-id subnet-xxxx \
--credit-specification 'CpuCredits=standard' \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=copied_instance}]' \
--associate-public-ip-address

delete AMI

aws ec2 deregister-image --image-id ami-xxxx 
aws ec2 describe-snapshots --owner-id xxxx --query 'Snapshots[?contains(Description, `ami-xxxx`)].SnapshotId'
aws ec2 delete-snapshot --snapshot-id snap-xxxx