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

feita há 2 anos715 visualizações
2 Respostas
2
Resposta aceita

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
respondido há 2 anos
profile pictureAWS
ESPECIALISTA
Uri
avaliado há 2 anos
  • 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
respondido há 2 anos

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas