0

I'm getting this error while accessing SQL Server database from aws-lambda. Everything works fine from local machine.Only having access issue when executing the code from lambda.

ConnectionError: Failed to connect to 10.2.3.44\SQLSRVR code: ETIMEOUT

This is my code snippet, any help would be appreciated!

const { Sequelize } = require('sequelize');
const sequelize = new Sequelize('DBname', null, null, {
  dialect: 'mssql',
  host: '10.2.3.44',   //MSSQL Server IP sample
  dialectOptions: {
    authentication: {
      type: 'ntlm',
      options: {
        domain: 'addidas',
        userName: "uname",
        password: "pwd"
      }
    },
    options: {
      instanceName: 'SQLSRVR'
    }
  }
})
async function connect() {
    try {
      await sequelize.authenticate();
      console.log('Connection has been established successfully.');
    } catch (error) {
      console.error('Unable to connect to the database:', error);
    }
  }
connect();
8
  • Does your Lambda function have internet access if that database is outside of AWS? Commented Nov 6, 2021 at 7:26
  • Where is you ql server located? Do you have any firewall rules that allow your local machine but not other clients? For instance on azure you have to explicitly allow any IP address that is not within azure to be able to access the sql server. Commented Nov 6, 2021 at 8:24
  • Please Edit your question to provide more details. For example, where is the SQL Server hosted? Is it an Amazon RDS database? Commented Nov 6, 2021 at 9:05
  • You probably need this: docs.aws.amazon.com/lambda/latest/dg/configuration-vpc.html Commented Nov 6, 2021 at 9:12
  • 3
    10.2.3.44 is private address. Nothing on the internet knows how to get to it unless you do some kind of port forwarding from a public internet address. Commented Nov 6, 2021 at 9:44

1 Answer 1

1

It was because of the network restrictions only, as assumed. So had to assign lambdas in the same network which SQL server is hosted. Thanks for all the suggestions.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.