如何过滤此输出并复制快照?解决方案参考:描述快照和复制快照 import boto3conn = 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 boto3REGIONS = ['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_snapshotimport boto3conn = 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快照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-10 07:42