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 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则