Reputation: 307
I have several docker containers running on an AWS EC2 instance, and was trying to find out how to run a script/commands (cd
& docker-compose
commands) after a CloudWatch alarm reboot were to ever occur.
I'm coming up short as to how to do this with the articles I've found on AWS. Thanks in advance!
Upvotes: 1
Views: 176
Reputation: 26163
Generally speaking, you shouldn't really be doing this. If you want to make sure that a certain program is always running (and thus resilient to reboots) you should be using a service manager (e.g. systemd
).
That said, if you must do things this way, then the best way to do this would be to use an EventBridge event that is triggered when the instance enters the running
state (which is what would happen after a successful reboot), which executes an SSM Run Command document (with the cd
and docker-compose
commands) against the EC2 instance. For this, you would need to install the SSM agent on the instance.
Helpful links:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-instance-state-changes.html
https://docs.aws.amazon.com/systems-manager/latest/userguide/execute-remote-commands.html
Upvotes: 1