Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect AWS S3 credentials in a modular shiny app

Running a shiny app with multiple folders served on shinyapps.io. The app has a function which pulls data from S3 (using a wrapper around get_bucket()), which works fine locally as I set the AWS secret and credentials in my project .Renviron file, but once pushed I get a HTTP 403 error:

Error in value[[3L]](cond) : Forbidden (HTTP 403).
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

Things I have tried:

  • including the aws key, secret, and region directly in the get_bucket() call
  • changing bucket setting in aws to "open access"
  • setting the credentials in global.R file which includes sys.setenv()
  • adding a .Renviron to the main project folder with the credentials
  • Adding the credentials in the server.R file (to test, for confidentiality I don't want to do this)

I'm completely out of ideas on this one. It stems into a broader question of how to set .Renviron variables in a shinyapps.io app. Things I've read say to add to the main folder or other options, but as I say above hasn't worked.

I am reading the data in with shiny::reactivePoll() but don't see how this is the issue.

Thanks for your help, been stuck on this for days.

like image 928
Corey Pembleton Avatar asked Oct 28 '22 08:10

Corey Pembleton


1 Answers

So, all along, the answer was in directly calling Sys.getenv() in the get_bucket()

get_bucket(s3BucketName,
                       "AWS_ACCESS_KEY_ID" = Sys.getenv("AWS_ACCESS_KEY_ID"),
                       "AWS_SECRET_ACCESS_KEY" = Sys.getenv("AWS_SECRET_ACCESS_KEY")

Which could call on the .Renviron I had in the main directory. I think in my previous attempts I had either a) not called on it correctly with Sys.getenv() or forget to address it properly.

like image 188
Corey Pembleton Avatar answered Nov 15 '22 06:11

Corey Pembleton