Skip to content
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

Merged
merged 10 commits into from
Oct 26, 2023

Conversation

go-to-k
Copy link
Contributor

@go-to-k go-to-k commented Oct 23, 2023

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

@aws-cdk-automation aws-cdk-automation requested a review from a team October 23, 2023 07:45
@github-actions github-actions bot added admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Oct 23, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a 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.

@aws-cdk-automation aws-cdk-automation dismissed their stale review October 23, 2023 09:21

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@go-to-k go-to-k marked this pull request as ready for review October 23, 2023 09:25
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Oct 23, 2023
Copy link
Contributor

@lpizzinidev lpizzinidev left a 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.

Comment on lines 121 to 122
private readonly useDefaultMethodResponses: boolean;
constructor(stateMachine: sfn.IStateMachine, options: StepFunctionsExecutionIntegrationOptions = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
useDefaultMethodResponses: true,

Redundant.

@@ -488,6 +488,44 @@ describe('StepFunctionsIntegration', () => {
},
});
});

test('default method responses are not created when useDefaultMethodResponses is false', () => {
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

Comment on lines 247 to 255
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,
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@go-to-k
Copy link
Contributor Author

go-to-k commented Oct 25, 2023

@lpizzinidev

Thanks, I changed. Please review them again.

Copy link
Contributor

@lpizzinidev lpizzinidev left a 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.

Comment on lines 174 to 224
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

@go-to-k
Copy link
Contributor Author

go-to-k commented Oct 25, 2023

Thanks, I changed it.

Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 👍

@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Oct 25, 2023
Copy link
Contributor

@scanlonp scanlonp left a 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.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 25, 2023
@mergify mergify bot dismissed scanlonp’s stale review October 26, 2023 04:53

Pull request has been modified.

@go-to-k
Copy link
Contributor Author

go-to-k commented Oct 26, 2023

@scanlonp

I was satisfied with just the StepFunctionsIntegration.startExecution test. I added that integ test.

I did not want to interfere with the behavior of the existing StepFunctionsRestApi test with useDefaultMethodResponses is true as a default value, so I added a new test.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 26, 2023
Copy link
Contributor

@scanlonp scanlonp left a 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.

@mergify
Copy link
Contributor

mergify bot commented Oct 26, 2023

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).

@scanlonp scanlonp self-assigned this Oct 26, 2023
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 26, 2023
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 257285a
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 22a3234 into aws:main Oct 26, 2023
12 checks passed
@mergify
Copy link
Contributor

mergify bot commented Oct 26, 2023

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).

mrgrain pushed a commit that referenced this pull request Nov 1, 2023
…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*
@go-to-k go-to-k deleted the feat/apigateway-useDefaultMethodResponses branch November 23, 2023 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

apigateway: StepFunctionsIntegrations add default methodResponses
4 participants