AWS Athena
This page covers the details about integrating Athena with Sprinkle.
When setting up Athena connection, Sprinkle additionally requires a S3 bucket. This guide covers the role of all the components and steps to setup.
- Integrating Athena: All analytical data is stored and queried from Athena warehouse
- Create S3 Bucket: Sprinkle stores all intermediate data and report caches in this bucket
Step by Step Guides
Section titled โStep by Step GuidesโIntegrating Athena
Section titled โIntegrating AthenaโSTEP-1: Configure Athena output location
Section titled โSTEP-1: Configure Athena output locationโCreate the S3 bucket in the same region and then configure in the AWS Athena Portal
STEP-2: Create Access and Secret key
Section titled โSTEP-2: Create Access and Secret keyโ- Create an user, say โsprinkle-athenaโ
- Set permissions
- Select -> Attach policy directly
- Select AmazonAthenaFullAccess and AmazonS3FullAccess
- Create access key
- In Security credential, create access ky
- Select usecase: Other
- Generate and copy access and secret key
STEP-3: Configure Athena Connection on Sprinkle
Section titled โSTEP-3: Configure Athena Connection on SprinkleโIn the Connect Warehouse form
- Provide all the mandatory details
- Distinct Name: Name to identify this connection
- Region: Select the AWS region where your Athena instance was created (e.g., Asia Pacific
- Port: Provide the port number. Default is set at 443.
- API Key (created in STEP-2) : You can create or view this in the IAM console under โSecurity credentialsโ.
- Secret Key (created in STEP-2)
- S3 Output Location: (location configured in STEP-1) This is the path to the Amazon S3 location where you want to store your query results. The path should be prefixed with
s3://and match the one configured in your Athena setup. - Schema: The name of the database schema to use by default when a schema is not explicitly specified in your query.
- Catalog (Optional): Provide the Catalog name if your Athena setup uses one.
- Workgroup (Optional): Specify the workgroup in which you want to execute your queries.
- Test Connection: Tests the connection endpoints provided.
- Create: Saves the endpoints provided and creates the connection in Sprinkle.
Create S3 Bucket
Section titled โCreate S3 BucketโS3 bucket is required to store intermediate data and report outputs. Refer here for creating an S3 bucket and configuring it in Sprinkle
(OPTIONAL) Athena Output Purging: Setup
Section titled โ(OPTIONAL) Athena Output Purging: Setupโ- Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.
- In the Buckets list, choose the name of the bucket that you want to create a lifecycle rule for.
- Choose the Management tab, and select Create lifecycle rule.
- In the Lifecycle rule name, enter a name for your rule. The name must be unique within the bucket.
- Choose the scope of the lifecycle rule as Limit the scope of this rule using one or more filters. To limit the scope by prefix, in Prefix, enter the prefix. (Folder name which we specified in Athena Query result location)
- Under Lifecycle rule actions, choose the following actions that this lifecycle rule will perform:
- Expire current versions of objects
- Permanently delete previous versions of objects
- To expire current versions of objects, under Expire current versions of objects, in the Number of days after object creation, enter the number of days as 1.
- To permanently delete previous versions of objects, under Permanently delete previous versions of objects, in the Number of days after objects become previous versions, enter the number of days as 1.
- Verify the rule once again and choose Create rule.
- The created rule will appear in the Life cycle rules.
(OPTIONAL) Database Level Access in Athena: Setup
Section titled โ(OPTIONAL) Database Level Access in Athena: SetupโThe following procedure can help to create Athena dB and provide access to the particular dB in Sprinkle. It will also help to share Athena across different organizations without sharing the same credentials.
Steps to be followed
Section titled โSteps to be followed โ- Create a new database in Athena
- Create IAM Policy
- Create IAM User
- Create Access key
- Update Sprinkle driver
Create Athena Database
Section titled โCreate Athena Databaseโ- Log in to the AWS console and go to Athena.
- Run the create database command in the query editor by updating dB name. CREATE DATABASE <DB_NAME>
Create IAM Policy
Section titled โCreate IAM Policy โ- Log in to the AWS console, go to IAM and select Policy from the left pane.
- Click on Creare policy and go to the JSON tab.
- Paste the following policy in the editor with updating <REGION>, <DB_NAME>, <ACCOUNT_NO> and S3 <BUCKET_NAME>.
Access Policy
Section titled โAccess Policyโ{ "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "glue:GetDatabase", "glue:GetDatabases", "glue:GetPartition", "glue:CreateTable", "glue:GetTables", "glue:GetPartitions", "glue:CreateDatabase", "glue:UpdateTable", "glue:DeleteTable", "glue:CreatePartition", "glue:DeletePartition", "glue:UpdatePartition", "glue:GetTable", "athena:StartQueryExecution", "athena:GetQueryExecution", "athena:GetQueryResults", "athena:GetQueryResultsStream" ], "Resource": [ "arn:aws:glue:<REGION>:<ACCOUNT_NO>:catalog", "arn:aws:glue:<REGION>:<ACCOUNT_NO>:database/<DB_NAME>", "arn:aws:glue:<REGION>:<ACCOUNT_NO>:table/<DB_NAME>/*", "arn:aws:athena:<REGION>:<ACCOUNT_NO>:workgroup/primary" ] }, { "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject", "s3:ListBucketMultipartUploads", "s3:ListBucket", "s3:DeleteObject", "s3:GetBucketLocation", "s3:ListMultipartUploadParts" ], "Resource": [ "arn:aws:s3:::<BUCKET_NAME>/*", "arn:aws:s3:::<BUCKET_NAME>" ] } ]}Create IAM user
Section titled โCreate IAM user โ- Log in to the AWS console, go to IAM and select User from the left pane.
- Click on Add User, provide the User name and select access type as Programmatic Access.
- Attach the policy created for Athena access from Attach existing policy directly.
Create Access key
Section titled โCreate Access key โ- Go to the IAM users and select the newly created user.
- Goto Security Credentials tab and click on create access key.
- This will create the access key. Download the CSV file and click on show secret to copy the secret.