Can I Create a JDBC Connection URL Using AWS Credential Profile?

I am trying to create a JDBC connection to Amazon Athena using AWS credentials stored in an AWS profile (either through InstanceProfileCredentialsProvider or ProfileCredentialsProvider). However, the connection works only when I explicitly include the user and password in the connection string.

I would like to know if it's possible to use AWS credential profiles in the JDBC connection URL to avoid hardcoding access credentials.

Working connection string (with user and password):

This works with hard-coded credentials:

jdbc:awsathena://AwsRegion=us-west-2;WorkGroup=primary;Catalog=AwsDataCatalog;
Database=default;S3OutputLocation=s3://fdsa-athena-data-store/;
User=AKIAEXAMPLE;Password=EXAMPLESECRET;

Non-working connection string (with profile):

I have tried the following connection string using both InstanceProfileCredentialsProvider and ProfileCredentialsProvider:

jdbc:awsathena://AwsRegion=us-west-2;WorkGroup=primary;Catalog=AwsDataCatalog;
Database=default;S3OutputLocation=s3://fdsa-athena-data-store/;AwsCredentialsProviderClass=com.simba.athena.amazonaws.auth.InstanceProfileCredentialsProvider;

or

jdbc:awsathena://AwsRegion=us-west-2;WorkGroup=primary;Catalog=AwsDataCatalog;
Database=default;S3OutputLocation=s3://fdsa-athena-data-store/;
AwsCredentialsProviderClass=com.simba.athena.amazonaws.auth.profile.ProfileCredentialsProvider;
AwsProfile=default;

Both attempts result in the following error:

java.sql.SQLException: Missing credentials error: Either UID/PWD or AwsCredentialsProviderClass must be provided.

How to establish a JDBC connection to Athena using AWS credential profiles without explicitly including the user and password in the connection URL?

Upvotes: 1

Views: 100

Answers (0)

Related Questions