Skip to content

APIGateway: Cannot create Resource with colon in pathPart #22477

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

Closed
mascur opened this issue Oct 12, 2022 · 1 comment · Fixed by #22531
Closed

APIGateway: Cannot create Resource with colon in pathPart #22477

mascur opened this issue Oct 12, 2022 · 1 comment · Fixed by #22531
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@mascur
Copy link
Contributor

mascur commented Oct 12, 2022

Describe the bug

Cannot create Resource with a colon in the pathPart. This error is thrown: Error: Resource's path part only allow [a-zA-Z0-9._-], an optional trailing '+' and curly braces at the beginning and the end: events:batch.

Expected Behavior

I expect to successfully deploy this since this works in both the L1 construct and the console.

Current Behavior

This error is thrown during synth: Error: Resource's path part only allow [a-zA-Z0-9._-], an optional trailing '+' and curly braces at the beginning and the end: events:batch.

Reproduction Steps

backend = _lambda.Function(
    self, 'HelloHandler',
    runtime=_lambda.Runtime.PYTHON_3_7,
    code=_lambda.Code.from_asset('lambda'),
    handler='hello.handler',
)

api = apigw.LambdaRestApi(self, "TestAPI", handler=backend, proxy=False)
api.root.add_method("GET")
api_v1_resource = api.root.add_resource("v1")
events_batch_resource = api_v1_resource.add_resource("events:batch")

Possible Solution

Change this to allow colons:

if (!/^[a-zA-Z0-9\.\_\-]+$/.test(part)) {

Additional Information/Context

A workaround is

...
events_batch_resource = api_v1_resource.add_resource("events_batch")
events_batch_resource.node.default_child.path_part = "events:batch"

CDK CLI Version

2.45.0

Framework Version

No response

Node.js Version

16.16.0

OS

OSX

Language

Typescript, Python

Language Version

Python (3.10.4)

Other information

No response

@mascur mascur added bug This issue is a bug. good first issue Related to contributions. See CONTRIBUTING.md p2 @aws-cdk/aws-apigateway Related to Amazon API Gateway effort/small Small work item – less than a day of effort labels Oct 12, 2022
@mergify mergify bot closed this as completed in #22531 Oct 19, 2022
mergify bot pushed a commit that referenced this issue Oct 19, 2022
… resources with colon (#22531)

This PR adjusts the validation rules for path parts in resources created using the APIGateway library to allow the use of colons in pathParts, as requested in #22477. This enables the creation of resources with paths such as `events:batch` (from the reproduction steps in the related issue).

An existing resource unit test (`'url for a resource'`) has been updated to ensure that a colon in a pathPart does not throw an error and properly reflects in the output of `RestApi.urlForPath`. The integration test `integ.restapi` has also been updated, wherein the `appliances` resource now has a path of `appliances:all` instead of `appliances`. If this is the wrong place to test the fix, I will gladly create a new resource to test on, or a new test altogether.

Closes #22477.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

mrgrain pushed a commit to mrgrain/aws-cdk that referenced this issue Oct 24, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
… resources with colon (aws#22531)

This PR adjusts the validation rules for path parts in resources created using the APIGateway library to allow the use of colons in pathParts, as requested in aws#22477. This enables the creation of resources with paths such as `events:batch` (from the reproduction steps in the related issue).

An existing resource unit test (`'url for a resource'`) has been updated to ensure that a colon in a pathPart does not throw an error and properly reflects in the output of `RestApi.urlForPath`. The integration test `integ.restapi` has also been updated, wherein the `appliances` resource now has a path of `appliances:all` instead of `appliances`. If this is the wrong place to test the fix, I will gladly create a new resource to test on, or a new test altogether.

Closes aws#22477.

----

### All Submissions:

* [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-apigateway Related to Amazon API Gateway bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
1 participant