步骤执行完成后获取任务状态的函数
我尝试修改此 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
I have tried to modify this python script to get the result of the step function execution , but is failing with :
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.
The code I used in the python script is :
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 AWS 文档,如果您使用
AWS CLI
和配置文件名称创建了凭证,那么您需要使用该配置文件配置您的客户端。为此,您可以使用带有配置文件名称的会话。下面的例子(写你的代码)。Boto 必须知道要使用哪个配置文件和凭据,您可以使用
Session
指定它们。有关更多详细信息,请参阅文档。From the AWS Documentation, if you created a credential with
AWS CLI
and with a profile name, then you need to configure your client with that profile. For this you can use the session with profile name. Example below (w.r.t your code).Boto has to know, which profile and credential to use, which you can specify with
Session
. Refer to the documentation for more details.