I have a lambda function that I use to fetch data from an API. In my lambda function, I use current time - 1 hour. Instead of this, I want to use current time - [last successful execution time] for that function. Is that possible?
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}")
I came across this https://docs.aws.amazon.com/cli/latest/reference/stepfunctions/get-execution-history.html
but I don't understand how I can use this get-execution-history
in my case (terraformed lambda function inside a step function)
use your SDK, in pythons case 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')
for pretty much all interaction between AWS services use the SDK of your lanuage (Boto3 for python)
You can read more here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html#SFN.Client.describe_execution
If you don't know the execution arn, you can find it with https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/stepfunctions.html#SFN.Client.list_executions and the first item in the list i believe is the last one. Im pretty sure that is how it orders it automatically. - and that has the start and stop time as well.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.