Copying AWS Snapshots using boto3

删除回忆录丶 提交于 2019-12-24 18:27:03

问题


I have piece of code for source and destination regions. I managed to have a reponse with all snapshot data but I can't manage to filter the response just to "SnapshotId" and copying it.

import boto3

REGIONS = ['eu-central-1', 'eu-west-3']

SOURCEREG = boto3.client('ec2', region_name='eu-central-1')
DISTREG = boto3.client('ec2', region_name='eu-west-3')

response = SOURCEREG.describe_snapshots()
print(response)

In this case I receive a json response looking like {'OwnerId': 'xxxxxxx', 'StartTime': datetime.xxxxxxxx, 'SnapshotId': 'snap-xxxxxxxxxx", etc .....}.

How can i filter this output and copy the snapshots?


回答1:


Reference: describe_snapshots and copy_snapshot

import boto3

conn = boto3.client('ec2', region_name='eu-central-1')
response = conn.describe_snapshots()

for snapshots in response['Snapshots']:
    print('Copying Snapshot -> ' + snapshots['SnapshotId'])
    copy_response = conn.copy_snapshot(
        Description='Snapshot copied from' + snapshots['SnapshotId'],
        DestinationRegion='eu-central-1',
        SourceRegion='eu-west-3',
        SourceSnapshotId=snapshots['SnapshotId'],
    )


来源:https://stackoverflow.com/questions/51818413/copying-aws-snapshots-using-boto3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!