Faisal Shani
Faisal Shani

Reputation: 810

AWS SNS is not invoking Lambda through another Lambda

I have two lambda function, functionA & functionB. I want to trigger functionB using SNS when functionA completes.

FunctionA > SNS > FunctionB

FunctionA code is ( Just showing the hello world to understand the situation)

import json

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

FunctionB code is

#!/usr/bin/python3.6
import urllib3
import json
http = urllib3.PoolManager()
def lambda_handler(event, context):

    print({
        "message": event['Records'][0]['Sns']['Message'], 

    })

I have configured a SNS topic and subscription and set that as a destination for both on_failure and on_success for functionA

enter image description here

The same SNS has been used as a trigger for FunctionB enter image description here

But when I am testing/running the functionA from AWS console it is not triggering functionB, no logs on cloudwatch - nothing. But when I am manually publishing the message to SNS then functionB is being triggered. I tried to provide the full Lambda and SNS permission to both functions but still it is not working through functionA. Any idea what I am doing wrong here? Thanks

Upvotes: 1

Views: 383

Answers (1)

Winson Tanputraman
Winson Tanputraman

Reputation: 3703

As per your screenshot, SNS is only triggered on success or on failure of Lambda asynchronous invocation. Hence, make sure you invoke Function A asynchronously. I think triggering from console is by default synchronous.

One way is to use the Invoke API, passing InvocationType as Event.

Or, use S3 or SNS as the function event source. S3 and SNS will trigger Lambda asynchronously. So SNS1 -> Function A -> SNS2 -> Function B.

Upvotes: 2

Related Questions