Easily mock aws-sdk API methods to enable easier testing of applications which use the AWS SDK for JavaScript
Questions tagged [aws-sdk-mock]
36 questions
18
votes
5 answers
Mocking using aws-sdk-mock's promise support with DocumentClient
I'm trying to write a unit test using aws-sdk-mock's promise support. I'm using DocumentClient.
My code looks like this:
const docClient = new AWS.DynamoDB.DocumentClient();
const getItemPromise = docClient.get(params).promise();
return…

JAck28
- 899
- 4
- 15
- 40
5
votes
2 answers
Mocking AWS with dwyl/aws-sdk-mock not working
First of all, I'm not using lambda, so I believe this thread isn't the same question.
I'm getting this error in the before hook:
TypeError: Attempted to wrap undefined property S3 as function
at checkWrappedMethod…

Henrique Barcelos
- 7,670
- 1
- 41
- 66
4
votes
4 answers
How to write unit test for the function which is accessing aws resources?
I have a function which is accessing multiple aws resources and now need to test this function, but I don't know how to mock these resources.
I have tried following github of aws-sdk-mock, but didn't get much there.
function someData(event,…

ankuselfie
- 65
- 1
- 1
- 11
4
votes
6 answers
To mock AWS SES with Sinon
I'm trying to mock SES with Sinon, but facing below error. Tried using aws-sdk-mock, but it's not working.
Error: TypeError: Cannot stub non-existent own property sendEmail
Code snippet of test class:
import * as AWS from 'aws-sdk';
const sandbox…

Abirami
- 223
- 6
- 21
3
votes
1 answer
How to do Parameter Validation while using aws-sdk-mock
I am using aws-sdk-mock with Jest for testing AWS Lamda.
My lambda uses AWS Polly Service to convert text to speech. Following is the piece of code which I want to mock as well as do parameter validation.
var task = await…

Vikas Roy
- 854
- 2
- 10
- 25
3
votes
1 answer
Testing async SQS sendMessage
I have an async lambda, which performs an async SQS sendMessage request. The SQS queue is a standard queue, not FIFO, just to clarify.
Here's an example of code (without irrelevant part of the logic):
exports.functionHandler = async (event, context,…

Salvatore Q Zeroastro
- 758
- 1
- 8
- 17
3
votes
2 answers
Using TypeScript with 'aws-sdk-mock'
So this question was asked and there was an answer here:
Is it possible to use TypeScript with 'aws-sdk-mock'
I don't have enough reputation to ask about the answer, so I had to create another question, because I couldn't get the answer to…

Ben
- 61
- 2
- 4
3
votes
1 answer
Mocking putRecord on firehose not working with aws-sdk-mock
I am trying to mock putRecord method on AWS Firehose object but mocking is not succeeding. The code ends up calling the aws-sdk api on firehose object which talks with live aws service. What is wrong in below code? what needs to be changed to avoid…

mi10
- 213
- 3
- 14
2
votes
1 answer
Does aws-sdk-mock support mocking of AWS SSM (Parameter Store)?
I am trying to mock AWS SSM using aws-sdk-mock with the code below but not working. Does not throw error, fetch the values from Actual store when getParametersByPath is called.
I had a look at the aws-sdk-mock documentation but does not seem to have…

Mandar
- 31
- 1
- 3
2
votes
1 answer
Mocking specific invocation of Lambda Invoke especially when chaining invocations
So I was wondering - been using the aws-sdk-mock library for Node / Jasmine.
This particular library allows you to mock the service method invocations. However this appears to be a problem when attempting to mock a method called more than once, but…

aspiringCoder
- 415
- 1
- 9
- 24
2
votes
0 answers
How can I use node-mocks-http when mocking the AWS SDK?
I've got an existing working test that is testing a route in an Express app (trimmed code):
const AWS = require('aws-sdk-mock');
const AWS_SDK = require('aws-sdk');
AWS.setSDKInstance(AWS_SDK);
...
before(() => {
sendEmailMock =…

jcollum
- 43,623
- 55
- 191
- 321
2
votes
0 answers
aws-sdk-mock not working inside lambda function
So i'm trying to use aws-sdk-mock to mock the calling of a dynamo db and cognito. But it turns out I always fail to mock although when it is called inside the .test.js file is fine. but inside the real lambda function it always call the real…

stephen1706
- 1,010
- 11
- 22
1
vote
0 answers
Jest return mocked value when S3.getObject function is called
I'm totally new to Jest and typescript. my 2nd test case to be honest.
I want in my jest test - when s3.getObject is called in the actual class, it should return the mocked value.
my handler code:
var aws = require("aws-sdk");
var s3 = new…

Lucky
- 783
- 2
- 10
- 28
1
vote
1 answer
How to test aws S3 in mocha
This is my first Mocha/Chai attempt at testing. What would be the best way to do integration testing in mocha with aws S3. I try to mock aws S3 using aws-sdk-mock and sinon but I really don't know how and where to mock this?
Here is my code:
//…

Jayesh Agarwal
- 131
- 10
1
vote
2 answers
aws-sdk-mock - Mocking s3.upload is not using mock implementation
I'm using this wrapper function to upload objects to s3
// upload.js
async function uploadToS3 (body, bucket, key) {
console.log(`Uploading data to s3://${bucket}${key}`)
await s3
.upload({
Body: body,
…

navig8tr
- 1,724
- 8
- 31
- 69