BuffaloSpeedway
BuffaloSpeedway

Reputation: 31

Determine if AWS instance started by scheduler or manually

Can a script query if the EC2 instance was started by the AWS Instance Scheduler?

I'd like to put code in rc.local that would run a script only if the instance was started by AWS Instance Scheduler. If the instance was started manually from the web console, the script would not run.

Upvotes: 0

Views: 240

Answers (1)

marekful
marekful

Reputation: 15361

Use Automated Tagging.

The Instance Scheduler can automatically add tags to all instances it starts or stops.

https://docs.aws.amazon.com/solutions/latest/instance-scheduler/components.html?shortFooter=true

You can retrieve current tags of an instance via Describe Tags API. If, for example, you would invoke your script from "User Data", you could check if the tag added automatically by the Scheduler exists and skip the script.

Note, automatically added tags are removed during scheduled stop.

Upvotes: 1

Related Questions