HaukurHaf
HaukurHaf

Reputation: 13806

Running .net core web app on AWS Beanstalk - file write permissions

Ok, so I've got a web application written in .NET Core which I've deployed to the AWS Elastic beanstalk which was pretty easy, but I've already hit a snag.

The application fetches JSON data from an external source and writes to a local file, currently to wwwroot/data/data.json under the project root. Once deployed to AWS, this functionality is throwing an access denied exception when it tries to write the file.

I've seen something about creating a folder called .ebextensions with a config file with some container commands to set permissions to certain paths/files after deployment, and I've tried doing that, but that does not seem to do anything for me - I don't even know if those commands are even being executed so I have no idea what's happening, if anything.

This is the config file I created under the .ebextensions folder:

{
    "container_commands": {
        "01-aclchange": {
            "command": "icacls \"C:/inetpub/AspNetCoreWebApps/app/wwwroot/data\" /grant DefaultAppPool:(OI)(CI)",
         }
    }
}

The name of the .config file matches the applicatio name in AWS, but I also read somewhere that the name does not matter, as long as it has the .config extension.

Has anyone successfully done something like this? Any pointers appreciated.

Upvotes: 0

Views: 719

Answers (1)

DavidG
DavidG

Reputation: 118977

Rather than trying to fix permission issues writing to the local storage within AWS Elastic Beanstalk, I would instead suggest using something like Amazon S3 for storing files. Some benefits would be:

  • Not having to worry about file permissions.
  • S3 files are persistent.
  • You may run into issues with losing local files when you republish your application.
  • If you ever move to using something like containers, you will lose the file every time the container is taken down.
  • S3 is incredibly cheap to use.

Upvotes: 1

Related Questions