-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(apigateway): invalid JSON structure in StepFunctions error responses causes 500s #34787
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
Conversation
…gration Fixes aws#34777 by updating the 500 error response template to generate valid JSON objects instead of malformed JSON strings.
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
|
@pahud is this PR still pending? |
|
@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.
|
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). |
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. |
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