8000 Fix bug: Support list header value on Step Functions ApiGateway:Invoke integration by ShahadIshraq · Pull Request #11681 · localstack/localstack · GitHub
[go: up one dir, main page]

Skip to content

Fix bug: Support list header value on Step Functions ApiGateway:Invoke integration #11681

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
merged 3 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def _headers_of(parameters: TaskParameters) -> Optional[dict]:
for forbidden_prefix in StateTaskServiceApiGateway._FORBIDDEN_HTTP_HEADERS_PREFIX:
if key.startswith(forbidden_prefix):
raise ValueError(f"The 'Headers' field contains unsupported values: {key}")

value = headers.get(key)
if isinstance(value, list):
headers[key] = f"[{','.join(value)}]"

if "RequestBody" in parameters:
headers[HEADER_CONTENT_TYPE] = APPLICATION_JSON
headers["Accept"] = APPLICATION_JSON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class ServicesTemplates(TemplateLoader):
API_GATEWAY_INVOKE_WITH_BODY: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/api_gateway_invoke_with_body.json5"
)
API_GATEWAY_INVOKE_WITH_HEADERS: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/api_gateway_invoke_with_headers.json5"
)
API_GATEWAY_INVOKE_WITH_QUERY_PARAMETERS: Final[str] = os.path.join(
_THIS_FOLDER, "statemachines/api_gateway_invoke_with_query_parameters.json5"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"Comment": "API_GATEWAY_INVOKE_WITH_HEADERS",
"StartAt": "ApiGatewayInvoke",
"States": {
"ApiGatewayInvoke": {
"Type": "Task",
"Resource": "arn:aws:states:::apigateway:invoke",
"Parameters": {
"ApiEndpoint.$": "$.ApiEndpoint",
"Method.$": "$.Method",
"Path.$": "$.Path",
"Stage.$": "$.Stage",
"RequestBody.$": "$.RequestBody",
"Headers.$": "$.Headers",
},
"End": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,67 @@ def test_invoke_with_body_post(
exec_input,
)

@pytest.mark.parametrize(
"custom_header",
[
## TODO: Implement checks for singleStringHeader case to cause exception
pytest.param(
"singleStringHeader",
marks=pytest.mark.skip(reason="Behavior parity not implemented"),
),
["arrayHeader0"],
["arrayHeader0", "arrayHeader1"],
],
)
@markers.aws.validated
def test_invoke_with_headers(
self,
aws_client,
create_lambda_function,
create_role_with_policy,
create_iam_role_for_sfn,
create_state_machine,
create_rest_apigw,
sfn_snapshot,
custom_header,
):
self._add_api_gateway_transformers(sfn_snapshot)

http_method = "POST"
part_path = "id_func"

api_url, api_stage = self._create_lambda_api_response(
apigw_client=aws_client.apigateway,
create_lambda_function=create_lambda_function,
create_role_with_policy=create_role_with_policy,
lambda_function_filename=ST.LAMBDA_ID_FUNCTION,
create_rest_apigw=create_rest_apigw,
http_method=http_method,
part_path=part_path,
)

template = ST.load_sfn_template(ST.API_GATEWAY_INVOKE_WITH_HEADERS)
definition = json.dumps(template)

exec_input = json.dumps(
{
"ApiEndpoint": api_url,
"Method": http_method,
"Path": part_path,
"Stage": api_stage,
"RequestBody": {"message": "HelloWorld!"},
"Headers": {"custom_header": custom_header},
}
)
create_and_record_execution(
aws_client.stepfunctions,
create_iam_role_for_sfn,
create_state_machine,
sfn_snapshot,
definition,
exec_input,
)

@markers.snapshot.skip_snapshot_verify(
paths=[
# TODO: ApiGateway return incorrect output type (string instead of json) either here or in other scenarios,
Expand Down
Loading
0