Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(elasticloadbalancingv2): add validation for `RedirectOptions.pa…
…th` (#31202) ### Issue # (if applicable) Closes #31201 . ### Reason for this change If we set a string without a leading `/` for the path property, deployment will fail as shown below. Given: ```ts httpListener.addAction('RedirectAction', { conditions: [elbv2.ListenerCondition.pathPatterns(['/*'])], action: elbv2.ListenerAction.redirect({ protocol: elbv2.ApplicationProtocol.HTTPS, path: 'example/path? ', permanent: true }), }) ``` Result: ```sh Failed resources: MainStack-develop | 1:34:02 AM | CREATE_FAILED | AWS::ElasticLoadBalancingV2::ListenerRule | Alb/HttpListener/RedirectActionRule (AlbHttpListenerRedirectActionRule1D930694) Internal error reported from downstream service during operation 'The Path parameter must be a valid path, should start with a '/', and may contain up to one of each of these placeholders: '#{path}', '#{host}', '#{port}'. (Service: ElasticLoadBalancingV2, Status Code: 400, Request ID: fd4c7f01-9c97-44c1-a177-30ac04b2db26)'. ``` Related docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-elasticloadbalancingv2-listenerrule-redirectconfig.html#cfn-elasticloadbalancingv2-listenerrule-redirectconfig-path ### Description of changes Add validation for `path` prop like below. ```ts if (options.path && !options.path.startsWith('/')) { throw new Error('Redirect path must start with a \'/\''); } ``` ### Description of how you validated changes Add unit test. ### 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*
- Loading branch information