AWS Code Sample
Catalog demonstrates how to request a reboot of one or more Amazon EC2 instances.

# Copyright 2010-2019, Inc. or its affiliates. All Rights Reserved. # # This file is licensed under the Apache License, Version 2.0 (the "License"). # You may not use this file except in compliance with the License. A copy of the # License is located at # # # # This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS # OF ANY KIND, either express or implied. See the License for the specific # language governing permissions and limitations under the License. import boto3 from botocore.exceptions import ClientError ec2 = boto3.client('ec2') try: ec2.reboot_instances(InstanceIds=['INSTANCE_ID'], DryRun=True) except ClientError as e: if 'DryRunOperation' not in str(e): print("You don't have permission to reboot instances.") raise try: response = ec2.reboot_instances(InstanceIds=['INSTANCE_ID'], DryRun=False) print('Success', response) except ClientError as e: print('Error', e)

Sample Details

Service: ec2

Last tested: 2018-06-25

Author: jschwarzwalder (AWS)

Type: full-example

On this page: