title: How to mock AWS RDSDataService methods?
body: <p>I have a database file (not a class) that does an update operation as shown below -</p>
  <pre><code>    /* database operations file  - NOT A CLASS */
      import * as AWS from 'aws-sdk';
      AWS.config.update({
           region: 'us-west-2'
      });
      //.... set resourceARN, secretARN and other params to be passed to 
      const secretARN = process.env['SECRETARN'];
      const resourceARN = process.env['RESOURCEARN'];
      const rdsDataService = new AWS.RDSDataService();
      const databaseName = process.env['DATABASE'];
  
  
      
      // update query here
      
      const addID = async(myID:string, userIds:string[], param3:string) =&gt; {
      // .....some validation on the parameters
      const userIdlist = userIds.join();
      const updateQuery = 'my update sql query';
  
      const sqlParams:any = {
          secretArn: secretARN,
          resourceArn: resourceARN,
          sql: updateQuery,
          database: databaseName,
          includeResultMetadata: true
      }
      // run SQL command
      await rdsDataService.executeStatement(sqlParams).promise()
          .then(() =&gt; { logger.info('Update Query succeeded') })
          .catch((error) =&gt; { logger.info(error); throw new Error('Unable to perform update for given users') });
  };
  
  export default {
      addID
  }
  </code></pre>
  <p>This is my test file -</p>
  <pre><code>import * as sinon from 'sinon';
  import chai from 'chai';
  import * as AWS from 'aws-sdk';
  import chaiaspromised from 'chai-as-promised';
  import AWSMock from 'aws-sdk-mock';
  import proxyquire from 'proxyquire';
  chai.use(chaiaspromised);
  
  const expect = chai.expect;
  describe('Test Database component', () =&gt; {
      it('add ID should be successful when all arguments are provided correctly', async () =&gt; {
      AWSMock.setSDKInstance(AWS);
      const rdstub = AWSMock.mock('RDSDataService', 'executeStatement', function (params, callback){
          callback(null, 'successfully put item in database');
      });
      const dbops = proxyquire('path to the database file above', {rdsDataService:rdstub}).default;
      expect(await dbops.addRegulationID('xyz', ['101', '102'], 'xyz')).to.not.throw();
      AWSMock.restore('AWS.RDSDataService');
  });
  });
  </code></pre>
  <p>whenever I run the test, I get an error like below -</p>
  <pre><code>Test Database component
      1) add ID should be successful when all arguments are provided correctly
  
  
    0 passing (4s)
    1 failing
  
    1) Test Database component add ID should be successful when all arguments are provided correctly:
       Error: Unable to perform update for given users
        at lib/dbops.ts:96:55
  </code></pre>
  <p>How can I mock the executeStatement API of RDSDataService? Do I need a separate mock library for it? I tried the above after referring a few examples for the npm library, but somehow the mock does not seem to be working for RDSDataService. Where am I going wrong here?</p>