R/utils.R

execute_aws_cmd <- function(args) {
  error_log <- paste0(tempdir(), "error.log")

  tryCatch(
    {
      system2("aws", args = args, stdout = TRUE, stderr = error_log)
    },
    error = function (cond) {
      stop("aws command not found, failing")
    },
    warning = function (cond) {
      error_msg <- readr::read_lines(error_log, skip_empty_rows = TRUE)
      stop(error_msg)
    },
    finally = {
      if (file.exists(error_log)) {
        file.remove(error_log)
      }
    }
  )
}
precision-analytics/precisely.aws documentation built on May 23, 2019, 6:05 p.m.