步骤执行完成后获取任务状态的步骤函数
step function to get the task status when step execution is completed
我试图修改此 python 脚本以获取步进函数执行的结果,但失败了:
File "step_function.py", line 6, in <module>
input = json.dumps({})
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the StartExecution operation: The security token included in the request is invalid.
我在 python 脚本中使用的代码是:
import time
from time import sleep
import boto3
import json
sf_client = boto3.client('stepfunctions')
sf_output = sf_client.start_execution(
stateMachineArn = arn:aws:states:us-west-2:208244xxxxx:stateMachine:samplePipelinedevs-xxxxx,
input = json.dumps({})
)
while True:
time.sleep(5) # don't need to check every nanosecond
sf_response = sf_client.describe_execution(executionArn=sf_output['executionArn'])
status = sf_response['status'] # BE SURE TO GET THE CURRENT STATE
print("%s: %s" % ("> Status...", status))
if status == 'RUNNING':
continue
elif status == 'FAILED':
raise Exception("%s: %s" % ("! ERROR ! Execution FAILED: ", sf_response))
else: # SUCCEEDED
break
根据 AWS 文档,如果您使用 AWS CLI
和配置文件名称创建了凭证,则需要使用该配置文件配置您的客户端。为此,您可以使用带有配置文件名称的会话。下面的示例(w.r.t 您的代码)。
import boto3
session = boto3.Session(profile_name='devsample')
sf_client = session.client('stepfunctions')
.
.
Boto 必须知道要使用哪个配置文件和凭据,您可以使用 Session
指定。详情请参阅 documentation。
我试图修改此 python 脚本以获取步进函数执行的结果,但失败了:
File "step_function.py", line 6, in <module>
input = json.dumps({})
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 386, in _api_call
return self._make_api_call(operation_name, kwargs)
File "/usr/local/lib/python2.7/dist-packages/botocore/client.py", line 705, in _make_api_call
raise error_class(parsed_response, operation_name)
botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the StartExecution operation: The security token included in the request is invalid.
我在 python 脚本中使用的代码是:
import time
from time import sleep
import boto3
import json
sf_client = boto3.client('stepfunctions')
sf_output = sf_client.start_execution(
stateMachineArn = arn:aws:states:us-west-2:208244xxxxx:stateMachine:samplePipelinedevs-xxxxx,
input = json.dumps({})
)
while True:
time.sleep(5) # don't need to check every nanosecond
sf_response = sf_client.describe_execution(executionArn=sf_output['executionArn'])
status = sf_response['status'] # BE SURE TO GET THE CURRENT STATE
print("%s: %s" % ("> Status...", status))
if status == 'RUNNING':
continue
elif status == 'FAILED':
raise Exception("%s: %s" % ("! ERROR ! Execution FAILED: ", sf_response))
else: # SUCCEEDED
break
根据 AWS 文档,如果您使用 AWS CLI
和配置文件名称创建了凭证,则需要使用该配置文件配置您的客户端。为此,您可以使用带有配置文件名称的会话。下面的示例(w.r.t 您的代码)。
import boto3
session = boto3.Session(profile_name='devsample')
sf_client = session.client('stepfunctions')
.
.
Boto 必须知道要使用哪个配置文件和凭据,您可以使用 Session
指定。详情请参阅 documentation。