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 in AWS by william
52 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 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 in AWS by Priyaj
• 56,960 points
416 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 in AWS by Esha
27 views
+1 vote
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 in AWS by Kalgi
• 45,780 points
122 views
0 votes
1 answer
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 in AWS by Kilga
26 views
0 votes
1 answer

Permission Denied: AWS EC2 FTP

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

answered Mar 28 in AWS by Kolki
164 views