fix(apigateway): invalid JSON structure in StepFunctions error responses causes 500s#34787
Merged
mergify[bot] merged 6 commits intoaws:mainfrom Aug 19, 2025
Merged
fix(apigateway): invalid JSON structure in StepFunctions error responses causes 500s#34787mergify[bot] merged 6 commits intoaws:mainfrom
mergify[bot] merged 6 commits intoaws:mainfrom
Conversation
…gration Fixes aws#34777 by updating the 500 error response template to generate valid JSON objects instead of malformed JSON strings.
Collaborator
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
1 task
Contributor
|
@pahud is this PR still pending? |
Contributor
Author
|
@aemada-aws let me finish it :) |
…ration Fixes aws#34777 by updating the 500 error response template to generate valid JSON objects instead of malformed JSON strings. The StepFunctions integration in API Gateway had an invalid VTL (Velocity Template Language) response template for 500 errors that generated malformed JSON, causing API Gateway to throw transformation errors instead of properly handling error responses. **Changes:** - Fixed 500 response template from `'"error": $input.path('$.error')'` (invalid JSON string) - To `'{"error": "$input.path('$.error')"}'` (valid JSON object) - Updated unit test expectations to match corrected VTL template - Updated integration test snapshots with corrected CloudFormation templates **Technical Details:** - Template now matches the established pattern used in the 400 response template - Ensures API Gateway can properly transform error responses without throwing 500 errors - CloudFormation templates now generate valid JSON: `{"error": "$input.path('$.error')"}` **Testing:** - Unit tests: 19/19 tests passing (14 integration + 5 API tests) - Integration tests: 36 tests run, 34 unchanged (no regressions), 2 updated (expected) - AWS deployment validation: 2/2 StepFunctions integration tests passed (220+ seconds deployment time) - CloudFormation template validation: Corrected VTL templates generate valid JSON BREAKING CHANGE: The 500 error response template now generates valid JSON objects instead of malformed JSON strings. This may affect applications that were parsing the malformed response, but the new format is the correct JSON structure.
Abogical
approved these changes
Aug 19, 2025
Contributor
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Contributor
|
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Contributor
|
Comments on closed issues and PRs are hard for our team to see. |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Issue # (if applicable)
Closes #34777
Reason for this change
The StepFunctions integration in API Gateway has an invalid VTL (Velocity Template Language) response template for 500 errors that generates malformed JSON, causing API Gateway to throw transformation errors instead of properly handling error responses.
Description of changes
stepfunctions.ts:217-219- Changed from invalid string to proper JSON object structurestepfunctions.test.ts:561-563andstepfunctions-api.test.ts:285-291- Tests now expect corrected JSON templateTechnical Details:
'"error": $input.path(\'$.error\')'(invalid JSON string)'{"error": "$input.path(\'$.error\')"}'(valid JSON object)Describe any new or updated permissions being added
N/A - No IAM permissions changes required. This is a template formatting fix.
Description of how you validated changes
Comprehensive Test Results:
CloudFormation Impact Verified:
"application/json": "\"error\": $input.path('$.error')"(invalid JSON string)"application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"(valid JSON object)Regression Testing:
API Gateway Deployment Replacement Required
This change modifies the integration response template format, which will cause API Gateway deployments to be replaced during stack updates.
What's Changing
"application/json": "\"error\": $input.path('$.error')""application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"Impact
Affected Resources
AWS::ApiGateway::Deploymentresources in integration testsAWS::ApiGateway::Stageresources (due to deployment reference changes)Migration Notes
"error message"to{"error": "error message"}Testing
Feature Flag Assessment: ❌ Not Required
Rationale:
Risk Level: Low - Response format improvement only
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license