Enable an SNS Event Source on lambda with javascript SDK
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?
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.
Here's a short checklist that should help you accomplish what you're looking for:
SNS Topic
needs to have IAM access policy
that grants access permissions to the Lambda
function. Lambda
function needs to have execution policy
granting the SNS Topic
execution permission. 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.
链接地址: http://www.djcxy.com/p/32246.html