简体   繁体   English

调用时获取触发lambda的触发器

[英]Get the trigger that invoked the lambda when it is invoked

I have an AWS lambda with multiple triggers.我有一个带有多个触发器的 AWS lambda。 When the lambda is invoked, I'd like to be able to determine which trigger invoked the lambda within the lambda code itself.当调用 lambda 时,我希望能够确定哪个触发器在 lambda 代码本身中调用了 lambda。 Is this information available somehow?这些信息是否以某种方式可用? I tried looking at the event object and the context object, but I did not see that information available.我尝试查看事件 object 和上下文 object,但我没有看到可用的信息。 Is there some api I can call to get the trigger or another way to get that information reliably?是否有一些 api 我可以打电话来获取触发器或其他可靠地获取该信息的方法?

Answering late but may help someone else looking for solution- As @Leon mentioned, eventSource would work.回答晚了,但可能会帮助其他人寻找解决方案——正如@Leon 提到的, eventSource会起作用。 For example, below are two different payload for s3 and sqs-例如,下面是 s3 和 sqs 的两个不同的有效负载-

    {
  "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": "DOC-EXAMPLE-BUCKET",
          "ownerIdentity": {
            "principalId": "A3I5XTEXAMAI3E"
          },
          "arn": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df"
        },
        "object": {
          "key": "b21b84d653bb07b05b1e6b33684dc11b",
          "size": 1305107,
          "eTag": "b21b84d653bb07b05b1e6b33684dc11b",
          "sequencer": "0C0F6F405D6ED209E1"
        }
      }
    }
  ]
 }

SQS- SQS-

    {
    "Records": [
        {
            "messageId": "11d6ee51-4cc7-4302-9e22-7cd8afdaadf5",
            "receiptHandle": "AQEBBX8nesZEXmkhsmZeyIE8iQAMig7qw...",
            "body": "Test message.",
            "attributes": {
                "ApproximateReceiveCount": "1",
                "SentTimestamp": "1573251510774",
                "SequenceNumber": "18849496460467696128",
                "MessageGroupId": "1",
                "SenderId": "AIDAIO23YVJENQZJOL4VO",
                "MessageDeduplicationId": "1",
                "ApproximateFirstReceiveTimestamp": "1573251510774"
            },
            "messageAttributes": {},
            "md5OfBody": "e4e68fb7bd0e697a0ae8f1bb342846b3",
            "eventSource": "aws:sqs",
            "eventSourceARN": "arn:aws:sqs:us-east-2:123456789012:fifo.fifo",
            "awsRegion": "us-east-2"
        }
    ]
}

Now you can use -现在你可以使用 -

source = event['Records'][0]['eventSource']

This should give the resource name, in case of s3 you would get aws:s3 , and for sqs- aws:sqs .这应该给出资源名称,在 s3 的情况下你会得到aws:s3 ,而对于 sqs- aws:sqs

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

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