Callback Pattern using AWS Step function + SQS queue + Lambda in Python

Pubblicato il: 01 ottobre 2022
sul canale di: Knowledge Amplifier
5,163
69

Callback tasks provide a way to pause a workflow until a task token is returned.
A task might need to wait for a human approval, integrate with a third party, or call legacy systems.
For tasks like these, you can pause Step Functions indefinitely, and wait for an external process or workflow to complete.
For these situations Step Functions allows you to pass a task token to the AWS SDK service integrations, and also to some Optimized service integrations.
The task will pause until it receives that task token back with a SendTaskSuccess or SendTaskFailure call.

In this video , this topic is explained with in-depth intuition.

Prerequisite:
-----------------------
Send message from Step Function to SQS directly | in-depth intuition
   • Send message from Step Function to SQS dir...  

Documentation Link:
--------------------------------------
https://docs.aws.amazon.com/step-func...

Boto3 Documentation Link :
-----------------------------------------------
https://boto3.amazonaws.com/v1/docume...
Step Function Code:
----------------------------------
{
"Comment": "A description of my state machine",
"StartAt": "SQS SendMessage",
"States": {
"SQS SendMessage": {
"Type": "Task",
"Resource": "arn:aws:states:::sqs:sendMessage.waitForTaskToken",
"Parameters": {
"MessageBody": {
"input.$": "$",
"MyTaskToken.$": "$$.Task.Token"
},
"QueueUrl": "{}"
},
"Next": "Pass"
},
"Pass": {
"Type": "Pass",
"End": true
}
}
}

Lambda Function Code:
----------------------------------------------
import json
import boto3
import time

client = boto3.client('stepfunctions')

def lambda_handler(event, context):
TODO implement
print(event)
main_message=json.loads(event['Records'][0]['body'])
print("Main Message Part : {}".format(main_message))

step_fucntion_input=main_message['input']
print("The comment is : {}".format(step_fucntion_input['Comment']))
print("The Hello is : {}".format(step_fucntion_input['Hello']))

task_token=main_message['MyTaskToken']
print("The task token is : {}".format(task_token))

time.sleep(20)

response = client.send_task_success(
taskToken=task_token,
output=json.dumps({'body':'Return from Lambda Callback'})
)

Learn AWS Step Function from Scratch:
   • AWS Step Functions Simplified  

Check this playlist for more AWS Projects in Big Data domain:
   • Demystifying Data Engineering with Cloud C...  

🙏🙏🙏🙏🙏🙏🙏🙏
YOU JUST NEED TO DO
3 THINGS to support my channel
LIKE
SHARE
&
SUBSCRIBE
TO MY YOUTUBE CHANNEL


In questa pagina del sito puoi guardare il video online Callback Pattern using AWS Step function + SQS queue + Lambda in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Knowledge Amplifier 01 ottobre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 5,163 volte e gli è piaciuto 69 spettatori. Buona visione!