Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pahud
Copy link
Contributor

@pahud pahud commented Jun 23, 2025

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

  • Fixed invalid VTL template in stepfunctions.ts:217-219 - Changed from invalid string to proper JSON object structure
  • Updated test expectations in stepfunctions.test.ts:561-563 - Test now expects corrected JSON template
  • Fixed unrelated linting issue in network-utils.test.ts:111 - Replaced deprecated fail() with throw new Error()
  • Enhanced CONTRIBUTING.llm.md - Added learnings about module-specific builds, test mirroring bugs, and VTL requirements

Technical Details:

  • Changed 500 response template from '"error": $input.path(\'$.error\')' (invalid JSON string)
  • To '{"error": "$input.path(\'$.error\')"}' (valid JSON object)
  • Template now matches the established pattern used in the 400 response template
  • Ensures API Gateway can properly transform error responses without throwing 500 errors

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

  • Unit tests: Updated existing test expectations to match corrected VTL template
  • Module build: Used efficient cd packages/aws-cdk-lib/aws-apigateway && yarn build approach
  • Targeted testing: Verified all 14 tests in StepFunctionsIntegration suite pass
  • Integration testing: Executed API Gateway + StepFunctions integration tests with CloudFormation verification
  • Template validation: Confirmed new template generates valid JSON structure matching 400 response pattern
  • CloudFormation impact: Verified corrected VTL templates appear properly in generated CloudFormation
  • Regression testing: No changes to core functionality - only fixed malformed JSON output

Test Results:

# Unit Tests
✓ StepFunctionsIntegration suite: 14/14 tests passing
✓ Build completes successfully with no linting violations

# Integration Tests (MANDATORY for CloudFormation changes)
✓ integ.stepfunctions-startexecution.js: UNCHANGED (no snapshot update needed)
✓ integ.stepfunctions-api.js: CHANGED (snapshot updated - VTL template fix confirmed)
✓ integ.stepfunctions-startexecution-without-default-method-responses.js: CHANGED (snapshot updated)
✓ CloudFormation templates now generate valid JSON: {"error": "$input.path('$.error')"}
✓ Integration tests execute successfully in AWS (actual deployment verification)

CloudFormation Impact Verified:

  • AWS::ApiGateway::Method IntegrationResponses now contain valid JSON templates
  • Before: "application/json": "\"error\": $input.path('$.error')"
  • After: "application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

…gration

Fixes aws#34777 by updating the 500 error response template to generate valid JSON objects instead of malformed JSON strings.
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Jun 23, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team June 23, 2025 05:18
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jun 23, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 7476349
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@leonmk-aws leonmk-aws assigned leonmk-aws and unassigned leonmk-aws Jul 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. effort/small Small work item – less than a day of effort p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stepfunctions: invalid vtl in 500 response template
3 participants