46
loading...
This website collects cookies to deliver better user experience
sam init
import json
import boto3
from datetime import date
ec2 = boto3.client('ec2')
def lambda_handler():
return {
"statusCode": 200,
"body": json.dumps({
"message": "Success",
}),
}
snapshots = ec2.describe_snapshots(
Filters=[{
'Name': 'owner-id',
'Values': ['YOUR_OWNER_ID'],
},
{
'Name': 'storage-tier',
'Values': ['standard'],
},
])
import json
import boto3
from datetime import date
ec2 = boto3.client('ec2')
def lambda_handler():
snapshots = ec2.describe_snapshots(
Filters=[{
'Name': 'owner-id',
'Values': ['YOUR_OWNER_ID'],
},
{
'Name': 'storage-tier',
'Values': ['standard'],
},
])
for snapshot in snapshots['Snapshots']:
if snapshot['StartTime'].date() < date.today():
response = ec2.modify_snapshot_tier(
SnapshotId=snapshot['SnapshotId'],
StorageTier='archive'
)
return {
"statusCode": 200,
"body": json.dumps({
"message": "Success",
}),
}
Events:
ScheduledEvent:
Type: Schedule
Properties:
Schedule: "cron(* 10 * * ? *)"
Enabled: True