1
package example;
import java.io.*;
import com.amazonaws.services.lambda.runtime.Context; 
public class LambdaMethodHandler {
    public String handlerString(String input,Context context) {
    System.out.println(input.length());
        return input;
    }
}
// This is my function policy
{
    "Version": "2012-10-17",
    "Id": "default",
    "Statement": [
        {
            "Sid": "sns-xxxx-Sns_Lambda_test",
            "Effect": "Allow",
            "Principal": {
                "Service": "sns.amazonaws.com"
            },
            "Action": "lambda:invokeFunction",
            "Resource": "arn:aws:lambda:xxxxx:function:theSimplestLambda",
            "Condition": {
                "ArnLike": {
                    "AWS:SourceArn": "arn:aws:sns:eu-west-1:xxxx:Sns_Lambda_test"
                }
            }
        }
    ]
}
  • Handler : I am very new to amazon web services, I made a demo lambda. When i invoke it using the cli(Or web console) with any random string, it works and shows the length of the input string on the webpage of lambda. Then i subscribed it to a SNS topic and tried to publish a event with a random string to it. I can't see the result on the webpage(lambda) i.e length of the string is not displayed. How to know that the lambda is processing the string correctly?
Crosk Cool
  • 664
  • 2
  • 12
  • 27
  • If you created the resources using CloudFormation (or CLI), you need to give Lambda permission to get invoked: aws lambda add-permission --region REGION_NAME --function-name LAMBDA_FUNCTION_NAME --statement-id SOME_ID --action lambda:InvokeFunction --principal config.amazonaws.com. – krishna_mee2004 Jul 31 '17 at 15:49
  • I checked my function policy and Effect is allowed, could you see it and tell me that if i am missing something.@KrishnaKumarR – Crosk Cool Jul 31 '17 at 15:57
  • This is in SNS. That is correct. But, you need to enable Lambda to get invoked. The command to do that was mentioned in the previous comment. – krishna_mee2004 Jul 31 '17 at 16:49
  • Possible duplicate of [AWS Lambda & SNS: Invoke Lambda cross-region](https://stackoverflow.com/questions/35006556/aws-lambda-sns-invoke-lambda-cross-region) – adamkonrad Jul 31 '17 at 20:40
  • Your question is seeking a solution similar to https://stackoverflow.com/questions/35006556/aws-lambda-sns-invoke-lambda-cross-region/35017361#35017361 – adamkonrad Jul 31 '17 at 20:40

1 Answers1

0

Apparently, the aws lambda was correctly getting invoked, the reason why the length of the string that I displayed in the handler wasn't getting displayed because of the parameter that i was taking inside the lambda, In order to process something as input from SNS i have to take a event of type SNSevent in the argument and then process it afterwards.

Crosk Cool
  • 664
  • 2
  • 12
  • 27