I have python code that is supposed to be accepting parameter and creating state machine. I keep getting this error
{
"errorMessage": "Unable to marshal response: Object of type StateMachineAlreadyExists is not JSON serializable",
"errorType": "Runtime.MarshalError",
"requestId": "67e700e5-57c7-46c2-bcb5-da12835c3f39",
"stackTrace": []
}
My json is valid as per jsonlint.com. I have to assume the issue is how I am passing it to the create_state_machine call but I have tried many things - so far without success.
here is my python for the create - being executed in a lambda (method shrunk for brevity)
def lambda_handler(event, context):
event_body = event["body"]
sf = boto3.client('stepfunctions',
aws_access_key_id='<<<accesskey>>>',
aws_secret_access_key='<<<secretkey>>>',
region_name = '<<<region>>>')
response_body = {}
try:
response_body = sf.create_state_machine(name="connexStepPuller",
definition=json.dumps(event_body),
roleArn="<<<rolearn<<<")
except Exception as err:
response_body["status_code"] = 500
print('error: %s', err)
response_body["error"] = err
response_body["stateMachineArn"] = None
I think you have a couple of problems here.
First, is that Python Exceptions are not serializable as JSON. This Question provides some solutions for you to consider. This is why you get the "Unable to marshall response" error.
Second, you are calling CreateStateMachine with a static value for Name. So you can't run this code more than once in an account. The exception you are experiencing, StateMachineAlreadyExists, indicates that:
A state machine with the same name but a different definition or role ARN already exists.