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

fix(cli): aws-cn partition fails notification ARN validation #29722

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/util/validate-notification-arn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
* Validate SNS topic arn
*/
export function validateSnsTopicArn(arn: string): boolean {
return /^arn:aws:sns:[a-z0-9\-]+:[0-9]+:[a-z0-9\-\_]+$/i.test(arn);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use Arn.split instead? There is still another unsupported partition with this solution (aws-us-gov), and it would be cleaner to just test the service and resource name with that method instead of a growing RegExp

return /^arn:(?:aws|aws-cn):sns:[a-z0-9\-]+:[0-9]+:[a-z0-9\-\_]+$/i.test(arn);
}
5 changes: 5 additions & 0 deletions packages/aws-cdk/test/util/validate-notification-arn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ describe('validate sns arns', () => {
const arn = 'arn:aws:sns:eu-west-1:123456789876:foo-bar_baz';
expect(validateSnsTopicArn(arn)).toEqual(true);
});

test('AWS China partition', () => {
const arn = 'arn:aws-cn:sns:cn-northwest-1:123456789876:foo-bar';
expect(validateSnsTopicArn(arn)).toEqual(true);
});
});

Loading