0
votes

I try to send a message to an SNS topic after the lambda function is done.

For that I return from the lambda handler function the message (python).

Lambda executes without error and returns the message correctly. IAM is set to allow the lambda to publish to the specific SNS topic.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "None",
            "Effect": "Allow",
            "Action": [
                "sns:Publish",
                "sns:Subscribe",
                "sns:ConfirmSubscription"
            ],
            "Resource": "arn:aws:sns:eu-central-1:123456789012:TOPIC"
        }
    ]
}

simplified code of lambda is:

#import packages

def handler(event, context) -> dict:
    """
    lambda handler function for invoking session

    param event: json/dict like key:val mapping for regular lambda invocations with custom topics (e.g. different data pipeline stage, different customers etc.)
    param context: AWS logging

    return: dict like key:val mapping to deliver custom topics to AWS Service invocations
    """

    #-----# key:val mapping #-----#
    '''
    '''
    Message = event["Records"][0]["Sns"]["Message"]
    Message = Message.replace("'", "\"")
    Message = json.loads(Message)

    #does lot's of stuff here
    #eg. getting data from S3, posting data to S3
    #send topic to SNS is NOT used, since it should be configured by the general lambda settings as endpoint destination.



    # -----# update key:val mapping #-----#
    event = {
        "timestamp": timestamp
    }

    return event

is there anything else one has to do? Because after inspecting cloudwatch logs, no messages arrive at the SNS.

1
How are you publishing the message to sns? - theherk
I tried to use the implemented lambda destination function. I have 2 destinations, one for failure, one for success. Failures are working and I directly receive the subscribed alarm topic. - NXK
You have both failure and success destinations allowed for publish in iam? Are some invocations going to failure destination and some missing, or just all going to failure destination? You could attempt to publish a test the message to each topic within your lambda using the sdk to verify the connection. - theherk
can you post your lambda code - omuthu
I ask because, you can only use these destinations with asynchronous invocations. Which means, you can't use the "test" button and expect it to work correctly, I believe, since that is synchronous. - theherk

1 Answers

0
votes

Solution: Used Test for testing, but it invokes the lambda function not async. Therefore the fault was in the kind of invokation.