AWS CLI Command to fetch RDS Snapshot Details

0

Can someone Please Help me in Fetching the AWS RDS Snapshots which are older than 1 month using "AWS CLI" Command.

Regards, kalyan varma

2개 답변
1
aws rds describe-db-snapshots --query "DBSnapshots[?SnapshotCreateTime <= \`"$(date --date "30 days ago" +"%Y-%m-%dT%H:%M:%S.000000+00:00")"\`]"
profile pictureAWS
전문가
kentrad
답변함 일 년 전
0

First, install the necessary libraries for Python:

pip install python-dateutil

Create a Python script - list_old_snapshots.py

import sys
import json
import dateutil.parser
from datetime import datetime, timedelta

# Load JSON input from stdin
snapshots = json.load(sys.stdin)

# Get the date one month ago
one_month_ago = datetime.now(dateutil.tz.tzutc()) - timedelta(days=30)

# Filter snapshots older than one month
old_snapshots = [snapshot for snapshot in snapshots['DBSnapshots'] if dateutil.parser.parse(snapshot['SnapshotCreateTime']) < one_month_ago]

# Print filtered snapshots as JSON
print(json.dumps(old_snapshots, indent=2, default=str))

Now, use the following command to get the RDS snapshots older than one month:

aws rds describe-db-snapshots | python list_old_snapshots.py

profile picture
전문가
답변함 일 년 전
  • Thanks. Will check and Let you know.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인