diff --git a/packages/aws-cdk-lib/.eslintrc.js b/packages/aws-cdk-lib/.eslintrc.js index 9445191d72613..62575606834de 100644 --- a/packages/aws-cdk-lib/.eslintrc.js +++ b/packages/aws-cdk-lib/.eslintrc.js @@ -30,7 +30,6 @@ const noThrowDefaultErrorNotYetSupported = [ 'aws-scheduler', 'aws-secretsmanager', 'aws-servicecatalog', - 'aws-sns-subscriptions', 'core', 'custom-resources', 'region-info', diff --git a/packages/aws-cdk-lib/aws-sns-subscriptions/lib/lambda.ts b/packages/aws-cdk-lib/aws-sns-subscriptions/lib/lambda.ts index 834690cdf1a45..69acf2a9bafe1 100644 --- a/packages/aws-cdk-lib/aws-sns-subscriptions/lib/lambda.ts +++ b/packages/aws-cdk-lib/aws-sns-subscriptions/lib/lambda.ts @@ -3,7 +3,7 @@ import { SubscriptionProps } from './subscription'; import * as iam from '../../aws-iam'; import * as lambda from '../../aws-lambda'; import * as sns from '../../aws-sns'; -import { ArnFormat, Names, Stack, Token } from '../../core'; +import { ArnFormat, Names, Stack, Token, ValidationError } from '../../core'; /** * Properties for a Lambda subscription @@ -25,7 +25,7 @@ export class LambdaSubscription implements sns.ITopicSubscription { // Create subscription under *consuming* construct to make sure it ends up // in the correct stack in cases of cross-stack subscriptions. if (!Construct.isConstruct(this.fn)) { - throw new Error('The supplied lambda Function object must be an instance of Construct'); + throw new ValidationError('The supplied lambda Function object must be an instance of Construct', topic); } this.fn.addPermission(`AllowInvoke:${Names.nodeUniqueId(topic.node)}`, { diff --git a/packages/aws-cdk-lib/aws-sns-subscriptions/lib/sqs.ts b/packages/aws-cdk-lib/aws-sns-subscriptions/lib/sqs.ts index f713fe6bb6ead..c79641892d403 100644 --- a/packages/aws-cdk-lib/aws-sns-subscriptions/lib/sqs.ts +++ b/packages/aws-cdk-lib/aws-sns-subscriptions/lib/sqs.ts @@ -3,7 +3,7 @@ import { SubscriptionProps } from './subscription'; import * as iam from '../../aws-iam'; import * as sns from '../../aws-sns'; import * as sqs from '../../aws-sqs'; -import { ArnFormat, FeatureFlags, Names, Stack, Token } from '../../core'; +import { ArnFormat, FeatureFlags, Names, Stack, Token, ValidationError } from '../../core'; import * as cxapi from '../../cx-api'; /** @@ -34,20 +34,20 @@ export class SqsSubscription implements sns.ITopicSubscription { // Create subscription under *consuming* construct to make sure it ends up // in the correct stack in cases of cross-stack subscriptions. if (!Construct.isConstruct(this.queue)) { - throw new Error('The supplied Queue object must be an instance of Construct'); + throw new ValidationError('The supplied Queue object must be an instance of Construct', topic); } const snsServicePrincipal = new iam.ServicePrincipal('sns.amazonaws.com'); // if the queue is encrypted by AWS managed KMS key (alias/aws/sqs), // throw error message if (this.queue.encryptionType === sqs.QueueEncryption.KMS_MANAGED) { - throw new Error('SQS queue encrypted by AWS managed KMS key cannot be used as SNS subscription'); + throw new ValidationError('SQS queue encrypted by AWS managed KMS key cannot be used as SNS subscription', topic); } // if the dead-letter queue is encrypted by AWS managed KMS key (alias/aws/sqs), // throw error message if (this.props.deadLetterQueue && this.props.deadLetterQueue.encryptionType === sqs.QueueEncryption.KMS_MANAGED) { - throw new Error('SQS queue encrypted by AWS managed KMS key cannot be used as dead-letter queue'); + throw new ValidationError('SQS queue encrypted by AWS managed KMS key cannot be used as dead-letter queue', topic); } // add a statement to the queue resource policy which allows this topic diff --git a/packages/aws-cdk-lib/aws-sns-subscriptions/lib/url.ts b/packages/aws-cdk-lib/aws-sns-subscriptions/lib/url.ts index f812611b6aaef..bce9372df3a46 100644 --- a/packages/aws-cdk-lib/aws-sns-subscriptions/lib/url.ts +++ b/packages/aws-cdk-lib/aws-sns-subscriptions/lib/url.ts @@ -1,6 +1,6 @@ import { SubscriptionProps } from './subscription'; import * as sns from '../../aws-sns'; -import { Token } from '../../core'; +import { Token, UnscopedValidationError } from '../../core'; /** * Options for URL subscriptions. @@ -49,11 +49,11 @@ export class UrlSubscription implements sns.ITopicSubscription { constructor(private readonly url: string, private readonly props: UrlSubscriptionProps = {}) { this.unresolvedUrl = Token.isUnresolved(url); if (!this.unresolvedUrl && !url.startsWith('http://') && !url.startsWith('https://')) { - throw new Error('URL must start with either http:// or https://'); + throw new UnscopedValidationError('URL must start with either http:// or https://'); } if (this.unresolvedUrl && props.protocol === undefined) { - throw new Error('Must provide protocol if url is unresolved'); + throw new UnscopedValidationError('Must provide protocol if url is unresolved'); } if (this.unresolvedUrl) {