serverless / serverless Public
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(AWS Lambda): Support for Amazon MQ RabbitMQ events #9919
Conversation
Codecov Report
@@ Coverage Diff @@
## master #9919 +/- ##
==========================================
+ Coverage 85.26% 85.30% +0.03%
==========================================
Files 334 335 +1
Lines 13638 13675 +37
==========================================
+ Hits 11628 11665 +37
Misses 2010 2010
Continue to review full report at Codecov.
|
Closes: #9924 |
Hello @liegeandlief - I've tried it out and after fixing few minor issues in integration tests they are failing, looks like the Lambda function cannot access rabbitmq at all. Did you have a chance to run the tests itself or did you perform similar testing to ensure it's working? |
Hi @pgrzesik, thanks for taking a look. Is that the Lambda function for putting a message into the queue? Unfortunately I have not been able to run the integration tests as I don't have access to an AWS account with suitable permissions to create all the necessary infrastructure. Is there a particular error you are getting? |
Hey @liegeandlief - yes, this it's the producer Lambda that cannot access the broker, it errors out with |
@pgrzesik There was a spelling mistake in one of the variable names which may have caused this error. I've have just pushed up a fix. |
Yeah, that one I've spotted and fixed on my side as it was simply trying to connect to localhost, but after fixing it it's still refusing to connect :( |
@pgrzesik I'm just trying to build the infrastructure stack so I can take a look at this test error. I have fixed the spelling mistake problem and also corrected the RabbitMQ instance type to |
Hey @liegeandlief, the MSK Cluster takes really long to provision, but I would encourage you to just simplify the script to not provision |
@pgrzesik The RabbitMQ integration test should now be working (at least i worked for me!) |
Thanks @liegeandlief - I see that it was about SSL in the end :D I've tried to test, but I see the integration test failing for me - there are not messages to be consumed by the consumer function that include the expected message. Is that test green for you? |
@pgrzesik It's weird that it isn't working for you. It is green for me. It is quite slow as it seems to take quite a long time to create the Lambda functions in the VPC. |
@liegeandlief That is surprising - for me it always fail with the following output Do you have any local changes that are not pushed here that might be affecting it? |
@pgrzesik No local changes, everything is pushed |
@pgrzesik When the test is running can you see the consumer function log group in CloudWatch and are you able to inspect what gets logged? |
@pgrzesik a colleague and I have both managed to run the test successfully. We both used brand new AWS accounts when doing so and all the resources were created in the us-east-1 region. The AWS user credentials had full permissions on each account. When creating the integration test dependency stack we didn't comment anything out, but allowed it to create all infrastructure even though only some of it was required for the test. I don't know if any of this context is helpful in determining why the test is failing for you? |
Hello @liegeandlief - I was trying it out once again today multiple times, with the exact same environment and the tests are not succeeding for me. Unfortunately, I won't be available for the next two weeks - I'm handing off the tasks to @medikoo, who based on availability might be able to help. |
Hello @liegeandlief |
Hello @liegeandlief - I've tried multiple different approaches and I cannot get this test to work - it does not pass and errors out without finding the expected item in the logs - is there anything else different with your setup when you're running this test by any chance? Additionally, could you rebase your PR on top of current master whenever you have a chance? Update - I've managed to finally resolve the issue on my side - it turns out the error was with my setup, where the current logic for setting up infrastructure does not update the passwords in Secrets Manager and I ran it the first time by mistake and then it wasn't using the updated password - all is good now, I'll review the PR and I imagine we should be good to go soon. |
Thank you @liegeandlief - it looks great in general. I only have small suggestions related to async/await
and changes to ActiveMQ
. I understand the reasoning behind "cleanup" for activemq
, but I would keep it out of this PR to make it focused on one thing only and submit the cleanup part separately if you'd like. What do you think?
Thanks a lot for your patience on this one
} | ||
|
||
async function producer() { | ||
await new Promise((resolve) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why it needs to be wrapped in a Promise? Can we just use simpler async/await
across the whole function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using asyc/await and it caused the test to fail. I think it may have something to do with the fact that amqplib isn't using native promises but is using Bluebird instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How was it failing? I don't think there should be an issue with await-ing Bluebird promises as we're doing that in our codebase in a lot of places
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't quite remember now, but I think it either wouldn't create the queue or wouldn't send the message to the queue. I fiddled about with it for ages with no success and then changed it to not use async/await which worked first time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried changing it and went with:
const connectOptions = {
protocol: 'amqps',
hostname: process.env.RABBITMQ_HOST,
port: 5671,
username: process.env.RABBITMQ_USERNAME,
password: process.env.RABBITMQ_PASSWORD,
};
const connection = await amqp.connect(connectOptions);
const channel = await connection.createChannel();
const queueName = process.env.QUEUE_NAME;
await channel.assertQueue(queueName);
await channel.sendToQueue(queueName, Buffer.from('Hello from RabbitMQ Integration test!'));
return {
statusCode: 200,
};
and it looks like it works just fine. Could you change the implementation to async/await-based one? I think it's the last thing before the merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's now been updated to use async/await
@@ -30,9 +30,9 @@ describe('AWS - Active MQ Integration Test', function () { | |||
|
|||
const outputMap = await getDependencyStackOutputMap(); | |||
|
|||
log.notice('Getting Active MQ Credentials ARN'); | |||
log.notice('Getting ActiveMQ Credentials ARN'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave out the adjustments to ActiveMQ
tests, even though the change might be valid to keep this PR focused on RabbitMQ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed those changes to the ActiveMQ tests
@pgrzesik I've brought my fork up to date with the upstream master branch |
Looks good overall, I just have a few minor things and we're good to ship it
} | ||
|
||
async function producer() { | ||
await new Promise((resolve) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How was it failing? I don't think there should be an issue with await-ing Bluebird promises as we're doing that in our codebase in a lot of places
test/utils/cloudformation.js
Outdated
@@ -4,7 +4,9 @@ const awsRequest = require('@serverless/test/aws-request'); | |||
|
|||
const SHARED_INFRA_TESTS_CLOUDFORMATION_STACK = 'integration-tests-deps-stack'; | |||
const SHARED_INFRA_TESTS_ACTIVE_MQ_CREDENTIALS_NAME = | |||
'integration-tests-active-mq-broker-credentials'; | |||
'integration-tests-activemq-broker-credentials'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep the old value for this const
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -130,17 +170,33 @@ async function handleInfrastructureUpdate() { | |||
(async () => { | |||
log.notice('Starting setup of integration infrastructure...'); | |||
|
|||
if (!process.env.SLS_INTEGRATION_TESTS_ACTIVE_MQ_USER) { | |||
if (!process.env.SLS_INTEGRATION_TESTS_ACTIVEMQ_USER) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep these env vars as they were - let's limit changes to existing logic in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
} | ||
|
||
async function producer() { | ||
await new Promise((resolve) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried changing it and went with:
const connectOptions = {
protocol: 'amqps',
hostname: process.env.RABBITMQ_HOST,
port: 5671,
username: process.env.RABBITMQ_USERNAME,
password: process.env.RABBITMQ_PASSWORD,
};
const connection = await amqp.connect(connectOptions);
const channel = await connection.createChannel();
const queueName = process.env.QUEUE_NAME;
await channel.assertQueue(queueName);
await channel.sendToQueue(queueName, Buffer.from('Hello from RabbitMQ Integration test!'));
return {
statusCode: 200,
};
and it looks like it works just fine. Could you change the implementation to async/await-based one? I think it's the last thing before the merge
@pgrzesik Thanks for all of your help on this! When is it likely to be included in a release? |
If nothing unexpected pops up, I was planning to prepare a release tomorrow morning CEST time |
@pgrzesik This should add support for Amazon MQ RabbitMQ events. It is very much based upon the recently merged PR for ActiveMQ events. I have added integration tests but have been unable to actually run them as I don't have access to an AWS account with the necessary permissions. If you could take a look then that would be great. Thanks :)