How to use the @aws-cdk/aws-lambda-event-sources.SnsEventSource function in @aws-cdk/aws-lambda-event-sources

To help you get started, we’ve selected a few @aws-cdk/aws-lambda-event-sources 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-samples / aws-cdk-changelogs-demo / changelogs-md.js View on Github external
environment: {
        GITHUB_CLIENT_ID: githubSecrets.clientId,
        GITHUB_SECRET: githubSecrets.secret,
        CHANGELOGS_TABLE_NAME: props.changelogsTable.tableName,
        FEEDS_TABLE_NAME: props.feedsTable.tableName,
        SEARCH_INDEX_TABLE_NAME: props.searchIndexTable.tableName,
        API_BUCKET_NAME: props.apiBucket.bucketName,
        WEB_BUCKET_NAME: props.webBucket.bucketName,
        REDIS_HOST: props.redis.cluster.attrRedisEndpointAddress,
        REDIS_PORT: props.redis.cluster.attrRedisEndpointPort
      }
    });

    // Attach the lambda to the SNS topic so that when the follower
    // publishes to the SNS topic the Lambda gets invoked.
    const crawlEventSource = new lambdaEvents.SnsEventSource(props.toCrawlTopic);
    crawlLambda.addEventSource(crawlEventSource);

    // Grant the lambda permission to modify the tables
    props.changelogsTable.grantReadWriteData(crawlLambda.role);
    props.feedsTable.grantReadWriteData(crawlLambda.role);
    props.searchIndexTable.grantReadWriteData(crawlLambda.role);

    // Grant the lambda permission to write to the buckets
    props.webBucket.grantReadWrite(crawlLambda.role);
    props.apiBucket.grantReadWrite(crawlLambda.role);

    // Grant the lambda networking access to Redis
    crawlLambda.connections.allowToDefaultPort(props.redis);
  }
}
github aws-samples / amazon-textract-serverless-large-scale-document-processing / textract-pipeline / lib / textract-pipeline-stack.ts View on Github external
SNS_ROLE_ARN : textractServiceRole.roleArn,
        AWS_DATA_PATH : "models"
      }
    });
    //asyncProcessor.addEnvironment("SNS_TOPIC_ARN", textractServiceRole.topicArn)

    //Layer
    asyncProcessor.addLayer(helperLayer)
    //Triggers
    // Run async job processor every 5 minutes
    const rule = new events.EventRule(this, 'Rule', {
      scheduleExpression: 'rate(2 minutes)',
    });
    rule.addTarget(asyncProcessor);
    //Run when a job is successfully complete
    asyncProcessor.addEventSource(new SnsEventSource(jobCompletionTopic))
    //Permissions
    contentBucket.grantRead(asyncProcessor)
    existingContentBucket.grantReadWrite(asyncProcessor)
    asyncJobsQueue.grantConsumeMessages(asyncProcessor)
    asyncProcessor.addToRolePolicy(new iam.PolicyStatement().addResource(textractServiceRole.roleArn).addAction('iam:PassRole'))
    asyncProcessor.addToRolePolicy(new iam.PolicyStatement().addAllResources().addAction("textract:*"))

    //------------------------------------------------------------

    // Async Jobs Results Processor
    const jobResultProcessor = new lambda.Function(this, 'JobResultProcessor', {
      runtime: lambda.Runtime.Python37,
      code: lambda.Code.asset('lambda/jobresultprocessor'),
      handler: 'lambda_function.lambda_handler',
      memorySize: 2000,
      reservedConcurrentExecutions: 50,
github deepalert / deepalert / test / workflow / bin / stack.ts View on Github external
super(scope, id, props);

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

    const buildPath = lambda.Code.fromAsset("./build");

    const testInspector = new lambda.Function(this, "testInspector", {
      runtime: lambda.Runtime.GO_1_X,
      handler: "inspector",
      timeout: cdk.Duration.seconds(30),
      code: buildPath,
      events: [new SnsEventSource(props.deepalert.taskTopic)],
      environment: {
        RESULT_TABLE: table.tableName,
        FINDING_QUEUE: props.deepalert.findingQueue.queueUrl,
        ATTRIBUTE_QUEUE: props.deepalert.attributeQueue.queueUrl,
      },
    });

    const testEmitter = new lambda.Function(this, "testEmitter", {
      runtime: lambda.Runtime.GO_1_X,
      handler: "emitter",
      timeout: cdk.Duration.seconds(30),
      code: buildPath,
      events: [new SnsEventSource(props.deepalert.reportTopic)],
      environment: {
        RESULT_TABLE: table.tableName,
      },
github deepalert / deepalert / test / workflow / bin / stack.ts View on Github external
timeout: cdk.Duration.seconds(30),
      code: buildPath,
      events: [new SnsEventSource(props.deepalert.taskTopic)],
      environment: {
        RESULT_TABLE: table.tableName,
        FINDING_QUEUE: props.deepalert.findingQueue.queueUrl,
        ATTRIBUTE_QUEUE: props.deepalert.attributeQueue.queueUrl,
      },
    });

    const testEmitter = new lambda.Function(this, "testEmitter", {
      runtime: lambda.Runtime.GO_1_X,
      handler: "emitter",
      timeout: cdk.Duration.seconds(30),
      code: buildPath,
      events: [new SnsEventSource(props.deepalert.reportTopic)],
      environment: {
        RESULT_TABLE: table.tableName,
      },
    });

    table.grantReadWriteData(testInspector);
    table.grantReadWriteData(testEmitter);
    props.deepalert.findingQueue.grantSendMessages(testInspector);
    props.deepalert.attributeQueue.grantSendMessages(testInspector);
  }
}
github PinkyJie / aws-transcribe-demo / aws-cdk / lib / lambda.ts View on Github external
...commonRuntimeProps,
                description:
                    'Function to transcribe audio to text using Amazon Transcribe.',
                handler: 'transcribeAudio.handler',
                code: lambda.Code.asset(
                    `${LAMBDA_FUNCTIONS_DIST_FOLDER}/transcribeAudio`
                ),
                environment: {
                    ...commonEnv,
                    OUTPUT_BUCKET_NAME:
                        props.transcribedTextFileBucket.bucketName,
                },
            }
        );
        this.transcribeAudioFunc.addEventSource(
            new SnsEventSource(props.newAudioTopic)
        );
    }