Skip to content

Commit

Permalink
feature: allow more boto3 client parameters to be passed from dbConne…
Browse files Browse the repository at this point in the history
…ct to boto3 (#169)
  • Loading branch information
DyfanJones committed Apr 19, 2022
1 parent f19059a commit 75bbce0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
28 changes: 17 additions & 11 deletions R/Connection.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ AthenaConnection <- function(aws_access_key_id = NULL,
aws_expiration = NULL,
keyboard_interrupt = NULL,
...){
kwargs = list(...)
sess_kwargs = c(
aws_access_key_id = aws_access_key_id,
aws_secret_access_key = aws_secret_access_key,
aws_session_token = aws_session_token,
region_name = region_name,
botocore_session = botocore_session,
profile_name = profile_name,
.boto_param(kwargs, .SESSION_PASSING_ARGS)
)

tryCatch(
boto3 <- boto$Session(aws_access_key_id = aws_access_key_id,
aws_secret_access_key = aws_secret_access_key,
aws_session_token = aws_session_token,
region_name = region_name,
botocore_session = botocore_session,
profile_name = profile_name,
...),
boto3 <- do.call(boto$Session, sess_kwargs),
error = function(e) py_error(e)
)

Expand All @@ -47,10 +52,11 @@ AthenaConnection <- function(aws_access_key_id = NULL,
"`AWS_REGION` in environment variables or `region_name` hard coded in `dbConnect()`.",
call. = FALSE)

ptr_ll <- list(Athena = boto3$client("athena"),
S3 = boto3$client("s3"),
glue = boto3$client("glue"))

ptr_ll <- list(
Athena = do.call(boto3$client, c(service_name="athena", .boto_param(kwargs, .CLIENT_PASSING_ARGS))),
S3 = do.call(boto3$client, c(service_name="s3", .boto_param(kwargs, .CLIENT_PASSING_ARGS))),
glue = do.call(boto3$client, c(service_name="glue", .boto_param(kwargs, .CLIENT_PASSING_ARGS)))
)
if(is.null(s3_staging_dir) && !is.null(work_group)){
tryCatch(s3_staging_dir <- ptr_ll$Athena$get_work_group(WorkGroup = work_group)$WorkGroup$Configuration$ResultConfiguration$OutputLocation,
error = function(e) py_error(e))
Expand Down
15 changes: 15 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,18 @@ info_msg = function(...){
if (athena_option_env$verbose)
message("INFO: ", ...)
}

.boto_param = function(param, default_param){
return(param[tolower(names(param)) %in% default_param])
}
.SESSION_PASSING_ARGS = c(
"botocore_session"
)

.CLIENT_PASSING_ARGS = c(
"config",
"api_version",
"use_ssl",
"verify",
"endpoint_url"
)

0 comments on commit 75bbce0

Please sign in to comment.