【问题标题】:Copying AWS Snapshots using boto3使用 boto3 复制 AWS 快照
【发布时间】:2018-08-13 20:29:35
【问题描述】:

我有一段用于源区域和目标区域的代码。我设法对所有快照数据进行了响应,但我无法将响应仅过滤到“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", etc .....} 的 json 响应。

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

【问题讨论】:

  • 只是为了理解清楚,您想将快照从eu-central-1复制到eu-west-3
  • 是的,但我有点搞砸了......我给了这段代码。我希望将来成为每个新快照然后复制的东西。
  • 查看以下解决方案。对我来说,你的问题看起来就足够了。

标签: python amazon-web-services boto3 snapshot


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-15
    • 1970-01-01
    • 2022-12-12
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多