Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support AWS IAM profile for Amazon Elasticsearch #3005

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions redash/query_runner/amazon_elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from . import register

try:
from requests_aws4auth import AWS4Auth
from requests_aws_sign import AWSV4Sign
from botocore import session, credentials
enabled = True
except ImportError:
enabled = False
Expand Down Expand Up @@ -40,17 +41,29 @@ def configuration_schema(cls):
'secret_key': {
'type': 'string',
'title': 'Secret Key'
},
'use_aws_iam_profile': {
'type': 'boolean',
'title': 'Use AWS IAM Profile'
}
},
"secret": ["secret_key"],
"order": ["server", "region", "access_key", "secret_key"],
"required": ['server', 'region', 'access_key', 'secret_key']
"order": ["server", "region", "access_key", "secret_key", "use_aws_iam_profile"],
"required": ['server', 'region']
}

def __init__(self, configuration):
super(AmazonElasticsearchService, self).__init__(configuration)

self.auth = AWS4Auth(configuration['access_key'], configuration['secret_key'], configuration['region'], 'es')
region = configuration['region']
cred = None
if configuration.get('use_aws_iam_profile', False):
cred = credentials.get_credentials(session.Session())
else:
cred = credentials.Credentials(access_key=configuration.get('access_key', ''),
secret_key=configuration.get('secret_key', ''))

self.auth = AWSV4Sign(cred, region, 'es')


register(AmazonElasticsearchService)
2 changes: 1 addition & 1 deletion requirements_all_ds.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pymapd>=0.2.1
qds-sdk>=1.9.6
ibm-db>=2.0.9
pydruid==0.4
requests-aws4auth==0.9
requests_aws_sign==0.1.4
# certifi is needed to support MongoDB and SSL:
certifi
# We don't install snowflake connector by default, as it's causing conflicts with
Expand Down