Todd de Quincey
09/01/2023, 6:04 PMAWS_REGION
env var being overridden in ServerlessTodd de Quincey
09/01/2023, 6:10 PMeu-west-1
via an env var of AWS_REGION
.
3. Running the asset locally, the data is correctly loaded into the S3 bucket / Glue database and table
4. However, on Serverless, this fails, stating that the database could not be found…
5. So to help debug, I inserted wr.catalog.create_database(_name_=database, _boto3_session_=_self_.session)
to see if it could create the database first, and it DID create the database. In theory this should have errored out as the database already exists
6. Digging through our AWS account, I can see that in fact, a new database has been created, but in us-west-2
- which is coincidentally, the same region which Dagster Serverless runs in. We do not use us-west-2
for any services at all in AWS.
7. I dropped into the debugger, and the session passed into AWS Wranger does have the region set to eu-west-1
8. Logging the AWS region in Dagster cloud does show that it is using eu-west-1
9. To ensure this isn’t a misconfigured env var, I downloaded the environment variables from Dagster cloud and used them locally. Again though, everything worked fine.
This task runs correctly in our existing orchestrator, and locally. So I can only assume something funky is happening on the Dagster side, but that would seem very odd.
Any thoughts at all?Joe
09/01/2023, 6:13 PMTodd de Quincey
09/01/2023, 6:14 PMTodd de Quincey
09/01/2023, 6:14 PMmidnite
daniel
09/01/2023, 6:17 PMeu-west-1
via an env var of AWS_REGION"
- by this do you mean you are setting the env var and then the intention is that boto will read that env var when figuring out the region? Or are you doing something like
boto3.session(region=os.getenv("AWS_REGION")
where you are the one passing in the region?Todd de Quincey
09/01/2023, 6:18 PMdef get_boto3_session(assume_role_arn=None):
session = boto3.Session(
aws_access_key_id=os.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key=os.getenv("AWS_SECRET_ACCESS_KEY"),
region_name=os.getenv("AWS_REGION"),
)
if not assume_role_arn:
return session
fetcher = AssumeRoleCredentialFetcher(
client_creator=_get_client_creator(session),
source_credentials=session.get_credentials(),
role_arn=assume_role_arn,
)
botocore_session = botocore.session.Session()
botocore_session._credentials = DeferredRefreshableCredentials(
method="assume-role", refresh_using=fetcher.fetch_credentials
)
return boto3.Session(botocore_session=botocore_session)
Todd de Quincey
09/01/2023, 6:19 PMdaniel
09/01/2023, 6:21 PMif not assume_role_arn
)? asking because i see that after that it is creating sessions without passing in the region (e.g. botocore.session.Session() also takes in a region_name parameter)daniel
09/01/2023, 6:21 PMTodd de Quincey
09/01/2023, 6:22 PMAWS_ROLE_ARN
env var set which we pass into the functiondaniel
09/01/2023, 6:22 PMJoe
09/01/2023, 6:24 PMAWS_REGION
envvar, boto doesn't use that value by default instead prefering AWS_DEFAULT_REGION
which will be set to us-west-2 in serverless unless you override it https://docs.aws.amazon.com/sdkref/latest/guide/feature-region.html#feature-region-sdk-compatTodd de Quincey
09/01/2023, 6:26 PMAWS_DEFAULT_REGION
in Dagster Cloud and set it to our desired region to see if that solves the issueTodd de Quincey
09/01/2023, 6:29 PMTodd de Quincey
09/01/2023, 6:29 PMJoe
09/01/2023, 6:30 PMJoe
09/01/2023, 6:30 PMTodd de Quincey
09/01/2023, 6:31 PMTodd de Quincey
09/01/2023, 6:31 PMTodd de Quincey
09/01/2023, 6:32 PMJoe
09/01/2023, 6:35 PMboto3.setup_default_session(region_name="")
might help, my assumption is that there is still some place thats pulling a session thats not using your preferred regionTodd de Quincey
09/01/2023, 6:36 PMTodd de Quincey
09/01/2023, 6:37 PMdaniel
09/01/2023, 6:37 PMTodd de Quincey
09/01/2023, 6:40 PMus-west-1
). But when AWS Wrangler fires, it’s pointing to eu-west-1
, which has to be in my config…
Apologies for the false alarm - it was just pure coincidence that our default region (since our account must be pre-2017) is the same as Dagsters!