使用 boto3 复制 AWS 快照

Copying AWS Snapshots using boto3

我有一段源区域和目标区域的代码。我设法对所有快照数据做出响应,但我无法设法将响应过滤到 "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)

在这种情况下,我收到一个 json 响应,看起来像 {'OwnerId': 'xxxxxxx', 'StartTime': datetime.xxxxxxxx, 'SnapshotId': 'snap-xxxxxxxxxx", 等.....}.

如何过滤此输出并复制快照?

参考: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'],
    )