简体   繁体   中英

Using Event Data from S3 Trigger in AWS Lambda

I'm trying to craft a Lambda function using event data from an S3 trigger I have setup on a bucket. My first function works as expected and prints the event data. However, when I try and pull that event data into the next function the bucket name does not print which is what I expected. What am I missing here? Can I not pull event data into other functions to grab pieces of it?

import boto3

s3 = boto3.client("s3")

def lambda_handler(event, context):
    s3_upload_record = event
    print(s3_upload_record)
    
def print_bucket_name(s3_upload_record):
    bucket_name = s3_upload_record["Records"][0]["s3"]["bucket"]["name"]
    print(bucket_name)

Your function print_bucket_name is not called at all. I think you should be using:

def lambda_handler(event, context):
    s3_upload_record = event
    print_bucket_name(s3_upload_record)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM