diff --git a/README.md b/README.md index 2cbd06d..2def5e2 100644 --- a/README.md +++ b/README.md @@ -6,4 +6,10 @@ This is a [Singer](https://singer.io) tap that produces JSON-formatted data following the [Singer spec](https://github.com/singer-io/getting-started/blob/master/SPEC.md). +## Configuration + +This tap can get it's credentials in a variety of ways, including [environment variables](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#environment-variables), [shared credentials file](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#shared-credentials-file), [AWS config file](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#aws-config-file), [assume role provider](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#assume-role-provider), and [IAM roles](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#iam-roles). + +The config file requires `region_name`. You can optionally add `account_id`, `external_id`, and `role_name` to have this tap assume that AWS Role. For testing you can specify `use_local_dynamo` to run against a local instance of [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html). + Copyright © 2019 Stitch diff --git a/tap_dynamodb/__init__.py b/tap_dynamodb/__init__.py index 36da0d6..8989c11 100644 --- a/tap_dynamodb/__init__.py +++ b/tap_dynamodb/__init__.py @@ -12,7 +12,7 @@ LOGGER = singer.get_logger() -REQUIRED_CONFIG_KEYS = ["account_id", "external_id", "role_name", "region_name"] +REQUIRED_CONFIG_KEYS = ["region_name"] def do_discover(config): LOGGER.info("Starting discover") diff --git a/tap_dynamodb/dynamodb.py b/tap_dynamodb/dynamodb.py index e503b2b..b785aba 100644 --- a/tap_dynamodb/dynamodb.py +++ b/tap_dynamodb/dynamodb.py @@ -40,30 +40,31 @@ def load(self): @retry_pattern() def setup_aws_client(config): - role_arn = "arn:aws:iam::{}:role/{}".format(config['account_id'].replace('-', ''), - config['role_name']) - - session = Session() - fetcher = AssumeRoleCredentialFetcher( - session.create_client, - session.get_credentials(), - role_arn, - extra_args={ - 'DurationSeconds': 3600, - 'RoleSessionName': 'TapDynamodDB', - 'ExternalId': config['external_id'] - }, - cache=JSONFileCache() - ) - - refreshable_session = Session() - refreshable_session.register_component( - 'credential_provider', - CredentialResolver([AssumeRoleProvider(fetcher)]) - ) - - LOGGER.info("Attempting to assume_role on RoleArn: %s", role_arn) - boto3.setup_default_session(botocore_session=refreshable_session) + if 'role_name' in config: + role_arn = "arn:aws:iam::{}:role/{}".format(config['account_id'].replace('-', ''), + config['role_name']) + + session = Session() + fetcher = AssumeRoleCredentialFetcher( + session.create_client, + session.get_credentials(), + role_arn, + extra_args={ + 'DurationSeconds': 3600, + 'RoleSessionName': 'TapDynamodDB', + 'ExternalId': config['external_id'] + }, + cache=JSONFileCache() + ) + + refreshable_session = Session() + refreshable_session.register_component( + 'credential_provider', + CredentialResolver([AssumeRoleProvider(fetcher)]) + ) + + LOGGER.info("Attempting to assume_role on RoleArn: %s", role_arn) + boto3.setup_default_session(botocore_session=refreshable_session) def get_client(config): if config.get('use_local_dynamo'):