如何获取在哪个步骤功能失败的组件名称

发布于 2025-02-13 22:57:32 字数 202 浏览 1 评论 0原文

我有executionArn stepfunction执行的列表,我正在过滤这些executionArn by status =='失败'

现在,如何在python中获得stepfunction的确切失败(意思是:执行失败)?

I have list of executionArn of stepfunction execution, I am filtering those executionArn by status == 'FAILED'.

Now, how can I get the exact failure of the stepfunction in Python, (meaning: at which point the execution has failed)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽月 2025-02-20 22:57:32

您可以做这样的事情:

import boto3
import jmespath

client = boto3.client('stepfunctions')


full_result = (
    client
    .get_paginator('get_execution_history')
    .paginate(arn=<your arn>)
    .build_full_result()
)

exn_failed_event = jmespath.search('events[?type==`ExecutionFailed`]', full_result)

exn_failed_event字典看起来像这样

[
  {
    'executionFailedEventDetails': {
         'cause': 
           'An error occurred while executing '
           "the state 'Lambda Invoke' (entered "
           'at the event id #4). Invalid path '
           "'$.foo' : No results for path: "
           "$['foo']",
         'error': 'States.Runtime'
    },
    'id': 11,
    'previousEventId': 0,
    'timestamp': datetime.datetime(2022, 7, 11, 19, 0, 24, 2000, tzinfo=tzlocal()),
    'type': 'ExecutionFailed'
  }
]

You can do something like this:

import boto3
import jmespath

client = boto3.client('stepfunctions')


full_result = (
    client
    .get_paginator('get_execution_history')
    .paginate(arn=<your arn>)
    .build_full_result()
)

exn_failed_event = jmespath.search('events[?type==`ExecutionFailed`]', full_result)

The exn_failed_event dictionary will look something like this

[
  {
    'executionFailedEventDetails': {
         'cause': 
           'An error occurred while executing '
           "the state 'Lambda Invoke' (entered "
           'at the event id #4). Invalid path '
           "'$.foo' : No results for path: "
           "$['foo']",
         'error': 'States.Runtime'
    },
    'id': 11,
    'previousEventId': 0,
    'timestamp': datetime.datetime(2022, 7, 11, 19, 0, 24, 2000, tzinfo=tzlocal()),
    'type': 'ExecutionFailed'
  }
]
屌丝范 2025-02-20 22:57:32

基于有一个搜索方法,您可以在迭代器对象上调用。

因此,您的实际代码可以简化 - 并收集不需要的数据 - 到:

import boto3

failed_events = boto3.client('stepfunctions')
  .get_paginator('get_execution_history')
  .paginate(arn=<your arn>)
  .search('events[?type==`ExecutionFailed`]')

Based on this issue in boto3 repository, it looks like there is a search method that you can call on an iterator object.

So your actual code could be simplified — and gather less unneeded data — to:

import boto3

failed_events = boto3.client('stepfunctions')
  .get_paginator('get_execution_history')
  .paginate(arn=<your arn>)
  .search('events[?type==`ExecutionFailed`]')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文