Using ASP.NET based applications on AWS – part 2

Packaging the application is really not harder than calling : msbuild <pathtoprojectfile>  /t:Package /p:DeployIisAppPath=”Default Web Site”

But there is more…   Through configuration files in a subdirectory .ebextensions (at the level of web.config) you can add multiple .config files (in yaml format) that let you do all kinds of stuff, from running scripts, simple commands to downloading packages, unzip sources, …  
There are a few caveats you need to be aware of before you conclude it’s not working.

First of all, you have to have the YAML correct (no tabs, spaces only, consistent indentation and no typos in the allowed directives.  The .config files need to be set as “Content”, Copy always/newer otherwise the .ebextensions directory doesn’t end up in the package.  The .config files are processed in alphabetical order, so it’s good practice to name them 001-….config, 002-….config, etc. to keep your sanity.

An example:

        mysql: //

        command: "cd > c:\\command_whereami.txt"

        command: "cd > c:\\container_whereami.txt"
        command: powershell.exe -ExecutionPolicy Bypass -Command "Get-Service | Out-File c:\\services.log"

Packages are quite self-explanatory. You specify your package manager (here msi), an arbitrary name (here ‘MySQL’ and a download URL). It will silently download and install the msi.
Commands are a bit tricky.
First of all, you have the difference between commands and container_commands. The former are ran before the package gets unpacked, just before the staging, the latter just after the unpacking but before the web server gets started.
Both can be an array of strings or a single string.
If you are not sure about the YAML best it to use some kind of YAML linter, you have online versions like this one: //

About the commands, on windows the assumed comspec is “cmd” to you don’t have to explicity specify cmd /c “your command”, “your command” alone is enough.
Needless to say, if you want to use powershell you need to do like above. Call powershell.exe with the necessary options, including the commmand or a .ps1 file.

If you are unsure where you are running, then the trick with the 2 a-whereami commands in above sample puts text files in the root of the C drive to see where these commands are actually running.

If you want to know under which account you are running (quite important in you want to install a service for example), you can do a trick with whoami > c:\\command_whoami.txt.

There is tons of other stuff you can do with the EB extensions. A good starting point is the official documentation at // (for windows servers).

Ah, and yes, the commands are also executed in alphabetical order…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.