【问题标题】:AWS X-Ray and StepFunctions -> can't get TraceHeaderAWS X-Ray 和 StepFunctions -> 无法获取 TraceHeader
【发布时间】:2020-10-16 13:38:21
【问题描述】:

我想获取我的 Stepfunction 的特定执行的跟踪。
我 100% 为我的 stepfunction 启用 X-Ray 并授予它完全访问权限。

我使用 boto3 创建了一个 lambda,它描述了给定 executionArn 的执行。
问题是响应不完整!它没有给我traceHeader。 (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html)

我的 Lambda 代码:

import json
import boto3
import pprint
import botocore

def lambda_handler(event, context):

    clientStepFunction = boto3.client('stepfunctions')
    
    try:
        response = clientStepFunction.describe_execution(executionArn="execArn...")
        pprint.pprint(response)
    except clientStepFunction.exceptions.ExecutionDoesNotExist:
        print("Error Execution doesn't exists")
    except clientStepFunction.exceptions.InvalidArn:
        print("Error invalid arn")

    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lamerarara!')
    }

我很好地打印了回复:

{'ResponseMetadata': {...},
 'executionArn': 'execArn',
 'input': '{\n  "IsHelloWorldExample": true\n}',
 'name': 'execName',
 'output': '[{\n'
           '  "IsHelloWorldExample": true\n'
           '},{\n'
           '  "IsHelloWorldExample": true\n'
           '}]',
 'startDate': datetime.datetime(2020, 10, 16, 13, 21, 6, 724000, tzinfo=tzlocal()),
 'stateMachineArn': 'stepMachineArn',
 'status': 'SUCCEEDED',
 'stopDate': datetime.datetime(2020, 10, 16, 13, 21, 10, 191000, tzinfo=tzlocal())}

谢谢!

解决方案:

终于是boto3的版本了。目前 aws 上的 boto3 版本不是最新的。你需要 boto3 1.15+ 来获取 traceHeader

【问题讨论】:

    标签: amazon-web-services boto3 aws-step-functions aws-xray


    【解决方案1】:

    您是否尝试按照此sample 添加 xray patch_all() 以在您的 Lambda 中启用 AWS sdk 检测?也不要忘记添加依赖aws-xray-sdk

    【讨论】:

    • 终于是boto3的版本了。目前 aws 上的 boto3 版本不是最新的。你需要 boto3 1.15+ 来获取 traceHeader
    猜你喜欢
    • 1970-01-01
    • 2019-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    • 1970-01-01
    • 2023-02-20
    • 2019-10-31
    相关资源
    最近更新 更多