我正在尝试使用Boto3创建AWS快照,但据我所知n个选项失败。
connection=ec2.connect_to_region('ap-southeast-1')
def Create_Snapshot(Source_volID):
snapshot = connection.create_snapshot(Source_volID)
while snapshot.status != 'completed':
snapshot.update()
print snapshot.status
time.sleep(5)
if snapshot.status == 'completed':
connection.create_tags(Resources=[snapshot.id], Tags=[{'Key':'Name', 'Value':'uat3-gold-'}])
return snapshot.id
这将返回错误:
Traceback (most recent call last):
File "/Users/py-projects/8.py", line 62, in <module>
print Create_Snapshot(Source_volID)
File "/Users/py-projects/8.py", line 47, in Create_Snapshot
connection.create_tags(Resources=[snapshot.id], Tags=[{'Key':'Name', 'Value':'uat3-sogpet-gold-'}])
TypeError: create_tags() got an unexpected keyword argument 'Resources'
还尝试了stackoverflow中提到的其他方式。
def Create_Snapshot(Source_volID):
snapshot = connection.create_snapshot(
VolumeId=Source_volID,
Description='Gold volume copy',
TagSpecifications=[
{
'ResourceType': 'snapshot',
'Tags': [
{
'Key': 'Name',
'Value': 'uat3-gold-'
}
]
},
]
)
while snapshot.status != 'completed':
snapshot.update()
print snapshot.status
time.sleep(5)
if snapshot.status == 'completed':
connection.create_tags(Resources=[snapshot.id], Tags=[{'Key':'Name', 'Value':'uat3-sogpet-gold-'}])
return snapshot.id
原因错误:
Number of snaps 0
No Snapshots present within 10 minutes
vol-0xxxxxxxxxxxxxxx
Traceback (most recent call last):
File "/Users/py-projects/8.py", line 76, in <module>
print Create_Snapshot(Source_volID)
File "/Users/py-projects/8.py", line 50, in
Create_Snapshot
'Value': 'uat3-gold-'
TypeError: create_snapshot() got an unexpected keyword argument 'VolumeId'
我也在python3中尝试过,但是失败了。请给我一个线索,因为我坚持了两天。谢谢。
答案 0 :(得分:1)
尝试这种方式。
session = boto3.Session(profile_name=profile, region_name=region)
client = session.client('ec2')
client.create_snapshot(
Description='Gold volume copy',
VolumeId=Source_volID,
TagSpecifications=[
{
'ResourceType': 'snapshot',
'Tags': [
{
'Key': 'Name',
'Value': 'uat3-gold-'
}
]
}
]
)