Skip to content

APIGW: fix rendering of $input.body when empty #12413

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 5 commits into from
Mar 19, 2025

Conversation

bentsku
Copy link
Contributor

@bentsku bentsku commented Mar 19, 2025

Motivation

We broke an upstream integration test following #12322, because API Gateway would forward an empty body to the SQS integration, and SQS disallows that.

This is because API Gateway will replace an empty body with {} when using $input.body in a VTL template.

I've added a few tests validating the assumption, and @dfangl added the SQS regression test to make sure we don't break upstream anymore. He also added some changes in the retry mechanism for deleting REST APIs, and I've updated it to use the Boto config in both creation and deletion of REST APIs.

note: I've also tried with a request template set with text/html and the empty body is still {} so it's not dependent on the content-type.

Changes

  • return a {} string if the body is empty for $input.body (so that it can be passed to function like $util.urlEncode)
  • add a test with multiple cases
  • add an SQS AWS integration test with empty body

@bentsku bentsku added aws:apigateway Amazon API Gateway semver: patch Non-breaking changes which can be included in patch releases labels Mar 19, 2025
@bentsku bentsku added this to the 4.3 milestone Mar 19, 2025
@bentsku bentsku self-assigned this Mar 19, 2025
@bentsku bentsku force-pushed the apigateway/sqs-integration-empty-payload branch from 67acd30 to 8c97dfb Compare March 19, 2025 17:20
Copy link

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 53m 41s ⏱️ - 1m 46s
4 294 tests +1  3 973 ✅ +1  321 💤 ±0  0 ❌ ±0 
4 296 runs  +1  3 973 ✅ +1  323 💤 ±0  0 ❌ ±0 

Results for commit 51c5b56. ± Comparison against base commit cf90cd4.

Copy link
Contributor

@cloutierMat cloutierMat left a comment

Choose a reason for hiding this comment

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

Awesome! A clean one line fix for 300 lines of testing! 🚀

Thanks for deep dive and addressing this issue in VTL, it looks like we will never be out of surprise from it! 🤣

for rest_api_id, _client_region_name in rest_apis:
apigateway_client = aws_client_factory(
region_name=_client_region_name,
config=retry_boto_config,
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch!

"recorded-date": "19-03-2025, 17:03:40",
"recorded-content": {
"response-raw-body": {
"empty-body": "b'{}'",
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm! interesting! nice find

"response-body-attr-access": {
"empty-body": "b'{}'",
"json-body": "b'{}'",
"str-body": "b'{}'"
Copy link
Contributor

Choose a reason for hiding this comment

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

I was trying to expect what would come out of it... not what I thought! 🤣

@bentsku bentsku merged commit 3a46145 into master Mar 19, 2025
35 checks passed
@bentsku bentsku deleted the apigateway/sqs-integration-empty-payload branch March 19, 2025 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
aws:apigateway Amazon API Gateway 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.

3 participants