Skip to content

Commit 0d5ce56

Browse files
authored
fix(apigateway): invalid JSON structure in StepFunctions error responses causes 500s (aws#34787)
### Issue # (if applicable) Closes aws#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` and `stepfunctions-api.test.ts:285-291` - Tests now expect corrected JSON template - **Updated integration test snapshots** - CloudFormation templates now reflect corrected VTL structure **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 - **Comprehensive unit testing**: All 19 StepFunctions-related tests passing (14 integration + 5 API tests) - **Module build verification**: Confirmed build completes successfully with no linting violations - **Integration testing**: Executed all 36 API Gateway integration tests with CloudFormation verification - **AWS deployment validation**: Real AWS deployment tests confirm templates work correctly - **Template validation**: Confirmed new template generates valid JSON structure matching 400 response pattern - **Regression testing**: 34/36 integration tests unchanged, confirming no impact to other functionality **Comprehensive Test Results:** ```bash # Unit Tests - All Passing ✓ StepFunctionsIntegration suite: 14/14 tests passing ✓ StepFunctionsAPI suite: 5/5 tests passing ✓ Build completes successfully with no linting violations # Integration Tests - Comprehensive Coverage ✓ Total integration tests run: 36 tests ✓ Unchanged tests: 34/36 (confirms no regressions) ✓ Changed tests: 2/36 (expected - VTL template fix) - integ.stepfunctions-api.js: CHANGED (snapshot updated) - integ.stepfunctions-startexecution-without-default-method-responses.js: CHANGED (snapshot updated) # AWS Deployment Validation ✓ integ.stepfunctions-api: 108.7s successful AWS deployment ✓ integ.stepfunctions-startexecution-without-default-method-responses: 112.0s successful AWS deployment ✓ CloudFormation templates generate valid JSON: {"error": "$input.path('$.error')"} ✓ Real AWS integration confirms fix resolves transformation errors ``` **CloudFormation Impact Verified:** - AWS::ApiGateway::Method IntegrationResponses now contain valid JSON templates - Before: `"application/json": "\"error\": $input.path('$.error')"` (invalid JSON string) - After: `"application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"` (valid JSON object) - Integration test snapshots updated to reflect corrected templates **Regression Testing:** - 34 out of 36 integration tests remained unchanged, confirming no impact to other API Gateway functionality - Cross-module impact assessment: No regressions detected in related modules - Performance impact: No performance degradation - template change is purely structural ## ⚠️ Breaking Change Notice **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 - **Before**: `"application/json": "\"error\": $input.path('$.error')"` - **After**: `"application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"` ### Impact - **Deployment**: API Gateway deployments will be replaced (not updated in-place) - **Downtime**: Minimal - replacement happens during CloudFormation update - **Response Format**: Error responses now return proper JSON objects instead of quoted strings ### Affected Resources - `AWS::ApiGateway::Deployment` resources in integration tests - `AWS::ApiGateway::Stage` resources (due to deployment reference changes) ### Migration Notes - No manual intervention required - Existing stacks will automatically replace deployments on next update - Error response format improves from `"error message"` to `{"error": "error message"}` ### Testing - [x] Integration tests pass with new response format - [x] Verified proper JSON structure in error responses - [x] Confirmed deployment replacement behavior in test environments ## Feature Flag Assessment: ❌ Not Required **Rationale**: - Bug fix for malformed JSON response format - Infrastructure-level change with minimal API impact - Improves response consistency and standards compliance - No new functionality being introduced **Risk Level**: Low - Response format improvement only ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) --- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 46021f5 commit 0d5ce56

24 files changed

+1497
-51
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/SfnRestApiWithoutDefaultMethodResponses.assets.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/SfnRestApiWithoutDefaultMethodResponses.template.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"Name": "StepFunctionsRestApi"
4242
}
4343
},
44-
"StepFunctionsRestApiDeployment8FF8D52A481e2c6fad35132b46721c49969398fb": {
44+
"StepFunctionsRestApiDeployment8FF8D52Afb21ad980b99258ceeed145ec1ebe3b5": {
4545
"Type": "AWS::ApiGateway::Deployment",
4646
"Properties": {
4747
"Description": "Automatically created by the RestApi construct",
@@ -60,7 +60,7 @@
6060
"Type": "AWS::ApiGateway::Stage",
6161
"Properties": {
6262
"DeploymentId": {
63-
"Ref": "StepFunctionsRestApiDeployment8FF8D52A481e2c6fad35132b46721c49969398fb"
63+
"Ref": "StepFunctionsRestApiDeployment8FF8D52Afb21ad980b99258ceeed145ec1ebe3b5"
6464
},
6565
"RestApiId": {
6666
"Ref": "StepFunctionsRestApiC6E3E883"
@@ -137,7 +137,7 @@
137137
},
138138
{
139139
"ResponseTemplates": {
140-
"application/json": "\"error\": $input.path('$.error')"
140+
"application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"
141141
},
142142
"SelectionPattern": "5\\d{2}",
143143
"StatusCode": "500"

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/integ.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/manifest.json

Lines changed: 487 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/sfnrestapiwithoutdefaultmethodresponsesDefaultTestDeployAssert7E2275C8.assets.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api-without-default-method-responses.js.snapshot/tree.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api.js.snapshot/StepFunctionsRestApiDeploymentStack.assets.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api.js.snapshot/StepFunctionsRestApiDeploymentStack.template.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
},
160160
{
161161
"ResponseTemplates": {
162-
"application/json": "\"error\": $input.path('$.error')"
162+
"application/json": "{\n \"error\": \"$input.path('$.error')\"\n }"
163163
},
164164
"SelectionPattern": "5\\d{2}",
165165
"StatusCode": "500"

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.stepfunctions-api.js.snapshot/cdk.out

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)