aws-samples / aws-blog-athena-custom-jdbc-credentials

The repository demonstrates use cases for running queries using Athena utilizing a custom JDBC credentials provider
MIT No Attribution
9 stars 10 forks source link

Error: Unable to find a region #1

Open spg opened 5 years ago

spg commented 5 years ago

Hey, I've been following the steps in this tutorial (Scenario 2: Cross-account access). When I try to connect, I get the following error:

...
Oct 29 14:55:42.728 TRACE 42 com.simba.athena.athena.core.AJConnection.updateConnectionSettings({AwsCredentialsProviderArguments=Variant[type: TYPE_WSTRING, value: AKIAI*****,MVXyc4*****,arn:aws:iam::*******:role/administrator], AwsCredentialsProviderClass=Variant[type: TYPE_WSTRING, value: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider], AwsRegion=Variant[type: TYPE_WSTRING, value: us-east-1], LogLevel=Variant[type: TYPE_WSTRING, value: 6], LogPath=Variant[type: TYPE_WSTRING, value: /Users/spgingras/athenalogstest], S3OutputLocation=Variant[type: TYPE_WSTRING, value: s3://aws-athena-query-results-*****-us-east-1/test/]}): +++++ enter +++++
Oct 29 14:55:42.728 TRACE 42 com.simba.athena.athena.core.AJConnection.connect({AwsCredentialsProviderArguments=Variant[type: TYPE_WSTRING, value: AKIA****,MVXyc4jpg****,arn:aws:iam::*****:role/administrator], AwsCredentialsProviderClass=Variant[type: TYPE_WSTRING, value: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider], AwsRegion=Variant[type: TYPE_WSTRING, value: us-east-1], LogLevel=Variant[type: TYPE_WSTRING, value: 6], LogPath=Variant[type: TYPE_WSTRING, value: /Users/spgingras/athenalogstest], S3OutputLocation=Variant[type: TYPE_WSTRING, value: s3://aws-athena-query-results-*****-us-east-1/test/]}): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.athena.utilities.AJUtilities.parseCredentialsProviderArgs(): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.getProperty(23): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.getProperty(21): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.athena.core.AJConnection.setConnectedPropertyValues(): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.setProperty(65, Variant[type: TYPE_UINT32, value: 32767]): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.setProperty(66, Variant[type: TYPE_UINT32, value: 0]): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.setProperty(81, Variant[type: TYPE_UINT32, value: 256]): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.setProperty(83, Variant[type: TYPE_UINT32, value: 0]): +++++ enter +++++
Oct 29 14:55:42.729 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.setProperty(68, Variant[type: TYPE_UINT32, value: 0]): +++++ enter +++++
Oct 29 14:55:42.730 TRACE 42 com.simba.athena.dsi.core.impl.DSIConnection.setProperty(139, Variant[type: TYPE_WSTRING, value: null]): +++++ enter +++++
Oct 29 14:55:42.730 TRACE 42 com.simba.athena.athena.api.AJClient.AJClient(): +++++ enter +++++
Oct 29 14:55:42.730 TRACE 42 com.simba.athena.athena.utilities.AJUtilities.createAwsCredentialsProvider(): +++++ enter +++++
Oct 29 14:55:50.574 ERROR 42 com.simba.athena.athena.utilities.AJUtilities.createAwsCredentialsProvider: [Simba][AthenaJDBC](100191) Failed to create AWS Credentials Provider class: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.
com.simba.athena.support.exceptions.GeneralException: [Simba][AthenaJDBC](100191) Failed to create AWS Credentials Provider class: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.
    at com.simba.athena.athena.utilities.AJUtilities.createAwsCredentialsProvider(Unknown Source)
    at com.simba.athena.athena.api.AJClient.<init>(Unknown Source)
    at com.simba.athena.athena.core.AJConnection.connect(Unknown Source)
    at com.simba.athena.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
    at com.simba.athena.jdbc.common.AbstractDriver.connect(Unknown Source)
    at workbench.db.DbDriver.connect(DbDriver.java:511)
    at workbench.db.ConnectionMgr.doConnect(ConnectionMgr.java:291)
    at workbench.db.ConnectionMgr.connect(ConnectionMgr.java:318)
    at workbench.db.ConnectionMgr.getConnection(ConnectionMgr.java:194)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.simba.athena.athena.utilities.AJUtilities.createAwsCredentialsProvider(Unknown Source)
    at com.simba.athena.athena.api.AJClient.<init>(Unknown Source)
    at com.simba.athena.athena.core.AJConnection.connect(Unknown Source)
    at com.simba.athena.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
    at com.simba.athena.jdbc.common.AbstractDriver.connect(Unknown Source)
    at workbench.db.DbDriver.connect(DbDriver.java:511)
    at workbench.db.ConnectionMgr.doConnect(ConnectionMgr.java:291)
    at workbench.db.ConnectionMgr.connect(ConnectionMgr.java:318)
    at workbench.db.ConnectionMgr.getConnection(ConnectionMgr.java:194)
    at workbench.gui.profiles.ConnectionGuiHelper$1.run(ConnectionGuiHelper.java:144)
Caused by: com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.
    at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371)
    at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337)
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
    at com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.<init>(CustomIAMRoleAssumptionCredentialsProvider.java:26)
    ... 14 more

Oct 29 14:55:50.574 ERROR 42 com.simba.athena.exceptions.ExceptionConverter.toSQLException: [Simba][AthenaJDBC](100191) Failed to create AWS Credentials Provider class: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.
java.sql.SQLException: [Simba][AthenaJDBC](100191) Failed to create AWS Credentials Provider class: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.
    at com.simba.athena.athena.utilities.AJUtilities.createAwsCredentialsProvider(Unknown Source)
    at com.simba.athena.athena.api.AJClient.<init>(Unknown Source)
    at com.simba.athena.athena.core.AJConnection.connect(Unknown Source)
    at com.simba.athena.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
    at com.simba.athena.jdbc.common.AbstractDriver.connect(Unknown Source)
    at workbench.db.DbDriver.connect(DbDriver.java:511)
    at workbench.db.ConnectionMgr.doConnect(ConnectionMgr.java:291)
    at workbench.db.ConnectionMgr.connect(ConnectionMgr.java:318)
    at workbench.db.ConnectionMgr.getConnection(ConnectionMgr.java:194)
Caused by: com.simba.athena.support.exceptions.GeneralException: [Simba][AthenaJDBC](100191) Failed to create AWS Credentials Provider class: com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.
    ... 9 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.simba.athena.athena.utilities.AJUtilities.createAwsCredentialsProvider(Unknown Source)
    at com.simba.athena.athena.api.AJClient.<init>(Unknown Source)
    at com.simba.athena.athena.core.AJConnection.connect(Unknown Source)
    at com.simba.athena.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
    at com.simba.athena.jdbc.common.AbstractDriver.connect(Unknown Source)
    at workbench.db.DbDriver.connect(DbDriver.java:511)
    at workbench.db.ConnectionMgr.doConnect(ConnectionMgr.java:291)
    at workbench.db.ConnectionMgr.connect(ConnectionMgr.java:318)
    at workbench.db.ConnectionMgr.getConnection(ConnectionMgr.java:194)
    at workbench.gui.profiles.ConnectionGuiHelper$1.run(ConnectionGuiHelper.java:144)
Caused by: com.amazonaws.SdkClientException: Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region.
    at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371)
    at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337)
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
    at com.amazonaws.custom.athena.jdbc.CustomIAMRoleAssumptionCredentialsProvider.<init>(CustomIAMRoleAssumptionCredentialsProvider.java:26)
    ... 14 more

even if I set AwsRegion=us-east-1 in the JDBC connection string, or even if I set the AWS_REGION=us-east-1 environment variable.

Am I missing something?

JorganPubshire commented 5 years ago

@spg I don't think you're missing anything, this doesn't seem to be an issue with the credentials provider, but rather how SQL Workbench handles its environment. I also had this issue and was unable to get the AWS_REGION to propagate through to the credentials provider chain. I tried passing it from the JDBC connection string, the extended properties, workspace variables, and in my shell before launching SQL Workbench.

I ended up working around this issue by downloading the source code, modifying CustomIAMRoleAssumptionCredentialsProvider by adding a region variable, manually building the jar, then passing my desired region at the end of AWSCredentialsProviderArguments.

mazoucou commented 2 years ago

Hello Everyone,

can you share with us the final modified driver please ? i am not able to recompile the jar and use it, i tried a lot of commands to convert the CustomIAMRoleAssumptionCredentialsProvider file from .java to .class and recompile the jar after but without success :

C:\appli\compiler\com\amazonaws\custom\athena\jdbc>javac -cp ".;/appli/compiler/com/amazonaws/auth/*" CustomIAMRoleAssumptionCredentialsProvider.java CustomIAMRoleAssumptionCredentialsProvider.java:3: error: package com.amazonaws.auth does not exist

Thank you for your reply.in advance.