Reputation: 693
I have an R script on an EC2 instance on an aws account X that is trying to connect to an Athena database on an aws account Y. If I were to use the RJDBC package, I can connect pretty seamlessly through:
URL <- 'https://s3.amazonaws.com/athena-downloads/drivers/JDBC/AthenaJDBC_1.1.0/AthenaJDBC41-1.1.0.jar'
fil <- basename(URL)
if (!file.exists(fil)) download.file(URL, fil)
drv <- JDBC(driverClass="com.amazonaws.athena.jdbc.AthenaDriver", fil, identifier.quote="'")
conn <- jdbcConnection <- dbConnect(drv, 'jdbc:awsathena://athena.us-west-2.amazonaws.com:xxx/',
s3_staging_dir="s3://xxx/",
user='xxx',
password='xxx')
This works, but I'm trying to get Athena working through the AWR.Athena package instead (doesn't have some row based limitations for large queries). It requires installing the aws cli on my ec2 instance, which I've done and setup using aws configure.
Within R, I've verified the credentials are working through:
install.packages('aws.signature')
library(aws.signature)
aws.signature::locate_credentials()
However, every time I try and connect to Athena using the below, I get an error:
library(rJava)
.jcall("java/lang/System", "S", "setProperty", "aws.profile", "xxx")
library(AWR.Athena)
require(DBI)
dbConnect(AWR.Athena::Athena(),
region='us-west-2',
S3OutputLocation='xxx',
Schema='default')
Error in .jcall(drv@jdrv, "Ljava/sql/Connection;", "connect", as.character(url)[1], :
java.sql.SQLException: [Simba][AthenaJDBC](100131) An error has been thrown from the AWS SDK client. Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), com.simba.athena.amazonaws.auth.profile.ProfileCredentialsProvider@xxx: No AWS profile named 'xxx', com.simba.athena.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@aeab9a1: The requested metadata is not found at http://xxx/latest/meta-data/iam/security-credentials/] [Execution ID not available]```
Upvotes: 1
Views: 322
Reputation: 693
I... fixed it. I don't know why this works, but I changed this line to read default and it worked.
.jcall("java/lang/System", "S", "setProperty", "aws.profile", "default")
Upvotes: 1