简体   繁体   中英

AWS Elastic Beanstalk Go File Permission Problem

I am currently deploying a Go application to AWS Elastic Beanstalk.

In the application, I create a file for logging.

When the application deploys, I get an error depending on what I did.

When I os.Create("/var/log/golang/golang-server.log") . I get the following error message back open /var/log/golang/golang-server.log: no such file or directory

But when I os.Create("/var/log/golang-server.log") . I get the following error message back open /var/log/golang-server.log: permission denied

I am currently deploying the example go.zip application they provide on their website to make sure that none of my implementation/code is the problem. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/go-getstarted.html

In there code, they also create a file for logging, but they are ignoring the error from os.Create, and thus the file never gets created.

I have a.ebextension folder that I could use should I need to fix something.

Thank you.

It seems that you are executing the os.Create commands from your application.

Your application executes under webapp user, while /var/log is owned by root . Subsequently you get those errors.

To recitfy the issue, in your .ebextension you could have commands (or files ) section which will create a log config file for your application by adding it to /opt/elasticbeanstalk/config/private/logtasks/bundle .

For example, you can just create:

/opt/elasticbeanstalk/config/private/logtasks/bundle/my-go-app.conf

with the content of

/var/app/current/log/*.log

where /var/app/current/log/*.log would be location of your custom application logs. It can be other location. This is just an example of the config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM