Delete the old instance in AWS

0 votes

I am trying to delete the old instance using the following command

aws ec2 describe-snapshots --filters Name=description,Values=$Description | grep "SnapshotId" | head -n -$Local_numbackups | awk '{print $2}' | sed -e 's/,//g' | xargs -n 1 -t aws ec2 delete-snapshot --snapshot-id

This is not working can someone help me as where I have done the mistake?

Mar 28, 2019 in AWS by william
463 views

1 answer to this question.

0 votes
# Get array of snapshot IDs sorted by age (oldest to newest) //can be done from your console
snapshots=($(aws ec2 describe-snapshots --filters Name=description,Values=$Description --query 'Snapshots[*].[StartTime,SnapshotId]' --output text | sort -n | sed -e 's/^.*\t//'))
# Get number of snapshots
count=${#snapshots[@]}

if [ "$count" -lt "$Local_numbackups" ]; then
  echo "We already have less than $Local_numbackups snapshots"
  exit 0
else
  # Drop the last (newest) $Local_numbackups IDs from the array
  snapshots=(${snapshots[@]:0:$((count - Local_numbackups))})
  # Loop through the remaining snapshots and delete
  for snapshot in ${snapshots[@]}; do
    aws ec2 delete-snapshot --snapshot-id $snapshot
  done
fi

Source: Github

answered Mar 28, 2019 by veena chinna

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 58,090 points
2,929 views
0 votes
1 answer

How to change the instance type in AWS?

Using the AWS Console. You can follow ...READ MORE

answered Mar 26, 2019 in AWS by Esha
715 views
+3 votes
1 answer

How to make the instance IP static in nature? - AWS

Hey @Laksha! By default, all instances have a ...READ MORE

answered Apr 11, 2019 in AWS by Kalgi
• 52,360 points
1,028 views
0 votes
1 answer

Using Shapely on AWS Lambda with Python 3

For some reason, the pip install of ...READ MORE

answered Oct 8, 2018 in AWS by Priyaj
• 58,090 points
2,568 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Usage in EC2 instance in AWS

If you are using your application in ...READ MORE

answered Mar 28, 2019 in AWS by Kilga
286 views
0 votes
1 answer

Permission Denied: AWS EC2 FTP

This is a permission issue. You can ...READ MORE

answered Mar 28, 2019 in AWS by Kolki
1,886 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP