how to upgrade aws ena driver through SSM(powershell ) and restart at end ?

0

cd cd Temp\AwsEnaNetworkDriver

.\install.ps1

Restart-Computer

am using above powershell script to upgrade AWS ena driver in all EC2 windows servers. if you guys know, when install/upgrading it - server goes offline for 15-20seconds and come back online. and if i restart manually - all looks good.

but if i use "restart-computer" at the end as above commands - it restarts and even after 30 mins ec2 instance does not finish rebooting. i have to force stop and start it and all looks good.( because 15-20 seconds of upgrade proecess does not happen, it goes to restart command straightaway after running the "install.ps1" script. ) even if i use the sleep command for 30 seconds before restart command, (15-20 seconds of upgrade process does not happen )

how do i write powershell, to give "install.ps1" to run for 15-20 seconds, then run next line either sleep or restart ? ?

profx
asked 9 months ago460 views
2 Answers
1

Have you tried using the start-job and wait-job powershell commands for the install.ps1 script? This may provide the time this scripts needs to complete.

Hope this helps, if it does please accept this answer.

profile picture
answered 9 months ago
0

If using SSM aka AWS Systems Manager, then save yourself the trouble and use the free built in AWS automation document called AWSSupport-UpgradeWindowsAWSDrivers [1]

This automation document has all the checks and balances in place and achieves your objective.

Now if you still want to DIY this with your own script then consider using exit code 3010 in place of Restart-Computer


"For Windows managed nodes, you specify exit 3010 in your script. For Linux and macOS managed nodes, you specify exit 194. The exit code instructs AWS Systems Manager Agent (SSM Agent) to reboot the managed node, and then restart the script after the reboot completed. Before starting the reboot, SSM Agent informs the Systems Manager service in the cloud that communication will be disrupted during the server reboot."


"When developing scripts that reboot managed nodes, make the scripts idempotent so the script execution continues where it left off after the reboot. Idempotent scripts manage state and validate if the action was performed or not. This prevents a step from running multiple times when it's only intended to run once." [2]


Example of idempotent code:

If (desired package not installed) 
    {
        Install package
        exit 3010
    }

References:

[1] https://docs.aws.amazon.com/systems-manager-automation-runbooks/latest/userguide/automation-awssupport-upgradewindowsawsdrivers.html

[2] https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-reboot.html

profile pictureAWS
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions