Skip to content

Business intelligence made simple

Merge branch 'configurable-aws-credentials-for-athena' of https://github.com/bobby-vandiver/blazer into bobby-vandiver-configurable-aws-credentials-for-athena

Andrew Kanecc5a9df75864
diff --cc README.md
index f8651ba5,fdb9b27f..653aa48a
--- a/README.md
+++ b/README.md
@@@ -621,42 -504,19 +621,44 @@@ data_sources
adapter: athena
database: database
output_location: s3://some-bucket/
++ access_key_id: ... # optional
++ secret_access_key: ... # optional
+```
+
+Here’s an example IAM policy:
+
+```json
+{
+ "Version": "2012-10-17",
+ "Statement": [
+ {
+ "Effect": "Allow",
+ "Action": [
+ "athena:GetQueryExecution",
+ "athena:GetQueryResults",
+ "athena:StartQueryExecution"
+ ],
+ "Resource": [
+ "arn:aws:athena:region:account-id:workgroup/primary"
+ ]
+ },
+ {
+ "Effect": "Allow",
+ "Action": [
+ "glue:GetTable",
+ "glue:GetTables"
+ ],
+ "Resource": [
+ "arn:aws:glue:region:account-id:catalog",
+ "arn:aws:glue:region:account-id:database/default",
+ "arn:aws:glue:region:account-id:table/default/*"
+ ]
+ }
+ ]
+}
```
-The AWS Access Key ID and Secret Access Key can optionally be set:
-
-```yml
-data_sources:
- my_source:
- adapter: athena
- database: database
- output_location: s3://some-bucket/
- access_key_id: my-access-key-id
- secret_access_key: my-secret-access-key
-```
+You also need to configure [S3 permissions](https://aws.amazon.com/premiumsupport/knowledge-center/access-denied-athena/).
### Amazon Redshift
diff --cc lib/blazer/adapters/athena_adapter.rb
index d62bc49d,42f65ddf..62f46259
--- a/lib/blazer/adapters/athena_adapter.rb
+++ b/lib/blazer/adapters/athena_adapter.rb
@@@ -118,11 -118,15 +118,21 @@@ module Blaze
end
def client
- @client ||= Aws::Athena::Client.new
- @client ||= Aws::Athena::Client.new(credentials: credentials)
++ @client ||= Aws::Athena::Client.new(**client_options)
end
def glue
- @glue ||= Aws::Glue::Client.new
- @glue ||= Aws::Glue::Client.new(credentials: credentials)
++ @glue ||= Aws::Glue::Client.new(**client_options)
+ end
+
- def credentials
- @credentials ||= Aws::Credentials.new(settings['access_key_id'], settings['secret_access_key']) if settings.key?('access_key_id') && settings.key?('secret_access_key')
++ def client_options
++ @client_options ||= begin
++ if settings["access_key_id"] || settings["secret_access_key"]
++ {credentials: Aws::Credentials.new(settings["access_key_id"], settings["secret_access_key"])}
++ else
++ {}
++ end
++ end
end
end
end