2

I deployed an AWS Lambda Function which triggers on S3 bucket event creation using Chalice, but the lambda function is not triggered when I upload an object to the S3 bucket. The Cloudwatch logs and metrics don't show any data.

The code is as follows:

from chalice import Chalice
import boto3

app = Chalice(app_name='ChaliceLambdaTest1')
app.debug = True    #Set the debug mode

s3 = boto3.client('s3')

@app.on_s3_event(bucket='chalicetestbucket1', events=['s3:ObjectCreated:*']) #Sample S3 bucket name

def handler(event):
    print("Object uploaded for bucket: %s, key: %s"
          % (event.bucket, event.key))
    print("Lamba triggered due to S3 event")
    app.log.debug("Lambda function triggered due to S3 event")

The requirements.txt file is as follows:

boto3

I also observed that the code is not there in the Function code section under the Configuration tab in the Lambda function management console.

  • Your code works fine on my end. Are you sure that you'd deployed the code properly? Let me ask couple of things. Have you updated the lambda function's role in IAM section? – Perfect Apr 20 '20 at 09:23
  • Yes, I have done the same. Is it something with the requirements.txt file because I tried again by deploying with an empty requirements.txt file, and the code is displayed in the lambda configuration section, and it works fine now? – YellowKing0907 Apr 23 '20 at 12:50
  • I don't think that the `requirements.txt` file was the reason because `chalice` upload compiled package on your local. So if you had proper dependencies on your local and `chalice deploy` worked, it should be fine. – Perfect Apr 23 '20 at 13:18
  • I wonder why you are creating s3 boot client, I believe you don't need it for this to work. also, you are not using it in the code. try to remove it and also from requirement.txt and try again. – me2resh Apr 25 '20 at 23:37
  • `chalice deploy` worked fine but still, I wasn't able to see any code in the Lambda configuration section in the management console. I followed the exact same procedure as mentioned in their official documentation. I don't think so creating an s3 boot client should lead to issues since the deploy operation works fine but the Lambda doesn't get triggered itself on event creation in S3. – YellowKing0907 Apr 27 '20 at 18:39

0 Answers0