簡體   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