title: How do I properly mock dynamoDB calls?
body: <p>I am trying to create a unit test for my nodeJS application that uses the AWS SDK to make calls into DynamoDB. In the test below, I attempt to mock out the putItem call into DynamoDB, but when I run the test, it attempts to call out to AWS.</p>
  
  <pre><code>    import AWSMock from 'aws-sdk-mock'
  
      ...
  
      it('Can create an item', mochaAsync(async () =&gt; {
          AWSMock.mock('DynamoDB', 'putItem', (params: Certification, callback: any) =&gt; {
              console.log('Returning certification content from mock');
              let temp: Certification = Object.create(certification);
              temp.id = uuid();
              return callback(null, temp);
          });
  
          let res: Certification = await service.upsert(certification);
          expect(res.id).empty.false;
          expect(res.name).to.eql(certification.name);
          expect(res.description).to.not.eql(certification.description);
          expect(res.dateIssued).to.eql(certification.dateIssued);
          expect(res.dateExpires).to.eql(certification.dateExpires);
          expect(res.image).to.eql(certification.image);
      }));
  </code></pre>
  
  <p>Code being tested, for full context see <a href="https://github.com/bkimbrou/resume-backend" rel="nofollow noreferrer">https://github.com/bkimbrou/resume-backend</a>:</p>
  
  <pre><code>    public upsert(event: Certification, context: any = {}) : Promise&lt;Certification&gt; {
          return new Promise&lt;Certification&gt;(() =&gt; this.putItem(event));
      }
  
  ...
  
      protected putItem(item: T) {
          if (!item.id) {
              item.id = uuid()
          }
          let params: AWS.DynamoDB.PutItemInput = {
              Item: AbstractDynamoService.jsonToItem(item),
              TableName: this.tableName
          };
  
          this.dynamo.putItem(params, AbstractDynamoService.handleResult);
      }
  </code></pre>
  
  <p>Any insights into where I have gone wrong would be much appreciated!</p>