AWS lambda - cannot connect to RDS database, only locally

Asked

Viewed 106 times

0

I am trying to connect to a RDS instance from a lambda. I made and tested the lambda locally, it worked perfectly. However, when I deploy to AWS the code is normally executed until the part where the connection to the bank is made. From this, not even log messages appear.

Note: I am using context.callbackWaitsForEmptyEventLoop = false;

Note: I am not using VPC in lambda.

Obs3: I have older planes that work normal, only the new ones are with this problem, even if the configurations are the same.

This is the relevant part of the code:

if (body && body.modality_id) {

            console.log('Just debugging...')

            DB.query("call sp_create_transaction (?)",[body.modality_id])
                .then(results => {
                    if (results[0][0]) {
                        if (results[0][0].Error) {
                            helper.body = { 'message': results[0][0].Error };
                            console.log('Error:' + results[0][0].Error);
                        }
                        else {
                            helper.statusCode = 200;
                            helper.body = results[0];
                            console.log(helper.body);
                            console.log('EXECUTION SUCCESS:');
                        }
                    }
                    else {
                        helper.statusCode = 401;
                        helper.body = { 'message': 'Falha ao buscar taxas.' };
                        console.log('Error: Rates not found.');
                    }
                    callback(null, helper.response);
                })
                .catch(err => {
                    helper.statusCode = 500;
                    helper.body = { 'message': 'Por favor, informa ao time de suporte técnico o código DAN-54.' };
                    console.log('Error: DAN-54');
                    console.log(err);
                    callback(null, helper.response);
                });
        }

Here is the log output:

START RequestId: fb134979-7d0e-4fa3-b7c8-4192f4765ea8 Version: $LATEST
2019-05-28T23:47:26.609Z fb134979-7d0e-4fa3-b7c8-4192f4765ea8 INFO Just debugging...
END RequestId: fb134979-7d0e-4fa3-b7c8-4192f4765ea8
REPORT RequestId: fb134979-7d0e-4fa3-b7c8-4192f4765ea8 Duration: 1273.33 ms Billed Duration: 1300 ms Memory Size: 128 MB Max Memory Used: 79 MB 

2 answers

1


Hard to say, but since the execution duration seems small for proc execution, my hypothesis is that the lambda is returning before the asynchronous execution of DB.query(), so you don’t see any more output. To confirm you can increase the timeout and if so, use async/await or the Promises API to wait for the result before invoking the return callback.

1

I implemented some lambda connecting on the RDS used the serverless framework That’s what it’s all about. To be able to connect in RDS your lamnda has to have access to VPC, the subnet that the bank finds more permissions in RDS itself

You have to configure on the network part of the lambda page

inserir a descrição da imagem aqui

  • I accidentally saved the incomplete answer and already took a negative :'(

  • Solved the problem ;)

  • Thanks @Jaksonfischer soon I plan to upload a lambda example code by accessing RDS on my github, I haven’t had time yet. Put the link here for staff to follow the documentation and very flawed then and example that we get the https://github.com/krismorte thing

  • Opa, this is always good. Unfortunately here are a people who is with the finger ready to negative, but give a vote in favor, necas... Unfortunately we suffer a lot from it, but there’s nothing to do :/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.