Created
August 15, 2022 16:43
-
-
Save nhammad/acf158beabb1e652c7f168b147b727b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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