Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(handler): Add custom header to all AWS responses from LocalStack #12769

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

gregfurman
Copy link
Contributor

@gregfurman gregfurman commented Jun 17, 2025

Motivation

This PR adds a custom header to all service responses -- allowing us to distinguish whether a request orignates from LocalStack or AWS.

Changes

  • Adds a LOCALSTACK_RESPONSE_HEADER_ENABLED environment variable that is opt-out by default.
  • When LOCALSTACK_RESPONSE_HEADER_ENABLED is truthy, a handler is added to the response chain that adds a x-localstack: true header to all responses from LocalStack gateway.

@gregfurman gregfurman added this to the 4.6 milestone Jun 17, 2025
@gregfurman gregfurman requested a review from joe4dev June 17, 2025 23:42
@gregfurman gregfurman self-assigned this Jun 17, 2025
@gregfurman gregfurman added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Jun 17, 2025
Copy link

github-actions bot commented Jun 17, 2025

S3 Image Test Results (AMD64 / ARM64)

β€‡β€ˆβ€‡β€‡2 files    2 suites   9m 7s ⏱️
β€‡β€ˆ506 tests 456 βœ…β€ƒβ€‡50 πŸ’€β€ƒ0 ❌
1β€ˆ012 runsβ€Šβ€ƒ912 βœ…β€ƒ100 πŸ’€β€ƒ0 ❌

Results for commit 73ff947.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 17, 2025

Test Results - Preflight, Unit

21β€ˆ635 tests  +5   19β€ˆ978 βœ… +5   6m 10s ⏱️ -14s
β€‡β€‡β€ˆβ€‡β€‡1 suites Β±0    1β€ˆ657 πŸ’€ Β±0 
β€‡β€‡β€ˆβ€‡β€‡1 files   Β±0β€‚β€ƒβ€ƒβ€‡β€‡β€ˆβ€‡β€‡0 ❌ Β±0 

Results for commit 73ff947. ± Comparison against base commit 67b3da6.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

Test Results (amd64) - Acceptance

7 tests  Β±0   5 βœ… Β±0   3m 7s ⏱️ -1s
1 suites Β±0   2 πŸ’€ Β±0 
1 files   Β±0   0 ❌ Β±0 

Results for commit 73ff947. ± Comparison against base commit 67b3da6.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

Test Results - Alternative Providers

988 tests  +1   620 βœ… +31   35m 46s ⏱️ + 6m 22s
  4 suites Β±0   367 πŸ’€  -β€Š31 
  4 files   Β±0     1 ❌ + 1 

For more details on these failures, see this check.

Results for commit 73ff947. ± Comparison against base commit 67b3da6.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

Test Results (amd64) - Integration, Bootstrap

β€‡β€ˆβ€‡β€‡5 files  Β±0β€‚β€ƒβ€‡β€ˆβ€‡β€‡5 suites  Β±0   2h 26m 10s ⏱️ + 3m 3s
5β€ˆ247 tests +5  4β€ˆ320 βœ… +7  926 πŸ’€  -β€Š3  1 ❌ +1 
5β€ˆ253 runsβ€Š +5  4β€ˆ320 βœ… +7  932 πŸ’€  -β€Š3  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 73ff947. ± Comparison against base commit 67b3da6.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 18, 2025

LocalStack Community integration with Pro

β€‡β€ˆβ€‡β€‡2 files  Β±0β€‚β€ƒβ€‡β€ˆβ€‡β€‡2 suites  Β±0   1h 45m 6s ⏱️ + 1m 39s
4β€ˆ890 tests +5  4β€ˆ115 βœ… +7  774 πŸ’€  -β€Š3  1 ❌ +1 
4β€ˆ892 runsβ€Š +5  4β€ˆ115 βœ… +7  776 πŸ’€  -β€Š3  1 ❌ +1 

For more details on these failures, see this check.

Results for commit 73ff947. ± Comparison against base commit 67b3da6.

♻️ This comment has been updated with latest results.

@gregfurman gregfurman marked this pull request as ready for review June 18, 2025 07:45
@gregfurman gregfurman requested a review from thrau as a code owner June 18, 2025 07:45
@gregfurman gregfurman force-pushed the add/infr/is-localstack-check branch from e3c1dcf to 0447cfd Compare June 19, 2025 08:31
@gregfurman gregfurman requested review from tiurin and anisaoshafi June 20, 2025 09:23
Copy link
Contributor

@tiurin tiurin left a comment

Choose a reason for hiding this comment

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

Reviewed and tested env variable in a pairing session.

@@ -1245,6 +1245,9 @@ def use_custom_dns():
# This flag enables `connect_to` to be in-memory only and not do networking calls
IN_MEMORY_CLIENT = is_env_true("IN_MEMORY_CLIENT")

# This flag enables all responses from LocalStack to contain a `x-localstack` HTTP header.
Copy link
Contributor

Choose a reason for hiding this comment

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

dismiss: would rephrase this that flag "disables" this header from being set in response. default: True.

just a heads up to add the env var in public docs: https://docs.localstack.cloud/references/configuration/

@@ -107,6 +108,26 @@ def _infrastructure_setup(
return _infrastructure_setup


@pytest.hookimpl
def pytest_runtest_setup(item):
Copy link
Contributor

Choose a reason for hiding this comment

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

would be nice to add a small high-level docstring/comment what this fixture was added for, so one can understand it in the code without having to open the PR where it was introduced for additional context.

e.g: """ fixture that skips header x-localstack from snapshot evaluation"""


# Otherwise, dynamically inject a path to the custom header inside all skip_snapshot_verify markers paths.
# If a path parameter is None, it's assumed that all paths are skipped.
for mark in skip_markers:
Copy link
Contributor

Choose a reason for hiding this comment

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

question: there are some snapshot tests example where path parameter is not explicitly set, but just the list with the item is passed. Is that covered by these conditions?

@markers.snapshot.skip_snapshot_verify( [ "$..Invalidation.Status", # In real AWS it can be still in progress "$..Location", # not currently supported ] )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huh that is a good question πŸ€” Let me see if the kwargs accounts for this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK damn. You're correct. This is not accounted for. Nice catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update on this... looks like paths are not skipped when added as args as opposed to kwargs πŸ’€

That means the test you linked actually skips all paths.

Copy link
Contributor

@anisaoshafi anisaoshafi left a comment

Choose a reason for hiding this comment

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

nice and clean, good job @gregfurman πŸ‘πŸΌ
I liked the logic for skipping the x-localstack header check from snapshot matching.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants