0

I've built a shiny app that saves and reads data from S3, using the aws.s3 package.

Along the lines of this answer I have saved my AWS credentials in a .Renviron file and successfully deployed the app to shinyapps.io

Now comes the problem. I want to host the app on an EC2 instance (I'm following this excellent tutorial). To do that, I need to clone the app from github. But I've added .Renviron to .gitignore.

The question is: can I make a .Renviron file within the EC2 instance? Is there some other way I should be approaching this?

PS I've tried creating it with touch .Renviron but shiny-server doesn't seem to have permission to access that file.

  • Did you restart the shiny server after creating the Renviron file? Did you get a specific error message that made you think it was a permissions issue? Does the file have the same owner as the rest of the application files? – MrFlick Aug 23 '22 at 14:17
  • I did restart. The reason I thought permission was that if ```cd my-app``` then ```sudo less .Renviron``` I can see my credentials. But If I assume the role of the user (shiny) with ```sudo su shiny``` then I can no longer open the .Renviron file with the same steps – Justin Beresford Aug 23 '22 at 14:23
  • >>Does the file have the same owner as the rest of the application files? This, I don't know how to check.. – Justin Beresford Aug 23 '22 at 14:26
  • Where exactly did you create the file? Just in your home directory? Is that the same place that you put the application code? You can change the owner of the file to the shiny user with `chown` – MrFlick Aug 23 '22 at 14:26
  • Wow - you did it! The solution was indeed ```chown```. Thank you so much! – Justin Beresford Aug 23 '22 at 14:34

1 Answers1

0

Credit goes to MrFlick for this. Here was the final solution.

  1. cd to the folder containing your app and create a .Renviron file using touch .Renviron

  2. Edit the file, using sudo nano .Renviron

    AWS_ACCESS_KEY_ID = yourkeyid

    AWS_SECRET_ACCESS_KEY = yoursecretaccesskey

    AWS_DEFAULT_REGION = yourregion

  3. Change the owner of the file, in my case chown ubuntu .Renviron

When you've done all that, you can Sys.getenv(AWS_ACCESS_KEY_ID) from your R code.