step function with Callback wait pattern Invalid token error

Viewed 19

I need help to debug my problem to resume execution of a step function after receiving the user choice submitted through an api gateway. My scenario is : 1- the step function is fired by an Iam event (policy creation) 2- The second step is a lambda function that sends an email to the user through sns to request an approval. The email contains an url with a Token generated by the step function at the AskUser state. 3- The step function wait the response 4- The user makes his choice 5- The api gateway receive the response and fire a lambda funtcion ReceiveUserResponse 6- ReceiveUserResponse parse the event token and try to resume the stepfunction

Unfortunately, my step function is not resumed and continue to wait indefinitely. I verified that the token is parsed and continue the same value reveived in the first email. The error returned is InvalidToken. There is my Pyhton code:

 import os
 import boto3
 import botocore
 import json, string, random 
 from botocore.exceptions import ClientError
 sns_client = boto3.client('sns')
 stf_client = boto3.client('stepfunctions')
 def lambda_handler(event, context):
 TopicArn= os.environ.get('Topic')
 token=event['queryStringParameters']['token'] 
 Message_url= 'The message has been returned with the token= '+token
 try: 
 response = stf_client.send_task_success(
  taskToken=token,
  output=str({'action': 'allow'})
 )
 except ClientError as error:
    print(type(token))
    print(str(error))
    Message_url1= 'An to execute send_task_sucess error with this token= '+token
    response = sns_client.publish (
    TargetArn = 'arn:aws:sns:us-east-1:269252182839:sam-app-AlertTopic-11K3SI14PNOT',
    Message = json.dumps({'default': Message_url1}),
    MessageStructure = 'json'
  )
     
response = sns_client.publish (
  TargetArn = 'arn:aws:sns:us-east-1:269252182839:sam-app-AlertTopic-11K3SI14PNOT',
  Message = json.dumps({'default': Message_url}),
  MessageStructure = 'json'
 ) 
return {
 'statusCode': 200,
 'body': json.dumps({'input': 'allow'})
}

Do you have any solution to handle with this error?

Thanks!

0 Answers
Related