Sending RabbitMQ messages from AWS Lambda
Asked Answered
B

2

6

Any idea why AWS Lambda functions are unable to publish messages to RabbitMQ using the amqp protocol?

(I'm using the node.js runtime with the node amqplib runtime)

When using the code from my local machine then messages get published and received on the target queue. When running identical code within Lambda then everything appears to run including returning a true response from Channel.publish BUT the messages don't appear at the Exchange

I've tried adding a delay just incase Lambda is terminating too fast

Any other ideas? Does Lambda block protocols or am I being stupid?

Beaux answered 18/8, 2016 at 8:49 Comment(3)
I can see that the Channel and Connection are being created (in RabbitMQ management panel these appear) - however no data appears to be being transferred down themBeaux
Did you ever figure this out? I am looking to do something similar, thanks for any informationGranivorous
If your RabbitMQ broker is not accessible over the internet, maybe you'll need to bound your lambda to a custom VPC in your accout. By default functions are bounded to an AWS managed vpc.Quinonez
B
0

I had to launch mine in a VPC subnet with a NAT gateway configured. I didn't dig much into it, but I suspect your network connection options are limited otherwise.

Biographer answered 11/11, 2016 at 2:47 Comment(0)
S
0

This is an old post, but I ran into this issue recently and was able to get passed it by waiting for the channel event buffer to drain. channel.publish returns a boolean, so for example...

const messageSent = myChannel.publish('foo'exchange','routing-key', Buffer.from("my message"));

 if (!messageSent) {
  await new Promise((resolve) => myChannel.once('drain', () => resolve));
}

The drain event is apparently raised when the buffer has been drained completely. Once I did this, messages start to get published successfully to RabbitMQ.

Studer answered 18/9 at 21:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.