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

DBT_TEST_ATHENA_AWS_PROFILE_NAME should be optional if using SSO #68

Closed
mattiamatrix opened this issue Nov 26, 2022 · 5 comments · Fixed by #63
Closed

DBT_TEST_ATHENA_AWS_PROFILE_NAME should be optional if using SSO #68

mattiamatrix opened this issue Nov 26, 2022 · 5 comments · Fixed by #63

Comments

@mattiamatrix
Copy link
Member

DBT_TEST_ATHENA_AWS_PROFILE_NAME should be optional for those who use SSO and don't have a profile

"aws_profile_name": os.getenv("DBT_TEST_ATHENA_AWS_PROFILE_NAME"),

@mattiamatrix mattiamatrix mentioned this issue Nov 26, 2022
2 tasks
@Jrmyy
Copy link
Member

Jrmyy commented Nov 27, 2022

DBT_TEST_ATHENA_AWS_PROFILE_NAME is optional : indeed if it is not passed, the value will be None and then it is the same as not putting the value, leading to AthenaConnection having default profile.

@mattiamatrix
Copy link
Member Author

mattiamatrix commented Nov 27, 2022

DBT_TEST_ATHENA_AWS_PROFILE_NAME is optional : indeed if it is not passed, the value will be None and then it is the same as not putting the value, leading to AthenaConnection having default profile.

But I don't use any profile because I export AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN directly in the terminal. This works well with dbt run or dbt compile.

It works if I comment out `"aws_profile_name": os.getenv("DBT_TEST_ATHENA_AWS_PROFILE_NAME"),

It will be needed if make test is executed by a job that assumes an IAM Role instead of having the credentials of IAM User.

@nicor88
Copy link
Member

nicor88 commented Nov 27, 2022

@mattiamatrix I've your same setup, I'm assuming a role using sso. I don't think that we need to change anything here, as in the cases where we use AWS_ env (doesn't matter how they are set), we can just ignore to setup the DBT_TEST_ATHENA_AWS_PROFILE_NAME.

@mattiamatrix
Copy link
Member Author

mmh, @nicor88 can you run make test locally? I can't with the current setup. Let me know if you can reproduce.

My .env looks like this make test fails.

DBT_TEST_ATHENA_S3_STAGING_DIR=s3://athena-output-results-eu-west-2
DBT_TEST_ATHENA_REGION_NAME=eu-west-2
DBT_TEST_ATHENA_DATABASE=awsdatacatalog
DBT_TEST_ATHENA_SCHEMA=athena_dbt_tests
DBT_TEST_ATHENA_WORK_GROUND=primary
# DBT_TEST_ATHENA_AWS_PROFILE_NAME=

I believe this is because

@pytest.fixture(scope="class")
def dbt_profile_target():
    return {
        "type": "athena",
        "s3_staging_dir": os.getenv("DBT_TEST_ATHENA_S3_STAGING_DIR"),
        "schema": os.getenv("DBT_TEST_ATHENA_SCHEMA"),
        "database": os.getenv("DBT_TEST_ATHENA_DATABASE"),
        "region_name": os.getenv("DBT_TEST_ATHENA_REGION_NAME"),
        "threads": 1,
        "num_retries": 0,
        "work_group": os.getenv("DBT_TEST_ATHENA_WORK_GROUND"),
        "aws_profile_name": os.getenv("DBT_TEST_ATHENA_AWS_PROFILE_NAME"),
    }

if DBT_TEST_ATHENA_AWS_PROFILE_NAME is not defined, it returns

"aws_profile_name": None

But, this makes AthenaCredentials or boto3 look for a default profile that doesn't exist in my setup.

I can make it works with

@pytest.fixture(scope="class")
def dbt_profile_target():
    return {
        "type": "athena",
        "s3_staging_dir": os.getenv("DBT_TEST_ATHENA_S3_STAGING_DIR"),
        "schema": os.getenv("DBT_TEST_ATHENA_SCHEMA"),
        "database": os.getenv("DBT_TEST_ATHENA_DATABASE"),
        "region_name": os.getenv("DBT_TEST_ATHENA_REGION_NAME"),
        "threads": 1,
        "num_retries": 0,
        "work_group": os.getenv("DBT_TEST_ATHENA_WORK_GROUND"),
        # "aws_profile_name": os.getenv("DBT_TEST_ATHENA_AWS_PROFILE_NAME"),
    }

@Jrmyy
Copy link
Member

Jrmyy commented Nov 28, 2022

I updated the PR, I tested with SSO user, it works now, let me know if it works for you.
There was indeed an issue with the aws_profile_name set as blank string instead of None ...
"aws_profile_name": os.getenv("DBT_TEST_ATHENA_AWS_PROFILE_NAME") or None
with an empty env variable works for me.

@Jrmyy Jrmyy closed this as completed in #63 Nov 28, 2022
Jrmyy added a commit that referenced this issue Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants