render R markdown directly to S3 bucket

I am working on an AWS Lambda function using R as a custom runtime. The desired output is to create an HTML report and save it to an S3.

render_func <- function(x){
  require(rmarkdown)
  require(googledrive)
  user_key <- 1
  tmp <- tempdir()
  nme <- paste0("user-",user_key,"-lambda_doc")
  rmarkdown::render(
    input = "markdown.rmd",
    output_file = nme,
    output_dir = tmp
    )
  tmp_path <- paste0(tmp,"/",nme,".html")
  drive_auth_configure(api_key = "a-secret-key")
  drive_upload(
    media = tmp_path,
    name = nme
  )
}

render_func(x)

I've written a function that works locally to save the HTML report into the temp directory, the file is then uploaded to google drive. The temp directory is available to save information on AWS Lambda which is why I chose this approach. Using this approach I can replace the google drive upload with an S3 upload.

However it would be much better to upload directly to S3 and not saving to the temp directory as that directory is limited to 500mb or so. Is it possible to save directly to the bucket from Rmarkdowns render function?

render_func <- function(x){
  require(rmarkdown)
  user_key <- 1
  nme <- paste0("user-",user_key,"-lambda_doc")
  rmarkdown::render(
    input = "markdown.rmd",
    output_file = nme,
    output_dir = path-to-S3-bucket
    )
}

render_func(x)

What OS are you running? It may be possible to mount the S3 bucket via FUSE - and then handle it as a mere directory

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.