使用boto3复制AWS快照 [英] Copying AWS Snapshots using boto3
本文介绍了使用boto3复制AWS快照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有用于源和目标区域的一段代码.我设法对所有快照数据进行了响应,但是我无法仅对"SnapshotId"进行过滤并复制响应.
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)
在这种情况下,我收到了一个类似{'OwnerId':'xxxxxxx','StartTime':datetime.xxxxxxxx,'SnapshotId':'snap-xxxxxxxxxx等.....}的JSON响应.>
如何过滤此输出并复制快照?
解决方案
参考:复制快照
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'],
)
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?
解决方案
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'],
)
这篇关于使用boto3复制AWS快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文