Ronaldo Lanhellas
Ronaldo Lanhellas

Reputation: 3336

AWS::S3::Bucket LambdaConfiguration in multiple AWS Lambdas

I have 4 AWS Lambdas that should read S3 bucket when some file is created (S3 Event), but in cloudformation I just can use 1 Lambda ARN, see inside AWS::S3::Bucket LambdaConfiguration:

enter image description here

How can I trigger more than 1 Lambda in Bucket Lambda Configuration ?

Upvotes: 3

Views: 277

Answers (3)

matsev
matsev

Reputation: 33779

AWS recently announced S3 Event Notifications with Amazon EventBridge. Consequently, you can enable EventBridge notification on your bucket and then have one (or more) Lambda function(s) triggered by those events.

Example implementation using AWS SAM:

AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: 'S3 EventBridge Example'

Parameters:
  BucketName:
    Type: String
    Description: 'Name of the bucket to be created'

Resources:

  S3Bucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref BucketName
      NotificationConfiguration:
        EventBridgeConfiguration:
          EventBridgeEnabled: true

  S3EventProcessor:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: S3EventListener
      Architectures:
        - arm64
      Runtime: nodejs14.x
      Handler: index.handler
      InlineCode: |
        exports.handler = (event, context) => {
          console.log('event:', JSON.stringify(event));
        }
      Events:
        S3EventBridgeRule:
          Type: EventBridgeRule
          Properties:
            Pattern:
              source:
                - aws.s3
              detail:
                bucket:
                  name:
                    - !Ref BucketName

Upvotes: 2

A Ralkov
A Ralkov

Reputation: 1044

I think Step functions is exactly what you want. Also S3-related tutorial can be useful

Upvotes: 1

luk2302
luk2302

Reputation: 57134

S3 does not offer this kind of fan-out out-of-the-box but only through e.g. SNS.
You need to push the notification into a SNS topic instead of a lambda and then either

  • subscribe four lambdas to that topic or
  • subscribe four queues to the topic and let each lambda "subscribe" to one queue

Upvotes: 2

Related Questions