8000 Adds HTTP integration URIs · codeperl/localstack@c239fc0 · GitHub
[go: up one dir, main page]

Skip to content

Commit c239fc0

Browse files
committed
Adds HTTP integration URIs
1 parent c86b47f commit c239fc0

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

localstack/services/apigateway/integration.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,21 @@ def invoke(self, invocation_context: ApiInvocationContext):
648648
if isinstance(payload, dict):
649649
payload = json.dumps(payload)
650650

651+
# https://docs.aws.amazon.com/apigateway/latest/developerguide/aws-api-gateway-stage-variables-reference.html
652+
# HTTP integration URIs
653+
#
654+
# A stage variable can be used as part of an HTTP integration URL, as shown in the following examples:
655+
#
656+
# A full URI without protocol – http://${stageVariables.<variable_name>}
657+
# A full domain – http://${stageVariables.<variable_name>}/resource/operation
658+
# A subdomain – http://${stageVariables.<variable_name>}.example.com/resource/operation
659+
# A path – http://example.com/${stageVariables.<variable_name>}/bar
660+
# A query string – http://example.com/foo?q=${stageVariables.<variable_name>}
661+
render_vars = {"stageVariables": invocation_context.stage_variables}
662+
rendered_uri = VtlTemplate().render_vtl(uri, render_vars)
663+
651664
uri = apply_request_parameters(
652-
uri,
665+
rendered_uri,
653666
integration=integration,
654667
path_params=path_params,
655668
query_params=query_string_params,

tests/integration/apigateway/test_apigateway_import.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
OAS_30_CIRCULAR_REF_WITH_REQUEST_BODY = os.path.join(
4444
PARENT_DIR, "files", "openapi.spec.circular-ref-with-request-body.json"
4545
)
46-
46+
OAS_30_STAGE_VARIABLES = os.path.join(PARENT_DIR, "files", "openapi.spec.stage-variables.json")
4747
TEST_LAMBDA_PYTHON_ECHO = os.path.join(PARENT_DIR, "awslambda/functions/lambda_echo.py")
4848

4949

@@ -722,3 +722,23 @@ def test_import_with_circular_models_and_request_validation(
722722
request = requests.post(url, json=wrong_request_schema)
723723
assert request.status_code == 400
724724
assert request.json().get("message") == "Invalid request body"
725+
726+
def test_import_with_stage_variables(self, import_apigw, aws_client, echo_http_server):
727+
728+
spec_file = load_file(OAS_30_STAGE_VARIABLES)
729+
import_resp, root_id = import_apigw(body=spec_file, failOnWarnings=True)
730+
rest_api_id = import_resp["id"]
731+
732+
response = aws_client.apigateway.create_deployment(restApiId=rest_api_id)
733+
734+
aws_client.apigateway.create_stage(
735+
restApiId=rest_api_id,
736+
stageName="v1",
737+
variables={"foo": echo_http_server},
738+
deploymentId=response["id"],
739+
)
740+
741+
url = api_invoke_url(api_id=rest_api_id, stage="v1", path="/path1")
742+
response = requests.get(url)
743+
744+
assert response.ok
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"openapi":"3.0.1",
3+
"info":{
4+
"title":"example",
5+
"version":"1.0"
6+
},
7+
"paths":{
8+
"/path1":{
9+
"get":{
10+
"x-amazon-apigateway-integration":{
11+
"httpMethod":"GET",
12+
"payloadFormatVersion":"1.0",
13+
"type":"HTTP_PROXY",
14+
"uri":"${stageVariables.foo}"
15+
}
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)
0