What is the format of AWS::Events::Rule to kick off a Lambda function when a file comes into an S3 bucket folder?

1

What is needed in the template to create a rule to kick off a lambda function when a file comes in to an S3 bucket. I know the details to S3 bucket and Lambda function / ARN are needed but not sure what the syntax of some of the details are. I've included some questions and what I extrapolated from the example in the documentation (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern) but unsure how it ties to the Lambda function and built into the CodePipeline. Is it: S3 bucket, S3 Code deploy, Lambda function, Event trigger, Glue Job?

Type: AWS::Events::Rule Properties:

Description: String

EventBusName: ?

EventPattern: ? # syntax needed here:

           +  prefix   (prefix of the folder path)
                                       
           +  suffix   (file type .parquet)

Name: String

RoleArn: # ARN to the role we are using which needs permissions to kick off lambda

State: Enabled

Targets:

- Target  :                #target of the lambda function (ARN and Id)
AllMur
asked 10 months ago367 views
2 Answers
0

You need to provide JSON EventBridge Event pattern:

{
    "source": [  "aws.s3" ],
    "detail-type": [  "Object Created" ],
    "detail": {
        "bucket": {
            "name": [ "yourbucketname" ]
        }    
  }
}

By the way you can trigger Lambda directly from S3 Events -> Lambda https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

profile picture
EXPERT
answered 10 months ago
profile picture
EXPERT
reviewed 10 months ago
  • Is this in addition to AWS::Events::Rule ?

0

In CloudFormation syntax it will be like this:

  YourEventRule:
    Type: AWS::Events::Rule
    Properties:
      EventPattern:
        source:
          - aws.s3
        detail-type:
          - 'Object Created'
        detail:
          bucket:
             name:
               - 'yourbucketname'
profile picture
EXPERT
answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions