简体   繁体   English

AWS Lambda:从S3上传事件中读取图像

[英]AWS Lambda : read image from S3 upload event

I am using Lambda to read image files when they are uploaded to S3 through a S3 trigger. 当通过S3触发器将图像文件上传到S3时,我正在使用Lambda读取图像文件。 The following is my code: 以下是我的代码:

import json
import numpy as np
import face_recognition as fr

def lambda_handler(event, context):
    for record in event['Records']:
        bucket=record['s3']['bucket']['name']
        key = record['s3']['object']['key']
        print(bucket,key)

This correctly prints the bucket name and key. 这样可以正确打印存储桶名称和密钥。 However how do I read the image so that I can run face-recognition module on the image. 但是,我如何读取图像,以便可以在图像上运行人脸识别模块。 Can i generate the arn for each uploaded image and use it to read the same? 我可以为每个上传的图像生成arn并使用它读取相同的图像吗?

You can read the image from S3 directly: 您可以直接从S3中读取图像:

s3 = boto3.client('s3')
resp = s3.get_object(Bucket=bucket, Key=key)
image_bytes = resp['Body'].read()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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