简体   繁体   中英

wait until the snapshot is completed with boto3 and lambda

i wrote python code in lambda to create snapshot and wait until it completed to execute the rest of the code but i have error the error

"errorMessage": "Parameter validation failed:\nUnknown parameter in input: \"SnapshotsId\", must be one of: Filters, MaxResults, NextToken, OwnerIds, RestorableByUserIds, SnapshotIds, DryRun",
  "errorType": "ParamValidationError",

the code

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)

You must use SnapshotIds instead of 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM