-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Resolve non-subdomain host prefixes to LocalStack #12653
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
Merged
joe4dev
merged 6 commits into
master
from
fix/resolve-custom-host-prefixes-to-localstack
Jun 3, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
304b73d
Resolve non-subdomain host prefixes to LocalStack
joe4dev 17a7c14
Fix assignment error with extend returning None
joe4dev 79b4573
Add hostPrefix test cases for DNS resolution
joe4dev 27cc631
Add test cases for host prefix resolution within Lambda
joe4dev e5ee939
Remove prefix discovery- removed in a recent botocore update
joe4dev a9ec9bb
Add real validation of NAME_PATTERNS_POINTING_TO_LOCALSTACK
joe4dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
tests/aws/services/lambda_/functions/host_prefix_operation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import json | ||
import os | ||
from urllib.parse import urlparse | ||
|
||
import boto3 | ||
from botocore.config import Config | ||
|
||
region = os.environ["AWS_REGION"] | ||
account = boto3.client("sts").get_caller_identity()["Account"] | ||
state_machine_arn_doesnotexist = ( | ||
f"arn:aws:states:{region}:{account}:stateMachine:doesNotExistStateMachine" | ||
) | ||
|
||
|
||
def do_test(test_case): | ||
sfn_client = test_case["client"] | ||
try: | ||
sfn_client.start_sync_execution( | ||
stateMachineArn=state_machine_arn_doesnotexist, | ||
input=json.dumps({}), | ||
name="SyncExecution", | ||
) | ||
return {"status": "failure"} | ||
except sfn_client.exceptions.StateMachineDoesNotExist: | ||
# We are testing the error case here, so we expect this exception to be raised. | ||
# Testing the error case simplifies the test case because we don't need to set up a StepFunction. | ||
return {"status": "success"} | ||
except Exception as e: | ||
return {"status": "exception", "exception": str(e)} | ||
|
||
|
||
def handler(event, context): | ||
# The environment variable AWS_ENDPOINT_URL is only available in LocalStack | ||
aws_endpoint_url = os.environ.get("AWS_ENDPOINT_URL") | ||
|
||
host_prefix_client = boto3.client( | ||
"stepfunctions", | ||
endpoint_url=os.environ.get("AWS_ENDPOINT_URL"), | ||
) | ||
localstack_adjusted_domain = None | ||
# The localstack domain only works in LocalStack, None is ignored | ||
if aws_endpoint_url: | ||
port = urlparse(aws_endpoint_url).port | ||
localstack_adjusted_domain = f"http://localhost.localstack.cloud:{port}" | ||
host_prefix_client_localstack_domain = boto3.client( | ||
"stepfunctions", | ||
endpoint_url=localstack_adjusted_domain, | ||
) | ||
no_host_prefix_client = boto3.client( | ||
"stepfunctions", | ||
endpoint_url=os.environ.get("AWS_ENDPOINT_URL"), | ||
config=Config(inject_host_prefix=False), | ||
) | ||
|
||
test_cases = [ | ||
{"name": "host_prefix", "client": host_prefix_client}, | ||
{"name": "host_prefix_localstack_domain", "client": host_prefix_client_localstack_domain}, | ||
# Omitting the host prefix can only work in LocalStack | ||
{ | ||
"name": "no_host_prefix", | ||
"client": no_host_prefix_client if aws_endpoint_url else host_prefix_client, | ||
}, | ||
] | ||
|
||
test_results = {} | ||
for test_case in test_cases: | ||
test_name = test_case["name"] | ||
test_result = do_test(test_case) | ||
test_results[test_name] = test_result | ||
|
||
return test_results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.