首页 > 解决方案 > 将 cloudwatch 请求 ID 替换为自定义唯一 ID

问题描述

我想向我的 cloudwatch 事件发送一个唯一 ID。
下图显示了请求 ID。必须更改此唯一 ID。

在此处输入图像描述

下面是我的 lambda 函数的 serverless.yml 代码。
我试图添加一个输入(InputTransformers),但它没有做太多。
我能在这里做什么???

functions:
  stream-function:
    handler: src/stream-handler/stream.handler
    memorySize: 1024 #in MB, also control CPU throughput
    timeout: 31 #in seconds, match with downstream to avoid concurrent request
    events:
      - stream:
          type: kinesis
          arn:
            Fn::GetAtt: [HagoStream, Arn]
          batchSize: 1
          parallelizationFactor: 2
          Id: "my cloud watch rule name"
          InputTransformer: {
               InputTemplate: '{"uniqueId": "96c80428-14fe-c8d0-f6e3-639384992391"}',
                InputPathsMap: {
                  id: '$.uniqueId'
                }
            }
          maximumRetryAttempts: 2
          destinations:
            onFailure:
              arn:
                Fn::GetAtt: [HagoFailedQueue, Arn]
              type: sqs

    environment:
      DLQ_URL:
        Ref: HagoDlqQueue

标签: amazon-web-servicesamazon-s3amazon-ec2aws-lambdaserverless

解决方案


这是 AWS为您的 lambda 函数调用分配的唯一 ID 。不能改变它。

RequestId – 调用的唯一请求 ID。

相反,在您的函数代码中,您可以生成一些额外的 ID,与您的其他数据一起在 CloudWatch Logs 中输出。


推荐阅读