-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(apigateway): add useDefaultMethodResponses property for StepFunctionsIntegrations #27645
feat(apigateway): add useDefaultMethodResponses property for StepFunctionsIntegrations #27645
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
Just some documentation and test minor-changes needed in my opinion.
private readonly useDefaultMethodResponses: boolean; | ||
constructor(stateMachine: sfn.IStateMachine, options: StepFunctionsExecutionIntegrationOptions = {}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private readonly useDefaultMethodResponses: boolean; | |
constructor(stateMachine: sfn.IStateMachine, options: StepFunctionsExecutionIntegrationOptions = {}) { | |
private readonly useDefaultMethodResponses: boolean; | |
constructor(stateMachine: sfn.IStateMachine, options: StepFunctionsExecutionIntegrationOptions = {}) { |
@@ -35,6 +35,7 @@ class StepFunctionsRestApiDeploymentStack extends cdk.Stack { | |||
accountId: true, | |||
userArn: true, | |||
}, | |||
useDefaultMethodResponses: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useDefaultMethodResponses: true, |
Redundant.
@@ -488,6 +488,44 @@ describe('StepFunctionsIntegration', () => { | |||
}, | |||
}); | |||
}); | |||
|
|||
test('default method responses are not created when useDefaultMethodResponses is false', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please also add a similar test using the StepFunctionsRestApi
class constructor to increase coverage?
@@ -83,6 +83,13 @@ export interface StepFunctionsExecutionIntegrationOptions extends IntegrationOpt | |||
* @default false | |||
*/ | |||
readonly authorizer?: boolean; | |||
|
|||
/** | |||
* Enable to add default method response models with 200, 400 and 500 status codes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Enable to add default method response models with 200, 400 and 500 status codes. | |
* Whether to add default response models with 200, 400, and 500 status codes to the method. |
Small revision, will need an update in StepFunctionsRestApiProps
as well.
And in `StepFunctionsRestApi`, method response models (`methodResponses`) with 200, 400 and 500 status codes are added by default. | ||
|
||
If you don't want to add default method response models, you can set `useDefaultMethodResponses` to `false` as follows: | ||
|
||
```ts fixture=stepfunctions | ||
new apigateway.StepFunctionsRestApi(this, 'StepFunctionsRestApi', { | ||
stateMachine: machine, | ||
useDefaultMethodResponses: false, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in `StepFunctionsRestApi`, method response models (`methodResponses`) with 200, 400 and 500 status codes are added by default. | |
If you don't want to add default method response models, you can set `useDefaultMethodResponses` to `false` as follows: | |
```ts fixture=stepfunctions | |
new apigateway.StepFunctionsRestApi(this, 'StepFunctionsRestApi', { | |
stateMachine: machine, | |
useDefaultMethodResponses: false, | |
}); | |
To disable default response models generation use the `useDefaultMethodResponses` property: | |
```ts | |
new apigateway.StepFunctionsRestApi(this, 'StepFunctionsRestApi', { | |
stateMachine: machine, | |
useDefaultMethodResponses: false, | |
}); |
I would move this here.
Thanks, I changed. Please review them again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just a minor adjustment and it will be good to go for me.
AuthorizationType: 'NONE', | ||
RestApiId: { | ||
Ref: 'StepFunctionsRestApiC6E3E883', | ||
}, | ||
ResourceId: { | ||
'Fn::GetAtt': [ | ||
'StepFunctionsRestApiC6E3E883', | ||
'RootResourceId', | ||
], | ||
}, | ||
Integration: { | ||
Credentials: { | ||
'Fn::GetAtt': [ | ||
'StepFunctionsRestApiANYStartSyncExecutionRole425C03BB', | ||
'Arn', | ||
], | ||
}, | ||
IntegrationHttpMethod: 'POST', | ||
IntegrationResponses: getIntegrationResponse(), | ||
RequestTemplates: { | ||
'application/json': { | ||
'Fn::Join': [ | ||
'', | ||
[ | ||
"## Velocity Template used for API Gateway request mapping template\n##\n## This template forwards the request body, header, path, and querystring\n## to the execution input of the state machine.\n##\n## \"@@\" is used here as a placeholder for '\"' to avoid using escape characters.\n\n#set($inputString = '')\n#set($includeHeaders = false)\n#set($includeQueryString = true)\n#set($includePath = true)\n#set($includeAuthorizer = false)\n#set($allParams = $input.params())\n{\n \"stateMachineArn\": \"", | ||
{ | ||
Ref: 'StateMachine2E01A3A5', | ||
}, | ||
"\",\n\n #set($inputString = \"$inputString,@@body@@: $input.body\")\n\n #if ($includeHeaders)\n #set($inputString = \"$inputString, @@header@@:{\")\n #foreach($paramName in $allParams.header.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.header.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n \n #end\n\n #if ($includeQueryString)\n #set($inputString = \"$inputString, @@querystring@@:{\")\n #foreach($paramName in $allParams.querystring.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.querystring.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #if ($includePath)\n #set($inputString = \"$inputString, @@path@@:{\")\n #foreach($paramName in $allParams.path.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.path.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n \n #if ($includeAuthorizer)\n #set($inputString = \"$inputString, @@authorizer@@:{\")\n #foreach($paramName in $context.authorizer.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($context.authorizer.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #set($requestContext = \"\")\n ## Check if the request context should be included as part of the execution input\n #if($requestContext && !$requestContext.empty)\n #set($inputString = \"$inputString,\")\n #set($inputString = \"$inputString @@requestContext@@: $requestContext\")\n #end\n\n #set($inputString = \"$inputString}\")\n #set($inputString = $inputString.replaceAll(\"@@\",'\"'))\n #set($len = $inputString.length() - 1)\n \"input\": \"{$util.escapeJavaScript($inputString.substring(1,$len)).replaceAll(\"\\\\'\",\"'\")}\"\n}\n", | ||
], | ||
], | ||
}, | ||
}, | ||
Type: 'AWS', | ||
Uri: { | ||
'Fn::Join': [ | ||
'', | ||
[ | ||
'arn:', | ||
{ | ||
Ref: 'AWS::Partition', | ||
}, | ||
':apigateway:', | ||
{ | ||
Ref: 'AWS::Region', | ||
}, | ||
':states:action/StartSyncExecution', | ||
], | ||
], | ||
}, | ||
PassthroughBehavior: 'NEVER', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuthorizationType: 'NONE', | |
RestApiId: { | |
Ref: 'StepFunctionsRestApiC6E3E883', | |
}, | |
ResourceId: { | |
'Fn::GetAtt': [ | |
'StepFunctionsRestApiC6E3E883', | |
'RootResourceId', | |
], | |
}, | |
Integration: { | |
Credentials: { | |
'Fn::GetAtt': [ | |
'StepFunctionsRestApiANYStartSyncExecutionRole425C03BB', | |
'Arn', | |
], | |
}, | |
IntegrationHttpMethod: 'POST', | |
IntegrationResponses: getIntegrationResponse(), | |
RequestTemplates: { | |
'application/json': { | |
'Fn::Join': [ | |
'', | |
[ | |
"## Velocity Template used for API Gateway request mapping template\n##\n## This template forwards the request body, header, path, and querystring\n## to the execution input of the state machine.\n##\n## \"@@\" is used here as a placeholder for '\"' to avoid using escape characters.\n\n#set($inputString = '')\n#set($includeHeaders = false)\n#set($includeQueryString = true)\n#set($includePath = true)\n#set($includeAuthorizer = false)\n#set($allParams = $input.params())\n{\n \"stateMachineArn\": \"", | |
{ | |
Ref: 'StateMachine2E01A3A5', | |
}, | |
"\",\n\n #set($inputString = \"$inputString,@@body@@: $input.body\")\n\n #if ($includeHeaders)\n #set($inputString = \"$inputString, @@header@@:{\")\n #foreach($paramName in $allParams.header.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.header.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n \n #end\n\n #if ($includeQueryString)\n #set($inputString = \"$inputString, @@querystring@@:{\")\n #foreach($paramName in $allParams.querystring.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.querystring.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #if ($includePath)\n #set($inputString = \"$inputString, @@path@@:{\")\n #foreach($paramName in $allParams.path.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($allParams.path.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n \n #if ($includeAuthorizer)\n #set($inputString = \"$inputString, @@authorizer@@:{\")\n #foreach($paramName in $context.authorizer.keySet())\n #set($inputString = \"$inputString @@$paramName@@: @@$util.escapeJavaScript($context.authorizer.get($paramName))@@\")\n #if($foreach.hasNext)\n #set($inputString = \"$inputString,\")\n #end\n #end\n #set($inputString = \"$inputString }\")\n #end\n\n #set($requestContext = \"\")\n ## Check if the request context should be included as part of the execution input\n #if($requestContext && !$requestContext.empty)\n #set($inputString = \"$inputString,\")\n #set($inputString = \"$inputString @@requestContext@@: $requestContext\")\n #end\n\n #set($inputString = \"$inputString}\")\n #set($inputString = $inputString.replaceAll(\"@@\",'\"'))\n #set($len = $inputString.length() - 1)\n \"input\": \"{$util.escapeJavaScript($inputString.substring(1,$len)).replaceAll(\"\\\\'\",\"'\")}\"\n}\n", | |
], | |
], | |
}, | |
}, | |
Type: 'AWS', | |
Uri: { | |
'Fn::Join': [ | |
'', | |
[ | |
'arn:', | |
{ | |
Ref: 'AWS::Partition', | |
}, | |
':apigateway:', | |
{ | |
Ref: 'AWS::Region', | |
}, | |
':states:action/StartSyncExecution', | |
], | |
], | |
}, | |
PassthroughBehavior: 'NEVER', |
Let's match only on HttpMethod
and MethodResponses
to keep this concise.
Thanks, I changed it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not have an integ test for the StepFunctionsRestApi
invocation? Otherwise looks good to go.
Pull request has been modified.
I was satisfied with just the I did not want to interfere with the behavior of the existing StepFunctionsRestApi test with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for the new integ test. The optional parameter is a good way to disable automatic behavior, and the tests cover both the template validation and deploy success.
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). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
…tionsIntegrations (#27645) In `StepFunctionsIntegration`, method response models (`methodResponses`) with 200, 400 and 500 status codes are added by default. This PR adds `useDefaultMethodResponses` property not to add default method response models by set it to `false`. Closes #27520. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
In
StepFunctionsIntegration
, method response models (methodResponses
) with 200, 400 and 500 status codes are added by default.This PR adds
useDefaultMethodResponses
property not to add default method response models by set it tofalse
.Closes #27520.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license