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

已提問 2 年前檢視次數 715 次
2 個答案
2
已接受的答案

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
已回答 2 年前
profile pictureAWS
專家
Uri
已審閱 2 年前
  • 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
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南