Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set folder permissions for elastic beanstalk windows application?

I am currently building a C# WebApi 2 application that I will be uploading to an Amazon Elastic Beanstalk instance to deploy. I am having success so far, and on my local machine, I just finished testing the file upload capability in order for clients to upload images.

The way it goes is I accept the multipart/formdata in the Web Api and save the temp file (with a random name like BodyPart_24e246c7-a92a-4a3d-84ef-c1651416e667) to the App_Data folder. The temporary file is put into an S3 Bucket and I create a reference in my SQL Server database to it.

Testing works fine with single or multiple file uploads locally but when I deploy the application to Elastic Beanstalk and try to upload I get errors like "Could not find a part of the path 'C:\inetpub\wwwroot\sbeAPI_deploy\App_Data\BodyPart_8f552d48-ed9b-4ec2-9986-88cbffd673ee'" or a similar one saying access is denied altogether.

I have been trying to find the solution online for a few hours now, but the AWS documentation is all over the place and tutorials/other questions seem to be outdated. I believe it has something to do with not having permission to write the temporary files on the EC2 server, but I can't figure out how to fix it.

Thanks very much in advance.

like image 774
Elie Zeitouni Avatar asked Jul 30 '14 21:07

Elie Zeitouni


2 Answers

This is already possible since April 2013, see also here: Basically the steps you need to perform are the following:

  1. Create a folder called .ebextensions in the top-level of your project through the solution explorer
  2. Add in this folder your configuration file e.g myapp.config (replace myapp with your Elastic Beanstalk's app name)
  3. Add the code displayed underneath to this configuration file you just created. Replace MyApp with your project name (not solution name) displayed in Visual Studio
  4. All set!! Be sure there's a file within App_Data otherwise Visual Studio won't publish it.

    {
        "containercommands": {
            "01-changeperm": {
                "command": "icacls \"C:/inetpub/wwwroot/MyApp_deploy/App_Data\" /grant DefaultAppPool:(OI)(CI)"
            }
        }
    }
    
like image 52
bicycle Avatar answered Sep 30 '22 03:09

bicycle


To give write permission to your DefaultAppPool you can
create an .ebextensions folder
create a config file and place it in your .ebextensions folder

This will change permission to your wwwroot folder

container_commands:
 01-changeperm :
  command : 'icacls "C:\\inetpub\\wwwroot" /grant "IIS APPPOOL\DefaultAppPool:(OI)(CI)F"'
like image 40
ynot Avatar answered Sep 30 '22 04:09

ynot