Skip to content

Instantly share code, notes, and snippets.

@nhammad
Created August 15, 2022 16:43
Show Gist options
  • Save nhammad/acf158beabb1e652c7f168b147b727b8 to your computer and use it in GitHub Desktop.
Save nhammad/acf158beabb1e652c7f168b147b727b8 to your computer and use it in GitHub Desktop.
import logging
import os
import boto3
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def turn_off_instance(instance_ids):
ec2 = boto3.client('ec2', region_name=region)
ec2.stop_instances(InstanceIds=instance_ids)
logger.info(f'Instance(s) stopped')
def lambda_handler(event, context):
logger.info(f'event info -: {event}')
global region
region = 'eu-east-1'
global instance_id
instance_id = os.getenv('instance_id')
turn_off_instance([instance_id])
return {
'statusCode': 200,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment