简体   繁体   English

使用Python处理Lambda中的S3 Bucket Trigger事件

[英]Handling S3 Bucket Trigger Event in Lambda Using Python

The AWS Lambda handler has a signature of AWS Lambda处理程序具有签名

def lambda_handler(event, context):

However, I cannot find any documentation as to the event's structure when the trigger is an S3 Bucket receiving a put 但是,当触发器是S3 Bucket接收put时,我找不到有关事件结构的任何文档

I thought that it might be defined in the s3 console, but couldn't find that there. 我认为它可能在s3控制台中定义,但在那里找不到。

Anyone have any leads? 有人有任何线索吗?

The event from S3 to Lambda function will be in json format as shown below, 从S3到Lambda函数的事件将采用json格式,如下所示,

{  
   "Records":[  
      {  
         "eventVersion":"2.0",
         "eventSource":"aws:s3",
         "awsRegion":"us-east-1",
         "eventTime":The time, in ISO-8601 format, for example, 1970-01-01T00:00:00.000Z, when S3 finished processing the request,
         "eventName":"event-type",
         "userIdentity":{  
            "principalId":"Amazon-customer-ID-of-the-user-who-caused-the-event"
         },
         "requestParameters":{  
            "sourceIPAddress":"ip-address-where-request-came-from"
         },
         "responseElements":{  
            "x-amz-request-id":"Amazon S3 generated request ID",
            "x-amz-id-2":"Amazon S3 host that processed the request"
         },
         "s3":{  
            "s3SchemaVersion":"1.0",
            "configurationId":"ID found in the bucket notification configuration",
            "bucket":{  
               "name":"bucket-name",
               "ownerIdentity":{  
                  "principalId":"Amazon-customer-ID-of-the-bucket-owner"
               },
               "arn":"bucket-ARN"
            },
            "object":{  
               "key":"object-key",
               "size":object-size,
               "eTag":"object eTag",
               "versionId":"object version if bucket is versioning-enabled, otherwise null",
               "sequencer": "a string representation of a hexadecimal value used to determine event sequence, 
                   only used with PUTs and DELETEs"            
            }
         }
      },
      {
          // Additional events
      }
   ]
}

here is the link for aws documentation which can guide you. 这是aws文档的链接,可以指导您。 http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html

I think your easiest route is just to experiment quickly: 我认为您最简单的方法就是快速实验:

  1. Create a bucket using the console 使用控制台创建存储桶
  2. Create a lambda that is triggered by puts to the bucket using the console 使用控制台创建由put放入存储区触发的lambda
  3. Ensure you choose the default execution role, so you create cloudwatch logs 确保选择默认执行角色,以便创建cloudwatch日志
  4. The lambda function just needs to "print(event)" when called, which is then logged lambda函数在调用时只需要“print(event)”,然后记录
  5. Save an object to the bucket 将对象保存到存储桶

You'll then see the event structure in the log - its pretty self explanatory. 然后,您将在日志中看到事件结构 - 它非常自我解释。

暂无
暂无

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

相关问题 python cdk 在 s3 存储桶上创建 lambda 触发器 - python cdk to create lambda trigger on s3 bucket AWS Lambda 使用 python 读取 S3 存储桶中的文件 - AWS Lambda read a file in the S3 bucket using python 在 AWS Lambda 中使用来自 S3 触发器的事件数据 - Using Event Data from S3 Trigger in AWS Lambda 当新对象到达S3存储桶时触发Lambda函数 - Trigger Lambda function when a new object arrives in S3 bucket AWS Lambda和S3和Pandas-将CSV加载到S3中,触发Lambda,加载到pandas,放回存储桶中? - AWS Lambda and S3 and Pandas - Load CSV into S3, trigger Lambda, load into pandas, put back in bucket? 如何使用事件触发的lambda从S3存储桶获取最新的文件名或文件 - How to get latest file-name or file from S3 bucket using event triggered lambda AWS Lambda:使用Python从s3存储桶中读取csv文件尺寸,而无需使用Pandas或CSV包 - AWS Lambda: read csv file dimensions from an s3 bucket with Python without using Pandas or CSV package Aws 使用 lambda python 将数据从一个 S3 存储桶复制到同一帐户上的另一个存储桶 - Aws copy data from one S3 bucket to another on same account using lambda python 从 AWS lambda function 中的 s3 存储桶中读取 .mdb 或 .accdb 文件并使用 python 将其转换为 excel 或 csv - Reading .mdb or .accdb file from s3 bucket in AWS lambda function and converting it into excel or csv using python 如何使用 lambda(python) 从 s3 存储桶将 xml 文件导出到 oracle 数据库中的表中 - how to export xml file from a s3 bucket using lambda(python) into tables in an oracle database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM