簡體   English   中英

使用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)

在這種情況下,我收到一個類似於{'OwnerId':'xxxxxxx','StartTime':datetime.xxxxxxxx,'SnapshotId':'snap-xxxxxxxxxx“等的json響應。

如何過濾此輸出並復制快照?

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM