Leo
Leo

Reputation: 862

how can I make a schedule(start, stop) for EC2 via API

I want to make a schedule and apply it to EC2 instances. How can I make schedule by using java sdk? for example, my schedule should contain policy that start instance at 7 am and stop instance at 6 pm.

Upvotes: 0

Views: 366

Answers (1)

Renato Gama
Renato Gama

Reputation: 16599

This can be very easily achieved by using a lambda function triggered by a cron pattern. Make sure to assign a role with permissions to start/stop your instances to the lambda function.

  1. Create a lambda function and then select CloudWatch Events under the section Add Triggers;

enter image description here

  1. Configure your desired pattern, you will need something like cron(0 7,18 * * *);

enter image description here

References:
1. Using AWS Lambda with Scheduled Events
2. Tutorial: Starting an EC2 Instance (Java SDK)

Upvotes: 2

Related Questions