Skip to content

Instantly share code, notes, and snippets.

Last active June 5, 2023 18:34
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
AWS CDK sample with Existing S3 bucket and existing SNS topic
import core = require("@aws-cdk/core");
import lambda = require("@aws-cdk/aws-lambda");
import s3 = require("@aws-cdk/aws-s3");
import sns = require("@aws-cdk/aws-sns");
import sqs = require("@aws-cdk/aws-sqs");
import { SqsEventSource } from "@aws-cdk/aws-lambda-event-sources";
import { SqsSubscription } from "@aws-cdk/aws-sns-subscriptions";
export class ExistingS3BucketAndSNSTopicToLambdaThroughSQS extends core.Construct {
constructor(scope: core.Construct, id: string) {
super(scope, id);
const bucket = s3.Bucket.fromBucketName(
const handler = new lambda.Function(this, "lambda", {
runtime: lambda.Runtime.NODEJS_10_X,
code: lambda.Code.asset("lambda/dist"),
handler: "index.main",
timeout: core.Duration.seconds(30),
environment: {
BUCKET_NAME: bucket.bucketName
const topic = sns.Topic.fromTopicArn(
const queue = new sqs.Queue(this, "queue");
topic.addSubscription(new SqsSubscription(queue));
new SqsEventSource(queue, {
batchSize: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment