简体   繁体   English

通过 S3 和 SQS 事件触发消息传递变量值

[英]Passing variable values through S3 and SQS event trigger message

I have setup the aws pipeline as S3 -> SQS -> Lambda.我已将 aws 管道设置为 S3 -> SQS -> Lambda。 S3 PutObject event will generate an event trigger message and pass it to SQS and SQS will trigger the lambda. S3 PutObject 事件将生成事件触发消息并将其传递给 SQS,SQS 将触发 lambda。 I have a requirement to pass a variable value from S3 to SQS and finally to Lambda as part of the event message.我需要将变量值从 S3 传递到 SQS,最后传递到 Lambda 作为事件消息的一部分。 Variable value could be the file name or some string value.变量值可以是文件名或某个字符串值。

  1. can we customize the event message json data generated by S3 event to pass some more information along with the message.我们可以自定义 S3 事件生成的事件消息 json 数据,以便与消息一起传递更多信息。
  2. Does SQS just pass the event message received from S3 to Lambda or does any alteration to the message or generate its own message. SQS 是否只是将从 S3 收到的事件消息传递给 Lambda 或对消息进行任何更改或生成自己的消息。
  3. how to display or see the message generated by S3 in SQS or Lambda.如何在 SQS 或 Lambda 中显示或查看 S3 生成的消息。

You can't manipulate the S3 event data.您无法操纵 S3 事件数据。 The schema looks like this .架构看起来像这样 That will be passed onto the SQS Queue which will add some it's own metadata and pass it along to Lambda.这将被传递到 SQS 队列,该队列将添加一些它自己的元数据并将其传递给 Lambda。 This tutorial has a sample SQS record. 本教程有一个示例 SQS 记录。

When Amazon S3 triggers an event, a message is sent to the desired destination (AWS Lambda, Amazon SNS, Amazon SQS).当 Amazon S3 触发事件时,会向所需目标(AWS Lambda、Amazon SNS、Amazon SQS)发送一条消息。 The message includes the bucket name and key (filename) of the object that triggered the event.该消息包括触发事件的 object 的存储桶名称和密钥(文件名)

Here is a sample event (from Using AWS Lambda with Amazon S3 - AWS Lambda ):这是一个示例事件(来自将 AWS Lambda 与 Amazon S3 - AWS Lambda 一起使用):

{
  "Records": [
    {
      "eventVersion": "2.1",
      "eventSource": "aws:s3",
      "awsRegion": "us-east-2",
      "eventTime": "2019-09-03T19:37:27.192Z",
      "eventName": "ObjectCreated:Put",
      "userIdentity": {
        "principalId": "AWS:AIDAINPONIXQXHT3IKHL2"
      },
      "requestParameters": {
        "sourceIPAddress": "205.255.255.255"
      },
      "responseElements": {
        "x-amz-request-id": "D82B88E5F771F645",
        "x-amz-id-2": "vlR7PnpV2Ce81l0PRw6jlUpck7Jo5ZsQjryTjKlc5aLWGVHPZLj5NeC6qMa0emYBDXOo6QBU0Wo="
      },
      "s3": {
        "s3SchemaVersion": "1.0",
        "configurationId": "828aa6fc-f7b5-4305-8584-487c791949c1",
        "bucket": {
          "name": "lambda-artifacts-deafc19498e3f2df",
          "ownerIdentity": {
            "principalId": "A3I5XTEXAMAI3E"
          },
          "arn": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df"
        },
        "object": {
          "key": "b21b84d653bb07b05b1e6b33684dc11b",
          "size": 1305107,
          "eTag": "b21b84d653bb07b05b1e6b33684dc11b",
          "sequencer": "0C0F6F405D6ED209E1"
        }
      }
    }
  ]
}

The bucket can be obtained from Records[].s3.bucket.name and the key can be obtained from Records[].s3.object.key .桶可以从Records[].s3.bucket.name ,key 可以从Records[].s3.object.key

However, there is no capability to send a particular value, since S3 triggers the event.但是,由于 S3 触发事件,因此无法发送特定值。 However, you could possibly derive a value.但是,您可能会得出一个值。 For example, if you had events from several different buckets triggering the Lambda function, then the Lambda function could look at the bucket name to determine why it was triggered, and then substitute a desired value. For example, if you had events from several different buckets triggering the Lambda function, then the Lambda function could look at the bucket name to determine why it was triggered, and then substitute a desired value.

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

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