How to use @aws-cdk/aws-sns - 10 common examples

To help you get started, we’ve selected a few @aws-cdk/aws-sns examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-cdk / packages / aws-cdk / integ-tests / app / app.js View on Github external
constructor(parent, id, providingStack) {
    super(parent, id);


    new sns.Topic(this, 'BogusTopic');  // Some filler
    new cdk.Output(this, 'IConsumedSomething', { value: providingStack.stackName });
  }
}
github aws / aws-cdk / packages / aws-cdk / integ-tests / app / app.js View on Github external
constructor(parent, id) {
    super(parent, id);

    new sns.Topic(this, 'BogusTopic'); // Some filler
  }
}
github daviddeejjames / send-that-invoice / lib / send-that-invoice-stack.ts View on Github external
environment: {
          DATA_BUCKET: `${bucket.bucketName}`,
          MAIL_NAME: `${mailName}`,
          MAIL_USER: `${mailUser}`,
          MAIL_PASS: `${mailPass}`,
          MAIL_HOST: `${mailHost}`,
          MAIL_PORT: `${mailPort}`,
          MAIL_REPLY_TO: `${mailReplyTo}`,
          DROPBOX_TOKEN: `${dropboxToken}`,
          SNS_TOPIC_ARN: `${snsTopicArn}`,
          SENTRY_DSN: `${sentryDsn}`
        }
      });

      bucket.grantReadWrite(lambdaFn);
      const snsTopic = Topic.fromTopicArn(
        this,
        'SendThatInvoice',
        `${snsTopicArn}`
      );
      snsTopic.grantPublish(lambdaFn);

      // Run every day at 6PM UTC
      // See https://docs.aws.amazon.com/lambda/latest/dg/tutorial-scheduled-events-schedule-expressions.html
      const rule = new events.Rule(this, 'send-that-invoice-cron-rule', {
        schedule: events.Schedule.expression('rate(4 hours)')
      });

      rule.addTarget(new targets.LambdaFunction(lambdaFn));
    } else {
      console.error(
        'It seems you haven\'t set one of your ENV vars correctly, please check below'
github deepalert / deepalert / lib / deepalert-stack.ts View on Github external
? iam.Role.fromRoleArn(this, "SfnRole", props.sfnRoleARN, {
          mutable: false,
        })
      : undefined;

    this.cacheTable = new dynamodb.Table(this, "cacheTable", {
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
      partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
      sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
      timeToLiveAttribute: "expires_at",
    });

    // ----------------------------------------------------------------
    // Messaging Channels
    this.alertTopic = new sns.Topic(this, "alertTopic");
    this.taskTopic = new sns.Topic(this, "taskTopic");
    this.contentTopic = new sns.Topic(this, "contentTopic");
    this.attributeTopic = new sns.Topic(this, "attributeTopic");
    this.reportTopic = new sns.Topic(this, "reportTopic");

    const alertQueueTimeout = cdk.Duration.seconds(30);
    this.alertQueue = new sqs.Queue(this, "alertQueue", {
      visibilityTimeout: alertQueueTimeout,
    });
    this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));

    const contentQueueTimeout = cdk.Duration.seconds(30);
    this.contentQueue = new sqs.Queue(this, "contentQueue", {
      visibilityTimeout: contentQueueTimeout,
    });

    const attributeQueueTimeout = cdk.Duration.seconds(30);
github deepalert / deepalert / lib / deepalert-stack.ts View on Github external
})
      : undefined;

    this.cacheTable = new dynamodb.Table(this, "cacheTable", {
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
      partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
      sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
      timeToLiveAttribute: "expires_at",
    });

    // ----------------------------------------------------------------
    // Messaging Channels
    this.alertTopic = new sns.Topic(this, "alertTopic");
    this.taskTopic = new sns.Topic(this, "taskTopic");
    this.contentTopic = new sns.Topic(this, "contentTopic");
    this.attributeTopic = new sns.Topic(this, "attributeTopic");
    this.reportTopic = new sns.Topic(this, "reportTopic");

    const alertQueueTimeout = cdk.Duration.seconds(30);
    this.alertQueue = new sqs.Queue(this, "alertQueue", {
      visibilityTimeout: alertQueueTimeout,
    });
    this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));

    const contentQueueTimeout = cdk.Duration.seconds(30);
    this.contentQueue = new sqs.Queue(this, "contentQueue", {
      visibilityTimeout: contentQueueTimeout,
    });

    const attributeQueueTimeout = cdk.Duration.seconds(30);
    this.attributeQueue = new sqs.Queue(this, "attributeQueue", {
      visibilityTimeout: attributeQueueTimeout,
github deepalert / deepalert / lib / deepalert-stack.ts View on Github external
const sfnRole = props.sfnRoleARN
      ? iam.Role.fromRoleArn(this, "SfnRole", props.sfnRoleARN, {
          mutable: false,
        })
      : undefined;

    this.cacheTable = new dynamodb.Table(this, "cacheTable", {
      billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
      partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
      sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
      timeToLiveAttribute: "expires_at",
    });

    // ----------------------------------------------------------------
    // Messaging Channels
    this.alertTopic = new sns.Topic(this, "alertTopic");
    this.taskTopic = new sns.Topic(this, "taskTopic");
    this.contentTopic = new sns.Topic(this, "contentTopic");
    this.attributeTopic = new sns.Topic(this, "attributeTopic");
    this.reportTopic = new sns.Topic(this, "reportTopic");

    const alertQueueTimeout = cdk.Duration.seconds(30);
    this.alertQueue = new sqs.Queue(this, "alertQueue", {
      visibilityTimeout: alertQueueTimeout,
    });
    this.alertTopic.addSubscription(new SqsSubscription(this.alertQueue));

    const contentQueueTimeout = cdk.Duration.seconds(30);
    this.contentQueue = new sqs.Queue(this, "contentQueue", {
      visibilityTimeout: contentQueueTimeout,
    });
github aws-samples / aws-cdk-changelogs-demo / changelogs-md.js View on Github external
const apiBucket = new s3.Bucket(this, 'api-bucket', {
      publicReadAccess: true,
      websiteIndexDocument: 'index.json'
    });

    // An S3 bucket which holds the static content
    const staticBucket = new s3.Bucket(this, 'static-bucket', {
      publicReadAccess: true,
      websiteIndexDocument: 'index.html'
    });

    // Create an ECS cluster
    const cluster = new ecs.Cluster(this, 'Cluster', { vpc });

    // An SNS topic to which we can publish to trigger the crawl of a changelog
    const toCrawlTopic = new sns.Topic(this, 'to-crawl', {
      displayName: 'Changelog to crawl'
    });

    const redisCluster = new redis.Cluster(this, 'redis', { vpc });

    this.vpc = vpc;
    this.changelogsTable = changelogsTable;
    this.feedsTable = feedsTable;
    this.searchIndexTable = searchIndexTable;
    this.webBucket = webBucket;
    this.apiBucket = apiBucket;
    this.staticBucket = staticBucket;
    this.toCrawlTopic = toCrawlTopic;
    this.cluster = cluster;
    this.redis = redisCluster;
  }
github aws / aws-cdk / packages / @aws-cdk / aws-sns-subscriptions / lib / url.ts View on Github external
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://');
    }

    if (this.unresolvedUrl && props.protocol === undefined) {
      throw new Error('Must provide protocol if url is unresolved');
    }

    if (this.unresolvedUrl) {
      this.protocol = props.protocol!;
    } else {
      this.protocol = this.url.startsWith('https:') ? sns.SubscriptionProtocol.HTTPS : sns.SubscriptionProtocol.HTTP;
    }
  }
github aws / aws-cdk / packages / @aws-cdk / aws-sns-subscriptions / lib / lambda.ts View on Github external
// 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`);
    }

    this.fn.addPermission(`AllowInvoke:${topic.node.uniqueId}`, {
      sourceArn: topic.topicArn,
      principal: new iam.ServicePrincipal('sns.amazonaws.com'),
    });

    return {
      subscriberScope: this.fn,
      subscriberId: topic.node.id,
      endpoint: this.fn.functionArn,
      protocol: sns.SubscriptionProtocol.LAMBDA,
      filterPolicy: this.props.filterPolicy,
    };
  }
}
github aws / aws-cdk / packages / aws-cdk / integ-tests / app / app.js View on Github external
constructor(parent, id) {
    super(parent, id);
    new sns.Topic(this, 'topic1');
    new sns.Topic(this, 'topic2');
  }
}

@aws-cdk/aws-sns

The CDK Construct Library for AWS::SNS

Apache-2.0
Latest version published 1 year ago

Package Health Score

70 / 100
Full package analysis