Skip to content

Instantly share code, notes, and snippets.

@MrHassanMurtaza
Created June 16, 2021 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrHassanMurtaza/34d14636eb637fc96e4db689f65abc56 to your computer and use it in GitHub Desktop.
Save MrHassanMurtaza/34d14636eb637fc96e4db689f65abc56 to your computer and use it in GitHub Desktop.
reboot ec2 instance using lambda
import json
import boto3
EC2_INSTANCE_ID="i-xxxxxx"
ec2_handle = boto3.client(
'ec2'
)
def lambda_handler(event, context):
response = ec2_handle.reboot_instances(
InstanceIds=[
EC2_INSTANCE_ID,
],
DryRun=False # change to True for dryrun
)
return {
'statusCode': 200,
'body': response
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment