Linux | Cloud | DevOps | Scripting

Breaking

Friday 23 August 2019

Stop and Start EC2 Instances at Scheduled Intervals Using Lambda


To do this practice, first we need to go through one more practical, using below-provided URL:

https://redhatpanacia.blogspot.com/2019/08/lambda.html

Step 1: Schedule a Cron using CloudWatch:

AWS ➔ Services ➔ CloudWatch ➔ Events ➔ Get started ➔ [*] Schedule ➔ [*] Cron expression: (provide UTC timing here because AWS cron uses Universal time)…

As I am doing this practical in India, so, I need to convert time from IST to UTC.

To open the converter click on URL:

https://www.worldtimebuddy.com/ist-to-utc-converter

to learn AWS Schedule Expressions for a role, use URL:

https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html

AWS Cron scheduler does not support all '*' together, we need to provide one '?' among them.

…select the UTC time and provide Cron expression: 46 7 * * ? * ➔ as we provide Cron expressions, this will result us the timings on which Lambda will start the instance…

Event Source
Fig: Event Source
… ➔ Add target: as our instance is stopped, select Lambda function which we created to start the instance ➔ Configure details ➔ Rule definition: Name: start_instance ➔ provide some description ➔ State: enabled ➔ Create rule.

Step 2: Verify the status of instance:

AWS ➔ Services ➔ EC2 ➔ Here, we can see that instance is in running state now.

Similarly, you can create a rule to stop the instance also.

Enjoy!


1 comment:

Pages