1
1
<div align =" center " >
2
2
3
- # ` aws-sdk-mock `
3
+ # aws-sdk-mock
4
4
5
- AWSome mocks for ` JavaScript ` ` aws-sdk ` services.
5
+ AWSome mocks for ` Javascript ` ` aws-sdk ` services.
6
6
7
7
[ ![ GitHub Workflow Status] ( https://img.shields.io/github/actions/workflow/status/dwyl/aws-sdk-mock/ci.yml?label=build&style=flat-square&branch=main )] ( https://github.com/dwyl/aws-sdk-mock/actions/workflows/ci.yml )
8
8
[ ![ codecov.io] ( https://img.shields.io/codecov/c/github/dwyl/aws-sdk-mock/main.svg?style=flat-square )] ( http://codecov.io/github/dwyl/aws-sdk-mock?branch=main )
9
9
[ ![ Known Vulnerabilities] ( https://snyk.io/test/github/dwyl/aws-sdk-mock/badge.svg?targetFile=package.json&style=flat-square )] ( https://snyk.io/test/github/dwyl/aws-sdk-mock?targetFile=package.json )
10
- [ ![ Node.js Version] ( https://img.shields.io/node/v/aws-sdk-mock.svg?style=flat-square " Node.js 18.x, 20.x & 21.x supported ")] ( http://nodejs.org/download/ )
11
10
[ ![ npm package version] ( https://img.shields.io/npm/v/aws-sdk-mock.svg?style=flat-square&color=bright-green )] ( https://www.npmjs.com/package/aws-sdk-mock )
11
+ [ ![ Node.js Version] ( https://img.shields.io/node/v/aws-sdk-mock.svg?style=flat-square " Node.js 18.x, 20.x & 21.x supported ")] ( http://nodejs.org/download/ )
12
12
![ npm monthly downloads] ( https://img.shields.io/npm/dm/aws-sdk-mock?style=flat-square )
13
13
[ ![ HitCount] ( https://hits.dwyl.com/dwyl/aws-sdk-mock.svg?style=flat-square )] ( http://hits.dwyl.com/dwyl/aws-sdk-mock )
14
14
[ ![ contributions welcome] ( https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square )] ( https://github.com/dwyl/aws-sdk-mock/issues )
15
15
16
16
</div >
17
17
18
+
18
19
This module was created to help test AWS Lambda functions but can be used in any situation where the AWS SDK needs to be mocked.
19
20
21
+ This library is best suited for ` AWS SDK for Javascript (v2) ` - see the [ introductory post on the AWS blog] ( https://aws.amazon.com/blogs/developer/mocking-modular-aws-sdk-for-javascript-v3-in-unit-tests/ ) for more context.
22
+ If you are using ` AWS SDK v3 ` you might not _ need_ this library, see:
23
+ [ aws-sdk-mock/issues #209 ] ( https://github.com/dwyl/aws-sdk-mock/issues/209#issuecomment-764841699 )
24
+
25
+
20
26
If you are * new* to Amazon WebServices Lambda
21
27
(* or need a refresher* ),
22
28
please checkout our our
23
29
*** Beginners Guide to AWS Lambda*** :
24
30
< https://github.com/dwyl/learn-aws-lambda >
25
31
32
+
26
33
* [ Why] ( #why )
27
34
* [ What] ( #what )
28
35
* [ Getting Started] ( #how )
@@ -39,6 +46,57 @@ Using stubs means you can prevent a specific method from being called directly.
39
46
40
47
Uses [ Sinon.js] ( https://sinonjs.org/ ) under the hood to mock the AWS SDK services and their associated methods.
41
48
49
+ ## Documentation
50
+
51
+ ### ` AWS.mock(service, method, replace) `
52
+
53
+ Replaces a method on an AWS service with a replacement function or string.
54
+
55
+ | Param | Type | Optional/Required | Description |
56
+ | :------------- | :------------- | :------------- | :------------- |
57
+ | ` service ` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
58
+ | ` method ` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
59
+ | ` replace ` | string or function | Required | A string or function to replace the method |
60
+
61
+ ### ` AWS.restore(service, method) `
62
+
63
+ Removes the mock to restore the specified AWS service
64
+
65
+ | Param | Type | Optional/Required | Description |
66
+ | :------------- | :------------- | :------------- | :------------- |
67
+ | ` service ` | string | Optional | AWS service to restore - If only the service is specified, all the methods are restored |
68
+ | ` method ` | string | Optional | Method on AWS service to restore |
69
+
70
+ If ` AWS.restore ` is called without arguments (` AWS.restore() ` ) then all the services and their associated methods are restored
71
+ i.e. equivalent to a 'restore all' function.
72
+
73
+ ### ` AWS.remock(service, method, replace) `
74
+
75
+ Updates the ` replace ` method on an existing mocked service.
76
+
77
+ | Param | Type | Optional/Required | Description |
78
+ | :------------- | :------------- | :------------- | :------------- |
79
+ | ` service ` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
80
+ | ` method ` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
81
+ | ` replace ` | string or function | Required | A string or function to replace the method |
82
+
83
+ ### ` AWS.setSDK(path) `
84
+
85
+ Explicitly set the require path for the ` aws-sdk `
86
+
87
+ | Param | Type | Optional/Required | Description |
88
+ | :------------- | :------------- | :------------- | :------------- |
89
+ | ` path ` | string | Required | Path to a nested AWS SDK node module |
90
+
91
+ ### ` AWS.setSDKInstance(sdk) `
92
+
93
+ Explicitly set the ` aws-sdk ` instance to use
94
+
95
+ | Param | Type | Optional/Required | Description |
96
+ | :------------- | :------------- | :------------- | :------------- |
97
+ | ` sdk ` | object | Required | The AWS SDK object |
98
+
99
+
42
100
## * How* ? (* Usage* )
43
101
44
102
### * install* ` aws-sdk-mock ` from NPM
@@ -295,56 +353,6 @@ AWS.Promise = Q.Promise;
295
353
**/
296
354
```
297
355
298
- ## Documentation
299
-
300
- ### ` AWS.mock(service, method, replace) `
301
-
302
- Replaces a method on an AWS service with a replacement function or string.
303
-
304
- | Param | Type | Optional/Required | Description |
305
- | :------------- | :------------- | :------------- | :------------- |
306
- | ` service ` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
307
- | ` method ` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
308
- | ` replace ` | string or function | Required | A string or function to replace the method |
309
-
310
- ### ` AWS.restore(service, method) `
311
-
312
- Removes the mock to restore the specified AWS service
313
-
314
- | Param | Type | Optional/Required | Description |
315
- | :------------- | :------------- | :------------- | :------------- |
316
- | ` service ` | string | Optional | AWS service to restore - If only the service is specified, all the methods are restored |
317
- | ` method ` | string | Optional | Method on AWS service to restore |
318
-
319
- If ` AWS.restore ` is called without arguments (` AWS.restore() ` ) then all the services and their associated methods are restored
320
- i.e. equivalent to a 'restore all' function.
321
-
322
- ### ` AWS.remock(service, method, replace) `
323
-
324
- Updates the ` replace ` method on an existing mocked service.
325
-
326
- | Param | Type | Optional/Required | Description |
327
- | :------------- | :------------- | :------------- | :------------- |
328
- | ` service ` | string | Required | AWS service to mock e.g. SNS, DynamoDB, S3 |
329
- | ` method ` | string | Required | method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB' |
330
- | ` replace ` | string or function | Required | A string or function to replace the method |
331
-
332
- ### ` AWS.setSDK(path) `
333
-
334
- Explicitly set the require path for the ` aws-sdk `
335
-
336
- | Param | Type | Optional/Required | Description |
337
- | :------------- | :------------- | :------------- | :------------- |
338
- | ` path ` | string | Required | Path to a nested AWS SDK node module |
339
-
340
- ### ` AWS.setSDKInstance(sdk) `
341
-
342
- Explicitly set the ` aws-sdk ` instance to use
343
-
344
- | Param | Type | Optional/Required | Description |
345
- | :------------- | :------------- | :------------- | :------------- |
346
- | ` sdk ` | object | Required | The AWS SDK object |
347
-
348
356
## Background Reading
349
357
350
358
* [ Mocking using Sinon.js] ( http://sinonjs.org/docs/ )
0 commit comments