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

gefragt vor 2 Jahren715 Aufrufe
2 Antworten
2
Akzeptierte Antwort

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
beantwortet vor 2 Jahren
profile pictureAWS
EXPERTE
Uri
überprüft vor 2 Jahren
  • 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
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen