https://pulumi.com logo
Title
b

bumpy-laptop-30846

05/12/2021, 9:23 AM
Hello, Is it possible to dynamically start / stop an existing ec2 instance? Pulumi up would start the instance, destroy would stop it, without destroying it? I don’t see how to do it with the api.
b

brave-planet-10645

05/12/2021, 9:47 AM
EC2 instances come up started by default. If you wanted to then stop it, you can do that but you'll need to use automation API and the AWS SDK as there isn't a property on the instance resource that says "start the instance, run any user data etc and then stop it"
b

bumpy-laptop-30846

05/12/2021, 10:02 AM
ok thank you. No plan on providing this feature?
b

brave-planet-10645

05/12/2021, 10:22 AM
Not as far as I know, using the base Pulumi software. As I said, you could do something using automation API to stop the instance once the provisioning has been completed.
m

millions-furniture-75402

05/12/2021, 1:59 PM
b

brave-planet-10645

05/12/2021, 2:02 PM
Great point. I always forget about tying things like this up with event bridge. Good spot
Having said that, what triggers the "running" event? Is it when the instance has started or when everything has finished (including all the cloud-init stuff)? From experience, running doesn't mean that userData has finished being run, for example
But I guess you could do "running + 5 minutes" or something like that