简体   繁体   中英

step function to get the task status when step execution is completed

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

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).

import boto3

session = boto3.Session(profile_name='devsample')
sf_client = session.client('stepfunctions')
.
.

Boto has to know, which profile and credential to use, which you can specify with Session . Refer to the documentation for more details.

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.

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