1

I'm trying to create an SNS event source on a lambda using the Javascript AWS SDK. I have the following snippet:

var permissionParams = {
  FunctionName: "MyFunction",
  Action: "lambda:Invoke",
  Principal: "sns.amazonaws.com",
  StatementId: "snsinvoke",
  SourceArn: "MyArn"
};
lambda.addPermission(permissionParams, function (err, data) {
  if (err) {
    console.log(err);
  } else {
    console.log(data);
  }
});

This combined with another call to subscribe to the topic creates the event source in the lambda, but it is disabled. Is there another call I can make to enable it or is there a way to have it enabled when I add it?

0

2 Answers 2

2

Are you the owner of the SNS topic? If not, the owner needs to grant you (in the topic policy) the right to subscribe to that topic.

Sign up to request clarification or add additional context in comments.

Comments

1

Here's a short checklist that should help you accomplish what you're looking for:

  1. Your SNS Topic needs to have IAM access policy that grants access permissions to the Lambda function.
  2. Your Lambda function needs to have execution policy granting the SNS Topic execution permission.
  3. Have your Lambda function subscribed to the SNS Topic.

This checklist is based on AWS mobile blog article Invoking AWS Lambda functions via Amazon SNS. Please remember the web console does these steps automatically. You have to perform them yourself if you're using the APIs.

2 Comments

I went through that same page, that's how I came up with my original question. The event source does get added to the lambda, and the subscription shows under the SNS topic, but the event source is "Disabled" on the lambda. I can't find a way via the sdk to set it to "Enabled". So unfortunately this doesn't work for me.
You are making a mistake somewhere in the process. Lambda subscription is Enabled by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.