Auto Start & Stop EC2 Instance at a Specific Time Using AWS EventBridge by awsmasterchef

preview_player
Показать описание
In this video we have created an EventBridge schedule that triggers an Lamba function which is responsible for start and stop of EC2 Instance

#aws #ec2 #awslambda
Рекомендации по теме
Комментарии
Автор

This is a great way to start / stop an EC2 instance. Thank you for this, however you should put the Lambda function in your video description to avoid people needing to manually type it out.

I have typed out the function here in case anyone needs it:

import boto3

def lambda_handler(event, context):
ec2 = boto3.client('ec2')
action = event['action']
instances = ec2.describe_instances()
instance_ids = [instance['InstanceId'] for reservation in instances['Reservations'] for instance in reservation['Instances']]
if action == 'start':
if instance_ids:

print('Starting instances;", instance_ids)
else:
print("No instances found to start")
elif action == 'stop':
if instance_ids:

print("Stopping instances:", instance_ids)
else:
print("No instances found to stop")
else:
print("Invalid action provided in the event")

uganrajoo