title: Why I am getting `Endpoint request timed out` error when AWS SecretsManager is implemented?
body: <p>I am developing a REST API with AWS Lambda, API Gateway, RDS (MySQL). I am using Node.js.</p>
  <p>This is my normal AWS Lambda code, calling database table to get the data and send it over the REST API.</p>
  <pre><code>const mysql = require('mysql');
  const con = mysql.createConnection({
    host     : &quot;****.****.****.rds.amazonaws.com&quot;,
    user     : &quot;****&quot;,
    password : &quot;****&quot;,
    port     : 3306,
    database : &quot;****&quot;
  });
  
  exports.getAllRoles = (event, context, callback) =&gt; {
    // allows for using callbacks as finish/error-handlers
    context.callbackWaitsForEmptyEventLoop = false;
    const sql = &quot;select * from role&quot;;
    con.query(sql, function (err, result) {
      if (err) throw err;
  
      var response = {
          &quot;statusCode&quot;: 200,
          &quot;headers&quot;: {
              &quot;Content-Type&quot;: &quot;application/json&quot;
          },
          &quot;body&quot;: JSON.stringify(result),
          &quot;isBase64Encoded&quot;: false
      };
      callback(null, response)
    });
  };
  </code></pre>
  <p>This is the same code, but now with <code>AWS SecretsManager</code></p>
  <pre><code>const mysql = require('mysql');
  
  
  // Load the AWS SDK
  var AWS = require('aws-sdk'),
      region = &quot;us-east-1&quot;,
      secretName = &quot;test-secret&quot;,
      secret,
      decodedBinarySecret;
  
  // Create a Secrets Manager client
  var client = new AWS.SecretsManager({
      region: region
  });
  
  
  exports.getAllRoles = (event, context, callback) =&gt; {
  
      client.getSecretValue({
          SecretId: secretName
      }, function (err, data) {
          if (err) {
              throw err;
          } else {
              // Decrypts secret using the associated KMS CMK.
              // Depending on whether the secret is a string or binary, one of these fields will be populated.
              if ('SecretString' in data) {
                  secret = data.SecretString;
              } else {
                  let buff = new Buffer(data.SecretBinary, 'base64');
                  decodedBinarySecret = buff.toString('ascii');
              }
          }
          // Your code goes here. 
          const secretObj = JSON.parse(secret);
  
          //Create MySQL Connection
          const con = mysql.createConnection({
              host     : secretObj.host,
              user     : secretObj.user,
              password : secretObj.password,
              port     : secretObj.port,
              database : secretObj.database
            });
  
          // allows for using callbacks as finish/error-handlers
          context.callbackWaitsForEmptyEventLoop = false;
          const sql = &quot;select * from role&quot;;
          con.query(sql, function (err, result) {
              if (err) throw err;
  
              var response = {
                  &quot;statusCode&quot;: 200,
                  &quot;headers&quot;: {
                      &quot;Content-Type&quot;: &quot;application/json&quot;
                  },
                  &quot;body&quot;: JSON.stringify(result),
                  &quot;isBase64Encoded&quot;: false
              };
              callback(null, response)
          });
      });    
  
  };
  </code></pre>
  <p>This is my cloud formation file</p>
  <pre><code>AWSTemplateFormatVersion: '2010-09-09'
  Transform: AWS::Serverless-2016-10-31
  Description: &gt;
    aaaa-restapi
  
    Sample SAM Template for aaaa-restapi
    
  # More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
  Globals:
    Function:
      Timeout: 100
      VpcConfig:
          SecurityGroupIds:
            - sg-4424242424
          SubnetIds:
            - subnet-424242424242
  
  Resources:
    
    GetAllRolesFunction:
      Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
      Properties:
        CodeUri: aaaa-restapi/
        Handler: role-getall.getAllRoles
        Runtime: nodejs14.x
        Events:
          HelloWorld:
            Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
            Properties:
              Path: /role/getall
              Method: get
    
  
    LambdaRole:
      Type: 'AWS::IAM::Role'
      Properties:
        AssumeRolePolicyDocument:
          Version: &quot;2012-10-17&quot;
          Statement:
            - Effect: Allow
              Principal:
                Service:
                  - lambda.amazonaws.com
              Action:
                - 'sts:AssumeRole'
        Path: /
        ManagedPolicyArns:
          - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
        Policies:
          - PolicyName: root
            PolicyDocument:
              Version: &quot;2012-10-17&quot;
              Statement:
                - Effect: Allow
                  Action:
                    - ec2:DescribeNetworkInterfaces
                    - ec2:CreateNetworkInterface
                    - ec2:DeleteNetworkInterface
                    - ec2:DescribeInstances
                    - ec2:AttachNetworkInterface
                  Resource: '*'
  </code></pre>
  <p>My code without the <code>AWS SecretsManager</code> is working fine when deployed.</p>
  <p>However the code with <code>AWS SecretsManager</code> is giving <code>timeout error</code> when deployed and tested the API Call with <code>POSTMAN</code>. I just call</p>
  <p><code>https://*****.****-api.****-1.amazonaws.com/Prod/role/getall</code></p>
  <p>I just see <code>&quot;message&quot;: &quot;Endpoint request timed out&quot;</code> and nothing else, even in the console. The same code is working fine when executed with <code>sam invoke local GetAllRolesFunction</code>. Also fine when tested with <code>sam local start-api</code>. The issue only arises when uploaded to AWS and the API Call is made.</p>
  <p>What is happening here?</p>