Skip to content

Conversation

@viren-nadkarni
Copy link
Member

@viren-nadkarni viren-nadkarni commented Nov 15, 2023

Motivation

This PR removes last notable remaining uses of get_aws_account_id() and aws_stack.get_region().

These functions will be marked as deprecated or removed altogether in a subsequent PR.

@viren-nadkarni viren-nadkarni self-assigned this Nov 15, 2023
@viren-nadkarni viren-nadkarni added the semver: patch Non-breaking changes which can be included in patch releases label Nov 15, 2023
@viren-nadkarni viren-nadkarni added this to the Playground milestone Nov 15, 2023
@coveralls
Copy link

coveralls commented Nov 16, 2023

Coverage Status

coverage: 84.151% (+0.002%) from 84.149%
when pulling b26f3f6 on remove-context-utils
into 731873d on master.

@github-actions
Copy link

github-actions bot commented Nov 16, 2023

LocalStack Community integration with Pro

       2 files         2 suites   1h 6m 2s ⏱️
2 370 tests 2 055 ✔️ 315 💤 0
2 371 runs  2 055 ✔️ 316 💤 0

Results for commit b26f3f6.

♻️ This comment has been updated with latest results.

Comment on lines +138 to +139
account_id = context.account_id or DEFAULT_AWS_ACCOUNT_ID
region_name = context.region_name or AWS_REGION_US_EAST_1
Copy link
Member Author

@viren-nadkarni viren-nadkarni Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mimics the existing behaviour. At the time of executing this function, the account ID and region enricher handlers are not executed in the handler chain:

handlers.serve_edge_router_rules,

These enricher handlers are responsible for setting the values in the thread context storage. Thus, the get_aws_account_id() and aws_stack.get_region() return the fallback values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation! I hope this doesn't fallback often, I guess it falls back before actually failing but at least we have values. This makes sense and will be revisited in an upcoming APIGW refactor! thanks a lot

):
"""Fix the account ID in the ARNs returned in the given Flask response or string"""
existing = existing or ["123456789", "1234567890", "123456789012", get_aws_account_id()]
existing = existing or ["123456789", "1234567890", DEFAULT_ACCOUNT_ID]
Copy link
Member Author

@viren-nadkarni viren-nadkarni Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This is great again, nice cleaning up! 🧹 that is quite the effort that lead to this final removal. Awesome!
Also, nice spotting the bug in the APIGW SQS integration. It might need a follow up on our side to make the URL construction depend on the SQS URL strategy.

Comment on lines +138 to +139
account_id = context.account_id or DEFAULT_AWS_ACCOUNT_ID
region_name = context.region_name or AWS_REGION_US_EAST_1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation! I hope this doesn't fallback often, I guess it falls back before actually failing but at least we have values. This makes sense and will be revisited in an upcoming APIGW refactor! thanks a lot

Comment on lines 695 to 694
url = urljoin(config.internal_service_url(), f"{get_aws_account_id()}/{queue}")
url = urljoin(config.internal_service_url(), f"{account_id}/{queue}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, damn, this was actually a bad bug 😬 shouldn't this URL depends on the SQS URL strategy actually?

Copy link
Member Author

@viren-nadkarni viren-nadkarni Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily, URL strategy controls how queues will be formatted in outputs. SQS will still recognise other queue URL formats if presented. Moreover the use of config.internal_service_url() prevents us from using the standard and domain strategies.

But you're right in another way, the region is currently omitted in the queue URL. I've added it with 71b862a. Great catch, thanks!

@viren-nadkarni viren-nadkarni merged commit 82fd17a into master Nov 28, 2023
@viren-nadkarni viren-nadkarni deleted the remove-context-utils branch November 28, 2023 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

semver: patch Non-breaking changes which can be included in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants