aws lambda 函数处理程序 python

aws lambda function handler python

我是 AWS 的新手,我正在尝试编写一个函数,只要在 s3 存储桶中创建了一个新对象,rekognition 就会开始分析。我查看了 lambda 函数处理程序 (python) 的 AWS 文档,它给出了处理的一般语法结构,但是我应该使用什么运算符来调用 s3 存储桶中的新对象的名称?我几乎找不到任何东西,任何人都可以帮忙吗?非常感谢

import boto3

client = boto3.client('rekognition')
s3 = boto3.resource('s3')
bucket = s3.bucket('my_bucket')
for obj in bucket.object.all():
    print(obj.key)

def my_handler(event,context):
    income_Name = event.***** # not sure what operator here?


    response = client.search_faces_by_image(
        CollectionId='my_collection',
        Image={
           #'Bytes': b'bytes',
           'S3Object': {
              'Bucket': 'my_bucket',
              'Name': income_name,

        },
        MaxFaces=123,
        FaceMatchThreshold=70
    )
    return response[]

这是 Lambda 接收到的 S3 事件的综合描述。

https://docs.aws.amazon.com/AmazonS3/latest/dev/notification-content-structure.html

确保您已正确配置 Lambda 函数以由 S3 事件触发。然后您可以解码从 S3 发送到 Lambda 的通知消息以获取您需要的值。

示例:s3_key = 事件['Records'][0]['s3']['object']['key']