boundless-farmer-38967
09/02/2022, 11:15 AM//lambda role
const lambdaHandlerRole = new paws.iam.Role(`${projectToken}-data-topic-lambda-role`, {
assumeRolePolicy: {
Version: "2012-10-17",
Statement: [{
Action: "sts:AssumeRole",
Principal: {
Service: "<http://lambda.amazonaws.com|lambda.amazonaws.com>",
},
Effect: "Allow",
Sid: "",
}],
},
});
new paws.iam.RolePolicyAttachment(`${projectToken}-role-attach`, {
role: lambdaHandlerRole,
policyArn: paws.iam.ManagedPolicies.AWSLambdaExecute,
});
//SNS topic
const topic = new paws.sns.Topic(`${projectToken}-data-topic`);
//Lambda - code loaded from a sub-dir
const badgerFunc = new paws.lambda.Function(`${projectToken}-data-sender-badger`, {
code: new pulumi.asset.AssetArchive({
".": new pulumi.asset.FileArchive("./lambda/badger"),
}),
runtime: "nodejs16.x",
handler: "index.handler",
role: lambdaHandlerRole.arn,
});
//Subscribe lambda to SNS
new paws.sns.TopicSubscription(`${projectToken}-badger`, {
topic: topic.arn,
protocol: "lambda",
endpoint: badgerFunc.arn,
});
What I already checked:
1. Run lambda to ensure it's properly set up
2. Manually subscribe the deployed lambda and confirm it triggers on new message
3. Subscribed my email to the same topic to ensure it indeed publishes messages
It has to be something in the above set up, but there's no document anywhere with a complete example for subscribing a lambda to a topic.
Thanks!victorious-church-57397
09/02/2022, 1:20 PMboundless-farmer-38967
09/02/2022, 3:26 PMvictorious-church-57397
09/02/2022, 3:27 PMnew aws.lambda.Permission('sns-event-trigger-permission', {
action: 'lambda:InvokeFunction',
principal: '<http://sns.amazonaws.com|sns.amazonaws.com>',
function: badgerFunc.arn,
sourceArn: topic.arn,
});
boundless-farmer-38967
09/02/2022, 11:36 PMvictorious-church-57397
09/03/2022, 9:53 AM