[英]wait until the snapshot is completed with boto3 and lambda
我在 lambda 中编写了 python 代码来创建快照并等到它完成执行其余代码但我有错误
"errorMessage": "Parameter validation failed:\nUnknown parameter in input: \"SnapshotsId\", must be one of: Filters, MaxResults, NextToken, OwnerIds, RestorableByUserIds, SnapshotIds, DryRun",
"errorType": "ParamValidationError",
编码
from __future__ import print_function
import botocore
import boto3
import urllib.request
def lambda_handler(event, context):
ec2_client = boto3.client('ec2', region_name='eu-west-1')
snapshot1 = ec2_client.create_snapshot(VolumeId='vol-054c95927bb8ed4a9', Description='Created by Lambda backup function ebs-snapshots')
try:
snapshot_id = snapshot1['SnapshotId']
snapshot_complete_waiter = ec2_client.get_waiter('snapshot_completed')
snapshot_complete_waiter.wait(SnapshotsId=['snapshot_id'])
except botocore.exceptions.WaiterError as e:
if "max attempts exceeded" in e.message:
print("snapshot not completed")
else:
print(e.message)
您必须使用SnapshotIds
而不是SnapshotsId
:
from __future__ import print_function
import botocore
import boto3
import urllib.request
def lambda_handler(event, context):
ec2_client = boto3.client('ec2', region_name='eu-west-1')
snapshot1 = ec2_client.create_snapshot(VolumeId='vol-054c95927bb8ed4a9', Description='Created by Lambda backup function ebs-snapshots')
try:
snapshot_id = snapshot1['SnapshotId']
snapshot_complete_waiter = ec2_client.get_waiter('snapshot_completed')
snapshot_complete_waiter.wait(SnapshotIds=[snapshot_id])
except botocore.exceptions.WaiterError as e:
print(e)
使用这个功能:
snapshot.wait_until_completed()
参考: https : //boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Snapshot.wait_until_completed
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.