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

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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

if [ "$count" -lt "$Local_numbackups" ]; then
  echo "We already have less than $Local_numbackups snapshots"
  exit 0
  # 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

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,140 points
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
0 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 in AWS by Kalgi
• 36,220 points
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
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

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.