0

The application itself is a Lambda handler written in Node. After "npm update", some of the sub-dependencies, babel?, is most likely interfering and doing something that have changed.

Our AWS code is initialised in one module looking like this:

const AWS = require('aws-sdk')

AWS.config.update({
  accessKeyId: process.env.AWS_ACCESSKEY_ID,
  secretAccessKey: process.env.AWS_ACCESSKEY_SECRET,
  region: process.env.AWS_REGION
})

module.exports= {
  s3: new AWS.S3(),
  dynamodb: new AWS.DynamoDB({ apiVersion: '2012-08-10' }),
  <more similar exports>
}

module.exports.default = AWS

As soon as I try to mock a method on a service, I get an error related to that service:

TypeError: AWS.DynamoDB is not a constructor
lobbin
  • 127
  • 1
  • 12

1 Answers1

0

This solved my problem this, not sure if it's a correct one, but at least I can move forward.

const AWS = require('aws-sdk')

AWS.config.update({
  accessKeyId: process.env.AWS_ACCESSKEY_ID,
  secretAccessKey: process.env.AWS_ACCESSKEY_SECRET,
  region: process.env.AWS_REGION
})

const S3 = require('aws-sdk/clients/s3')
const DynamoDB = require('aws-sdk/clients/dynamodb')

module.exports= {
  s3: new S3(),
  dynamodb: new DynamoDB({ apiVersion: '2012-08-10' }),
  <more similar exports>
}

module.exports.default = AWS
lobbin
  • 127
  • 1
  • 12