Lambda Destinations

0

HI All I am trying to trigger a lambda(B) from an existing lambda(A) when A executes successfully. For this I created a Destination for A and set it to B, with OnSuccess.

here is the code for Lambda A, they are both in Pyhton 3.8

import json
#import pandas

def lambda_handler(event, context):
    # TODO implement
    print("Test")
    return{
        
        'statsuCode': 200,
        'body': json.dumps('Hello From Lambda')
    }
    

Lambda B

import json

def lambda_handler(event, context):
    # TODO implement
    print(event)
    print("Dummy 2")
    return {
        'statusCode': 200,
        'body': json.dumps('Hello1 from Lambda!')
    }

For some reason when I execute Lambda A successfully, Lambda B does not get triggered.

Is there something I am missing?

Regards Tanmay

asked 2 years ago704 views
2 Answers
2
Accepted Answer

Destinations will trigger only on async invocation. The TEST button on the console invokes the function synchronously. You'll need to test via the aws cli to see it in action.

Here's a command to test it

aws lambda invoke --function-name lambdaA --cli-binary-format raw-in-base64-out --invocation-type Event --payload '{"my": "event"}' result.json

This is also detailed on the blog

The other option is async invocation using Amazon S3, Amazon SNS, Amazon EventBridge etc.

AWS
answered 2 years ago
profile pictureAWS
EXPERT
Uri
reviewed 2 years ago
  • From the vague use case description, Event Bridge or Step Functions would appear to meet his needs.

1

You should invoke lambda(A) asynchronously.

e.g. Trigger lambda(A) by EventBridge event.

https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html

Regards.

kabik
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions