Skip to content

About Lambda UI integration with S3

0

Hi,

I've developed a simple demo of Lambda Function being triggered by a file uploaded to an S3 Bucket. Everything work well, however, in the Lambda UI S3 doesn't appear as trigger

This is my SAM file

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Simple lambda function triggered by a file uploaded to a S3 container

Resources:

  S3Storage:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: 
        Fn::Sub: "${AWS::StackName}-bucket"

  ListenerFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: src/
      Handler: app.lambda_handler
      Runtime: python3.11
      FunctionName: s3-listener
      Events:
        S3Event:
          Type: S3
          Properties:
            Bucket: 
              Ref: S3Storage
            Events: 
              - s3:ObjectCreated:*
      Policies: 
        - S3ReadPolicy:
            BucketName: 
              Fn::Sub: "${AWS::StackName}-bucket"

And the Lambda Designer UI

Enter image description here

I realized that the template in Lambda UI designer is different from the one deployed via SAM CLI

# This AWS SAM template has been generated from your function's configuration. If
# your function has one or more triggers, note that the AWS resources associated
# with these triggers aren't fully specified in this template and include
# placeholder values. Open this template in AWS Application Composer or your
# favorite IDE and modify it to specify a serverless application with other AWS
# resources.
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Application Model template describing your function.
Resources:
  s3listener:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Description: ''
      MemorySize: 128
      Timeout: 3
      Handler: app.lambda_handler
      Runtime: python3.11
      Architectures:
        - x86_64
      EphemeralStorage:
        Size: 512
      EventInvokeConfig:
        MaximumEventAgeInSeconds: 21600
        MaximumRetryAttempts: 2
      PackageType: Zip
      Policies:
        - Statement:
            - Action:
                - s3:GetObject
                - s3:ListBucket
                - s3:GetBucketLocation
                - s3:GetObjectVersion
                - s3:GetLifecycleConfiguration
              Resource:
                - arn:aws:s3:::s3-triggers-lambda-bucket
                - arn:aws:s3:::s3-triggers-lambda-bucket/*
              Effect: Allow
            - Effect: Allow
              Action:
                - logs:CreateLogGroup
                - logs:CreateLogStream
                - logs:PutLogEvents
              Resource: '*'
      SnapStart:
        ApplyOn: None
      Tags:
        lambda:createdBy: SAM
      RuntimeManagementConfig:
        UpdateRuntimeOn: Auto

Can you help me please understand what is happening? Kinesis triggers and others do appear in the UI

Regards

Jona

4 Answers
1

Hello,

I tested this serverless pattern, S3 to Lambda in my aws account. https://serverlessland.com/patterns/s3-lambda

I observed a similar pattern and don't see the trigger in the Lambda console.

But I can confirm that in my S3 bucket event notification is configured to send a notification when specific events occur to Lambda. Notifications was working without issues and triggered the lambda function.

Enter image description here

EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
0

As I mentioned in a comment above, the local template is fine. When I deployed, its like the event source mapping dissapeared.

Sivaraman Selvam, can you check the template of you SAM App on the Lambda UI if you have the event source mapping?

Regards

answered 2 years ago
  • Hi,

    I don't see the S3 event source mapping in the Lambda console, but the Lambda function is triggered when I upload an object. You can see in my screenshot that I have an event notification configured in my S3 bucket to trigger the Lambda function.

  • I have the very same ... So, you don't know why this is happening?

    Regards

0

Just walking around here to see if somebody has a kind of answer .. Could I raise a ticket about this?

Regards

answered 2 years ago
-1

you need to include the appropriate event source mapping within your AWS SAM (Serverless Application Model) template. The current SAM template lacks the configuration that links the S3 bucket to the Lambda function as an event source.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: An AWS Serverless Application Model template describing your function.
Resources:
  s3listener:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Description: ''
      MemorySize: 128
      Timeout: 3
      Handler: app.lambda_handler
      Runtime: python3.11
      Architectures:
        - x86_64
      EphemeralStorage:
        Size: 512
      EventInvokeConfig:
        MaximumEventAgeInSeconds: 21600
        MaximumRetryAttempts: 2
      PackageType: Zip
      Policies:
        - Statement:
            - Action:
                - s3:GetObject
                - s3:ListBucket
                - s3:GetBucketLocation
                - s3:GetObjectVersion
                - s3:GetLifecycleConfiguration
              Resource:
                - arn:aws:s3:::s3-triggers-lambda-bucket
                - arn:aws:s3:::s3-triggers-lambda-bucket/*
              Effect: Allow
            - Effect: Allow
              Action:
                - logs:CreateLogGroup
                - logs:CreateLogStream
                - logs:PutLogEvents
              Resource: '*'
      SnapStart:
        ApplyOn: None
      Tags:
        lambda:createdBy: SAM
      RuntimeManagementConfig:
        UpdateRuntimeOn: Auto
      Events:
        S3UploadEvent:
          Type: S3
          Properties:
            Bucket: s3-triggers-lambda-bucket
            Events: s3:ObjectCreated:*

answered 2 years ago
  • You can see in my original post that my template has the event mapping just right here. However, when deployed, the event mapping dissapeared in the template that you can find in the Lambda UI designer.

    Regards

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.