Make Your .Ebextensions PowerShell scripts "Self Destruct"

If you’re using Amazon’s PaaS offering, Elastic Beanstalk, you’re more than likely using .EBExtensions to control the configuration or other aspects of your applications. And I’m sure, As any responsible devloper/admin would, you’re cleaning up after yourself as well… right?

In the event that you aren’t, its not tough to start. In fact, here is the PowerShell code you need to have your scripts remove themselves after they’ve completed their duties.

Remove-Item -LiteralPath $MyInvocation.MyCommand.Path -Force

Just throw that in as the last line of your PowerShell script and they’ll run through their task and then - *poof* - no more script!

This is particularly useful for things that are only needed on initial deployments, or only need to be run once. I personally use it to setup scheduled tasks on the initial deployment.

Curtis Rissi

Solutions Architect and Full Stack Engineer by day and mad scientist by night. I specialize in making the impossible possible through code and technology. I also make some crazy good Korean BBQ. You know you want to try it.

Disclaimer: I work for AWS, but unless otherwise stated, the words and thoughts expressed in this blog are my own.

comments powered by Disqus