Establishing a Connection
Creating a JDBC Data Source
You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for Amazon Athena consists of three basic steps:
- Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
- Provide the driver class. For example:
cdata.jdbc.amazonathena.AmazonAthenaDriver
- Provide the JDBC URL. For example:
jdbc:amazonathena:AWSAccessKey='a123';AWSSecretKey='s123';AWSRegion='IRELAND';Database='sampledb';S3StagingDirectory='s3://bucket/staging/'; or jdbc:cdata:amazonathena:AWSAccessKey='a123';AWSSecretKey='s123';AWSRegion='IRELAND';Database='sampledb';S3StagingDirectory='s3://bucket/staging/';
The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:amazonathena:" or "jdbc:cdata:amazonathena:" and can include any of the connection properties in name-value pairs separated with semicolons.
Connecting to Amazon Athena
Specify the following to connect to data:
- DataSource: The name of the Amazon Athena data source to connect to.
- Database: The name of the Amazon Athena database to connect to.
- AWSRegion: Set this to the region where your Amazon Athena data is hosted.
- S3StagingDirectory: Set this to a folder in S3 where you would like to store the results of queries.
If Database and DataSource are not specified, the driver tries to list all databases from the available data sources in Amazon Athena. Setting both properties improves the performance of the driver.
Authenticating to Amazon Athena
In addition to specifying basic connection information required for all connections, you must choose an authentication method from one of the below listed options.
Obtain AWS Keys
To obtain the credentials for an IAM user, follow the steps below:
- Sign into the IAM console.
- In the navigation pane, select Users.
- To create or manage the access keys for a user, select the user and then go to the Security Credentials tab.
To obtain the credentials for your AWS root account, follow the steps below:
- Sign into the AWS Management console with the credentials for your root account.
- Select your account name or number and select My Security Credentials in the menu that is displayed.
- Click Continue to Security Credentials and expand the "Access Keys" section to manage or create root account access keys.
Root Credentials
To authenticate using account root credentials, set the following:
- AuthScheme: Set this to AwsRootKeys.
- AWSAccessKey: The access key associated with the AWS root account.
- AWSSecretKey: The secret key associated with the AWS root account.
Note: Use of this authentication scheme is discouraged by Amazon for anything but simple tests. The account root credentials have the full permissions of the user, making this the least secure authentication method.
Temporary Credentials
To authenticate using temporary credentials, specify the following:
- AuthScheme: Set this to TemporaryCredentials.
- AWSAccessKey: The access key of the IAM user to assume the role for.
- AWSSecretKey: The secret key of the IAM user to assume the role for.
- AWSSessionToken: Your AWS session token. This will have been provided alongside your temporary credentials. See AWS Identity and Access Management User Guide for more info.
The driver can now request resources using the same permissions provided by long-term credentials (such as IAM user credentials) for the lifespan of the temporary credentials.
If you are also using an IAM role to authenticate, you must additionally specify the following:
- AWSRoleARN: Specify the Role ARN for the role you'd like to authenticate with. This will cause the driver to attempt to retrieve credentials for the specified role.
- AWSExternalId: Only if required when you assume a role in another account.
EC2 Instances
If you are using the driver from an EC2 Instance and have an IAM Role assigned to the instance, you can use the IAM Role to authenticate. To do so, set the following properties to authenticate:
- AuthScheme: Set this to AwsEC2Roles.
If you are also using an IAM role to authenticate, you must additionally specify the following:
- AWSRoleARN: Specify the Role ARN for the role you'd like to authenticate with. This will cause the driver to attempt to retrieve credentials for the specified role.
- AWSExternalId: Only if required when you assume a role in another account.
IMDSv2 Support
The Amazon Athena driver now supports IMDSv2. Unlike IMDSv1, the new version requires an authentication token. Endpoints and response are the same in both versions. In IMDSv2, the Amazon Athena driver first attempts to retrieve the IMDSv2 metadata token and then uses it to call AWS metadata endpoints. If it is unable to retrieve the token, the driver reverts to IMDSv1.
AWS IAM Roles
In many situations it may be preferable to use an IAM role for authentication instead of the direct security credentials of an AWS root user.
To authenticate as an AWS role, set the following:
- AuthScheme: Set this to AwsIAMRoles.
- AWSRoleARN: Specify the Role ARN for the role you'd like to authenticate with. This will cause the driver to attempt to retrieve credentials for the specified role.
- AWSExternalId: Only if required when you assume a role in another account.
- AWSAccessKey: The access key of the IAM user to assume the role for.
- AWSSecretKey: The secret key of the IAM user to assume the role for.
Note: Roles may not be used when specifying the AWSAccessKey and AWSSecretKey of an AWS root user.
ADFS
Set the AuthScheme to ADFS. The following connection properties need to be set:
- User: Set this to your ADFS username.
- Password: Set this to your ADFS password.
- SSOLoginURL: Set this to the login URL used by the SSO provider.
AuthScheme=ADFS; AWSRegion=Ireland; Database=sampledb; [email protected]; Password=CH8WerW121235647iCa6; SSOLoginURL='https://adfs.domain.com'; AWSRoleArn=arn:aws:iam::1234:role/ADFS_SSO; AWSPrincipalArn=arn:aws:iam::1234:saml-provider/ADFSProvider; S3StagingDirectory=s3://athena/staging;
ADFS Integrated
To use the ADFS Integrated flow, specify the SSOLoginURL and leave the username and password empty.
Okta
Set the AuthScheme to Okta. The following connection properties are used to authenticate through Okta:
- User: Set to your Okta user.
- Password: Set to your Okta password.
- SSOLoginURL: Set to the login URL used by the SSO provider.
- using a trusted application or proxy that overrides the Okta client request
- configuring MFA
then you need to use combinations of SSOProperties input parameters to authenticate using Okta. Otherwise, you do not need to set any of these values.
In SSOProperties when required, set these input parameters:
- APIToken: When authenticating a user via a trusted application or proxy that overrides the Okta client request context, set this to the API Token the customer created from the Okta organization.
- MFAType: Set this if you have configured the MFA flow. Currently we support the following types: OktaVerify, Email, and SMS.
- MFAPassCode: Set this only if you have configured the MFA flow. If you set this to empty or an invalid value, the driver issues a one-time password challenge to your device or email. After the passcode is received, reopen the connection where the retrieved one-time password value is set to the MFAPassCode connection property.
- MFARememberDevice: Okta supports remembering devices when MFA is required. If remembering devices is allowed according to the configured authentication policies, the driver sends a device token to extend MFA authentication lifetime. This property is, by default, set to True. Set this to False only if you do not want MFA to be remembered.
Example connection string:
AuthScheme=Okta; AWSRegion=Ireland; Database=sampledb; [email protected]; Password=CH8WerW121235647iCa6; SSOLoginURL='https://cdata-us.okta.com/home/amazon_aws/0oa35m8arsAL5f5NrE6NdA356/272'; SSOProperties='ApiToken=01230GGG2ceAnm_tPAf4MhiMELXZ0L0N1pAYrO1VR-hGQSf;'; AWSRoleArn=arn:aws:iam::1234:role/Okta_SSO; AWSPrincipalARN=arn:aws:iam::1234:saml-provider/OktaProvider; S3StagingDirectory=s3://athena/staging;
PingFederate
Set the AuthScheme to PingFederate. The following connection properties need to be set:
- User: Set this to the PingFederate user.
- Password: Set this to PingFederate password for the user.
- SSOLoginURL: Set this to the login url used by the SSO provider.
- SSOExchangeUrl: The Partner Service Identifier URI configured in your PingFederate server instance under: SP Connections > SP Connection > WS-Trust > Protocol Settings. This should uniquely identify a PingFederate SP Connection, so it is a good idea to set it to your AWS SSO ACS URL. You can find it under AWS SSO > Settings > View Details next to the Authentication field.
- AuthScheme (optional): The authorization scheme to be used for the IdP endpoint. The allowed values for this IdP are None or Basic.
- SSLClientCert
- SSLClientCertType
- SSLClientCertSubject
- SSLClientCertPassword
authScheme=pingfederate;SSOLoginURL=https://mycustomserver.com:9033/idp/sts.wst;SSOExchangeUrl=https://us-east-1.signin.aws.amazon.com/platform/saml/acs/764ef411-xxxxxx;user=admin;password=PassValue;AWSPrincipalARN=arn:aws:iam::215338515180:saml-provider/pingFederate;AWSRoleArn=arn:aws:iam::215338515180:role/SSOTest2;AWSRegion=Ireland;S3StagingDirectory=s3://somedirectory/staging;Database=athenadatabase;
MFA
For users and roles that require Multi-factor Authentication, specify the following to authenticate:
- AuthScheme: Set this to AwsMFA.
- CredentialsLocation: The location of the settings file where MFA credentials are saved. See the Credentials File Location page under Connection String Options for more information.
- MFASerialNumber: The serial number of the MFA device if one is being used.
- MFAToken: The temporary token available from your MFA device.
- AWSAccessKey: The access key of the IAM user for whom MFA will be issued.
- AWSSecretKey: The secret key of the IAM user whom MFA will be issued.
- AWSRoleARN: Specify the Role ARN for the role you'd like to authenticate with. This will cause the driver to attempt to retrieve credentials for the specified role using MFA.
- AWSExternalId: Only if required when you assume a role in another account.
Note that you can control the duration of the temporary credentials by setting the TemporaryTokenDuration property (default 3600 seconds).
Credentials Files
You can use a credentials file to authenticate. Any configurations related to AccessKey/SecretKey authentication, temporary credentials, role authentication, or MFA can be used. To do so, set the following properties to authenticate:
- AuthScheme: Set this to AwsCredentialsFile.
- AWSCredentialsFile: Set this to the location of your credentials file.
- AWSCredentialsFileProfile (optional): Optionally set this to the name of the profile you would like to use from the specified credentials file. If not specified, the profile with the name default will be used.
AWS Cognito Credentials
If you want to use the driver with a user registered in a User Pool in AWS Cognito, set the following properties to authenticate:
- AuthScheme: Set this to AwsCognitoSrp (recommended). You can also use AwsCognitoBasic.
- AWSCognitoRegion: Set this to the region of the User Pool.
- AWSUserPoolId: Set this to the User Pool Id.
- AWSUserPoolClientAppId: Set this to the User Pool Client App Id.
- AWSUserPoolClientAppSecret: Set this to the User Pool Client Secret.
- AWSIdentityPoolId: Set this to the Identity Pool Id of the Identity Pool that is linked with the User Pool.
- User: Set this to the username of the user registered in the User Pool.
- Password: Set this to the password of the user registered in the User Pool.
AzureAD
Set the AuthScheme to AzureAD. The following connection properties are used to connect to AzureAD:
Note that this configuration requires two AAD applications: the "Amazon Athena" application used for single sign-on, and a separate "connector" application with user_impersonation permission on the "Amazon Athena" application. You must also specify the OAuth connection properties:
- OAuthClientId: The application Id of the connector application, listed in the Overview section of the app registration.
- OAuthClientSecret: The client secret value of the connector application. Azure AD displays this when you create a new client secret.
The following SSOProperties are used to authenticate to AzureAD:
- Resource: The application Id URI of the Amazon Athena application, listed in the Overview section of the app registration. In most cases this is the URL of your custom Amazon Athena domain.
- AzureTenant: The Id of the Azure AD tenant where the applications are registered.
The following is an example connection string:
AuthScheme=AzureAD;InitiateOAuth=GETANDREFRESH;OAuthClientId=3ea1c786-d527-4399-8c3b-2e3696ae4b48;OauthClientSecret=xxx;SSOProperties='Resource=';