简体   繁体   English

AWS Lambda函数处理程序python

[英]aws lambda function handler python

I am new to AWS, im trying to write a function whenever there is a new object created in s3 bucket, rekognition will start analysis. 我是AWS的新手,我试图在s3存储桶中创建新对象时编写函数,重新识别将开始分析。 I looked at AWS documentation for lambda function handler(python), it gives a general syntax structure for handling, but what operators should I use to call the name of new object in s3 bucket? 我查看了有关lambda函数处理程序(python)的AWS文档,它提供了用于处理的常规语法结构,但是在s3存储桶中应使用哪些运算符来调用新对象的名称? I hardly find any, can anyone please help? 我几乎找不到任何东西,有人可以帮忙吗? thank you so much 非常感谢

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[]

Here is a comprehensive description of the S3 event that is received by Lambda. 这是Lambda收到的S3事件的全面描述。

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

Make sure that you have properly configured the Lambda function to be triggered by an S3 event. 确保已正确配置Lambda函数以由S3事件触发。 Then you can decode the notification message sent from S3 to Lambda to get the values you need. 然后,您可以解码从S3发送到Lambda的通知消息,以获取所需的值。

example : s3_key = event['Records'][0]['s3']['object']['key'] 例如:s3_key = event ['Records'] [0] ['s3'] ['object'] ['key']

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

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