8

I'm deploying a Windows / .NET MVC app on Elastic Beanstalk, and managed to get through most of the challenges except for one.

The webapp in question creates a local cache for binary assets in a subfolder of its current deployment location, and for this to work I need to add permissions for the IIS_IUSRS group to read/write to that folder.

After a long trial-and-error exercise I now have a solution that seems to work, but I am not 100% sure of the "legality" of it...

In the MVC solution, I created a folder named ".ebextensions", and in it a yaml file named "eb.config".

In this file I basically create 2 batch files that I deploy to c:\temp - the first batch file checks if there is already a copy of the 2nd file in C:\Program Files\Amazon\ElasticBeanstalk\hooks\appdeploy\post, and if not, copies it there.

The 2nd batch file sets the required ACL for this "BinaryData" folder. Elastic Beanstalk executes any batch file it finds in the folder mentioned above, and this seems to do the trick for now.

I haven't been able to find any documentation on how to achieve this "officially", and found out about this trick from this blogpost.

Any suggestions on how to achieve this in a "cleaner" way would be much appreciated.

Nuno Linhares
  • 545
  • 3
  • 11
  • Did you look at Elastic Beanstalk platform hooks? https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/custom-platform-hooks.html – Lech Migdal Sep 02 '18 at 06:52

1 Answers1

8

It's 2019 and I still couldn't find any documentation for Beanstalk Platform Hooks regarding .NET apps. I ended up doing something similar to your solution.

  1. Create a config file in .ebextensions folder.
  2. Create a script file that I want to run (either save it in the code, or define/retrieve it as part of the config file in Step 1)
  3. Inside this config file, under container_commands section, run a command to copy the script from Step 2 into C:\Program Files\Amazon\ElasticBeanstalk\hooks\appdeploy\post\ (or whichever hook you want). More info here

When Beanstalk deploys the application, the command under container_commands will run after the server has been set up, but before the code has been deployed 1. After that, your hook script should be in place and will trigger according to the folder it's in.

Unfortunately I don't know if this is the official way to do it for .NET apps.

Karn Ratana
  • 96
  • 1
  • 3
  • 1
    I can also confirm this works. Very frustrating to have to go this route when it would seem logical to have a post install section directly in .ebextensions – Particleman Sep 01 '19 at 02:33
  • 1
    If it works this is a good workaround but I'm guessing the intended method is to use the .ebextensions "files" command to generate your script in the desired location (link below). I think this is likely less frustrating and fewer steps/more clean solution? https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-windows-ec2.html#windows-files – NoPathInParticular Jan 06 '21 at 17:57
  • Agreed with @NoPathInParticular I used the solution of OP but used the files ebextension approach and it worked great for me. – Hashir Baig Feb 14 '22 at 10:13