繁体   English   中英

使用上次成功执行时间在 lambda function

[英]use last successful execution time in lambda function

我有一个 lambda function,用于从 API 获取数据。在我的 lambda function 中,我使用当前时间 - 1 小时。 而不是这个,我想使用当前时间 - [最后成功执行时间] function。这可能吗?

    from_time = ""
    if response["executions"]:
        start_time = response["executions"][0]["startDate"]
        week_ago = datetime.now() - timedelta(days=7)
        week_ago = week_ago.replace(tzinfo=start_time.tzinfo)
        if start_time > week_ago:
            from_time = get_utc_time(start_time)
        else:
            from_time = get_utc_time(datetime.now() - timedelta(hours=1))
        logger.info(f"Last successful execution time in UTC: {from_time}")

我遇到了这个https://docs.aws.amazon.com/cli/latest/reference/stepfunctions/get-execution-history.html

但我不明白如何在我的案例中使用这个get-execution-history (在步进函数中 terraformed lambda function)

使用你的 SDK,在 python 的情况下是 Boto3

 import boto3

 state_machine_client = boto3.client('stepfunctions')
 execution_data = state_machine_client.describe_execution(executionArn="execution arn")

 if execution_data.get('status') == "SUCCEEDED":
      end_time = execution_data.get('stopDate')

对于 AWS 服务之间的几乎所有交互,请使用语言的 SDK(Python 的 Boto3)

您可以在这里阅读更多内容: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html#SFN.Client.describe_execution

如果您不知道执行 arn,可以通过https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html#SFN.Client.list_executions和第一项找到它在列表中,我相信是最后一个。 我很确定这就是它自动订购的方式。 - 这也有开始和停止时间。

暂无
暂无

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

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