I’ve setup an SNS subscription like this in serverless.yml
functions:
helloWorld:
handler: lib/handlers/hello.helloWorldHandler
events:
- sns: helloWorld
- http:
method: get
path: hello
- http:
method: post
path: hello
That creates the SNS topic and subscription seemingly fine upon deploy - and when I publish to the topic subscription via the AWS console UI it causes the lambda to run.
PROBLEM: however, when I try and publish via the NodeJS API the lambda does not respond, eg:
async function publishSomething() {
const sns = new aws.SNS({ region: 'us-west-2' });
const payload = JSON.stringify({ foo: 123 });
await sns.publish({
Subject: 'My Subject',
Message: payload,
TargetArn: 'arn:aws:sns:us-west-2:255291343873:helloWorld',
})
}
What am I doing wrong here? Something obvious/stupid??!! The fact that it responds from the AWS Console UI suggests that it’s configured OK in the serverless.yml
and that I’m somehow addressing it wrong in the publish
method.
Thanks everyone!