Aram
09/01/2021, 8:21 AM// WebhookEventsProcessor
const webhookEventsProcessor = new Function(this, 'WebhookEventsProcessor', {
handler: 'src/webhookEventsProcessor.handler',
functionName: `${scope.stage}-webhook-events-processor`,
memorySize: 256,
timeout: 30,
environment: {
...globalEnvironment,
SEND_WEBHOOK_EVENTS_QUEUE: sendWebhookEventsQueue.sqsQueue.queueUrl,
},
permissions: ['sns', 'sqs'],
currentVersionOptions: {
provisionedConcurrentExecutions: 1,
},
vpc: appVpc,
vpcSubnets: {
subnets: appVpc.privateSubnets,
},
});
const webhookEventsProcessorLive = webhookEventsProcessor.currentVersion;
const messagingEventsTopic = new Topic(this, 'MessagingEvents', {
subscribers: [
{
function: webhookEventsProcessorLive,
},
],
});
and the error I'm getting when trying to build this is
{"awsRequestId":"NOT SET YET","level":"error","message":"(node:24544) UnhandledPromiseRejectionWarning: Error: Invalid function definition for the \"Subscriber_0\" Fun
ction\n at Function.fromDefinition (/code/messaging/node_modules/@serverless-stack/resources/src/Function.ts:433:11)\n at Topic.addFunctionSubscriber (/code/mess
aging/node_modules/@serverless-stack/resources/src/Topic.ts:203:19)\n at Topic.addSubscriber (/code/messaging/node_modules/@serverless-stack/resources/src/Topic.ts:
158:12)\n at /code/messaging/node_modules/@serverless-stack/resources/src/Topic.ts:117:46\n at Array.forEach (<anonymous>)\n at Topic.addSubscribers (/code/me
ssaging/node_modules/@serverless-stack/resources/src/Topic.ts:117:17)\n at new Topic (/code/messaging/node_modules/@serverless-stack/resources/src/Topic.ts:72:10)\n
at new MindfulMessagingStack (/code/messaging/services/sst/lib/MindfulMessagingStack.ts:146:34)\n at Object.main (/code/messaging/services/sst/lib/index.ts:27:2
5)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)\n(Use `node --trace-warnings ...` to show where the warning was created) "}
{"awsRequestId":"NOT SET YET","level":"error","message":"(node:24544) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by th
rowing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled pro
mise rejection, use the CLI flag `--unhandled-rejections=strict` (see <https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode>). (rejection id: 1) "}
{"awsRequestId":"NOT SET YET","level":"error","message":"(node:24544) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise
rejections that are not handled will terminate the Node.js process with a non-zero exit code. "}
{"awsRequestId":"NOT SET YET","level":"info","message":"\u001b[90mLinting Lambda function source\u001b[39m "}
Frank
subscribers: [
{
function: webhookEventsProcessorLive,
},
],
Try this:
subscribers: [
{
function: webhookEventsProcessor,
},
],
You need to use the function as the subscriber, instead of the version.Aram
09/02/2021, 5:55 AMAram
09/02/2021, 5:57 AM// WebhookEventsProcessor
const webhookEventsProcessor = new Function(this, 'WebhookEventsProcessor', {
handler: 'src/webhookEventsProcessor.handler',
functionName: `${scope.stage}-webhook-events-processor`,
memorySize: 256,
timeout: 30,
environment: {
...globalEnvironment,
SEND_WEBHOOK_EVENTS_QUEUE: sendWebhookEventsQueue.sqsQueue.queueUrl,
},
permissions: ['sns', 'sqs'],
currentVersionOptions: {
provisionedConcurrentExecutions: 1,
},
});
const webhookEventsProcessorLive = webhookEventsProcessor.currentVersion;
const messagingEventsTopic = new sns.Topic(this, 'MessagingEvents');
messagingEventsTopic.addSubscription(new subscriptions.LambdaSubscription(webhookEventsProcessorLive));
Frank
sst.Topic
doesn’t take a version for the subscriber. Let me open an issue for it.Frank
webhookEventsProcessor.currentVersion
, isn’t it the same as adding the trigger to the original function?Aram
09/02/2021, 8:16 AMFrank