Logging EC2 power state before maintenance window, then return to that state

0

Hello All, I need to patch EC2 instances that are currently powered down and return them to this state after patching. I'm trying to figure out if there is an easy way to track the power state of an EC2 instance before starting it for a maintenance window. I know maintenance windows automation tasks can power on and power off EC2 instances, but how would it keep track of an instances state so I can return it to that state after the maintenance window is over? After googleing for days, I've read a few people suggesting you can trigger a lambda function to run first and tag your instances with a state tag, once your maint window is over, you run another lamba that captures all instances with the tag state of say "powerOffWhenDone" and you then power them off and remove the tag. Can anybody suggest any other methods their currently using? I cant find much in regards to this topic.

2 réponses
0

Hello. Just come across your post. I'm looking for the same solution. Did you eventually go for the lambda method that records the instance state as a tag? Thanks

Kal
répondu il y a un an
  • Hey Kal, I couldn't find anything much on the internet besides suggesting lambda BUT I stumbled upon Systems Manager > Automation .. Which allows you to write "documents", these documents can execute a script or call AWS APIs and all other sorts of neat stuff. https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-automation.html

    So what I ended up doing was creating an automation doc that executes a powershell script that finds all powered off EC2 instances, tags them then powers them on. You can then put this automation doc in a maintenance window that runs say monthly. After the instances are patched, you can trigger another doc that shutsdown instances and removes the tags. This method was pretty simple, i dont have much experience with lambda so this approach was much easier to build. I also did stumble upon this doc, which explains how to make a parent-child automation doc which i think will be my ultimate end goal so i can scrap the powershell.

    https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-authoring-runbooks-parent-child-example.html

0

Thanks for the reply. Yes the pshell method sounds like an easier option. I'm more comfortable with powershell than Lambda, so will try that. Thanks again for your help.

Kal
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions