【问题标题】:replace the cloudwatch request id with a custom unique id将 cloudwatch 请求 ID 替换为自定义唯一 ID
【发布时间】:2023-03-22 19:30:01
【问题描述】:

我想向我的 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-services amazon-s3 amazon-ec2 aws-lambda serverless


    【解决方案1】:

    这是 AWS 为您的 lambda 函数调用分配的 unique ID。你无法改变它。

    RequestId – 调用的唯一请求 ID。

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

    【讨论】:

    • 注明。好的,我想向我的日志发送一个额外的唯一 ID。最好的方法是什么??
    • @grooot 它的用例特定。在 python 中,只需执行 print(f"MyRequestId: {id-that-you-somehow-generated-based-on-your-application-needs}").
    • @grooot 进展如何?您是否设法生成了 ID?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    相关资源
    最近更新 更多