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(aws-apigateway-sqs): update construct to allow custom path params #1079

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

Conversation

dcustic
Copy link

@dcustic dcustic commented Feb 13, 2024

…for GET, POST, DELETE operations on the SQS

I've read that one concern was backwards compatibility
This solution should backwards compatible, because if the properties are not set, the fallback will be the previous behaviour.

Small PSA: this is my first Open Source PR, so bear with me please. I'm open to any suggestions/requests to learn how to do a propper OpenSource PR.

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: bbffe2f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

|readRequestTemplate?|`string`|API Gateway Request Template for the read method for the default `application/json` content-type.|
|additionalReadRequestTemplates?|`{ [contentType: string]: string; }`|Optional Read Request Templates for content-types other than `application/json`. Use the `readRequestTemplate` property to set the request template for the `application/json` content-type.|
|readIntegrationResponses?|[`api.IntegrationResponses[]`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_apigateway.IntegrationResponse.html)|Optional, custom API Gateway Integration Response for the read method.|
|allowDeleteOperation?|`boolean`|Whether to deploy an API Gateway Method for HTTP DELETE operations on the queue (i.e. sqs:DeleteMessage).|
|allowDeleteOperation?|`boolean`|Whether to deploy an API Gateway Method for DELETE HTTP operations on the queue (i.e. sqs:DeleteMessage).|
Copy link
Author

Choose a reason for hiding this comment

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

Swapped DELETE AND HTTP to be consistent with the GET and POST documentation

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 91fbeea
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: ecff909
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@biffgaut
Copy link
Contributor

Thanks for the contribution - we're excited to review it, but won't be able to until Thursday morning.

@dcustic
Copy link
Author

dcustic commented Feb 13, 2024

Thanks for the contribution - we're excited to review it, but won't be able to until Thursday morning.

Thanks for the heads up. Cheers :)

readonly readRequestPath?: string;
/**
* Optional, custom API Gateway path for the POST method.
* This property can only be specified if the `allowCreateOperation` property is not set to false.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the allowDeleteOperation and allowCreateOperation attributes default to false, it seems the wording for these would be better as "This property can only be specified if the `allowCreateOperation' is set to true."

readonly createRequestPath?: string;
/**
* Optional, custom API Gateway path for the DELETE method.
* This property can only be specif||ied if the `allowDeleteOperation` property is not set to false.
Copy link
Contributor

Choose a reason for hiding this comment

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

Pretty sure you don't mean 'specif' OR 'ied' here and that this is a typo?

@@ -244,13 +265,14 @@ export class ApiGatewayToSqs extends Construct {
// Create
const createRequestTemplate = props.createRequestTemplate ?? this.defaultCreateRequestTemplate;
if (props.allowCreateOperation && props.allowCreateOperation === true) {
const apiCreateRequestResource = props.createRequestPath ? this.apiGateway.root.addResource(props.createRequestPath) : this.apiGateway.root;
Copy link
Contributor

Choose a reason for hiding this comment

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

The first thing I tried was creating a new integration test with the following:

new ApiGatewayToSqs(stack, 'test-api-gateway-sqs-default', {
  allowCreateOperation: true,
  allowDeleteOperation: true,
  createRequestPath: 'my-resource',
  deleteRequestPath: 'my-resource',

I think think a single resource for a workload, using the HTTP method to distinguish between operations, is a reasonable expectation of a client. While it's going to be non-trivial, it seems worthwhile to sort out the required resources prior to line 266. addResource will return the resulting resource and we would then call addMethod for additional operations.

(I did not write this test anticipating this issue, I was lazy and reused the resource name :-)

An alternative would be specifying a single, optional resource name that would be used across all implemented HTTP methods. The more I think about this, the more it appeals to me. Using different resource names for different HTTP methods on the same queue does not seem like a design we would want to encourage (and shouldn't have implemented ourselves with the 'message' resource).

What do you think?

@@ -63,14 +63,17 @@ new ApiGatewayToSqs(this, "ApiGatewayToSqsPattern", new ApiGatewayToSqsProps.Bui
|deployDeadLetterQueue?|`boolean`|Whether to deploy a secondary queue to be used as a dead letter queue. Defaults to `true`.|
|maxReceiveCount|`number`|The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue.|
|allowCreateOperation?|`boolean`|Whether to deploy an API Gateway Method for POST HTTP operations on the queue (i.e. sqs:SendMessage).|
|createRequestPath?|`string`| Optional, user provided request path for POST HTTP operations.|
Copy link
Contributor

@biffgaut biffgaut Feb 15, 2024

Choose a reason for hiding this comment

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

I think we should call these attributes resources rather than paths (createRequestResource, readRequestResource, etc.). We only allow one level deep - if someone tries to specify a valid "path" name of "resource/subresource" the stack will fail to launch because this is an invalid resource name.

@biffgaut
Copy link
Contributor

Small PSA: this is my first Open Source PR, so bear with me please. I'm open to any suggestions/requests to learn how to do a propper OpenSource PR.

You did just fine. Some issues did pop up in review that you will read about, but the issues were surprises to us as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pattern: aws-apigateway-sqs registers methods on root and a /message resource inconsistently
3 participants