https://github.com/serverless/aws-event-mocks
https://github.com/serverless/aws-event-mocks
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/serverless/aws-event-mocks
- Owner: serverless
- License: other
- Created: 2016-09-28T06:07:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-12T05:47:30.000Z (over 5 years ago)
- Last Synced: 2025-04-18T07:51:31.543Z (about 2 months ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 84
- Watchers: 27
- Forks: 20
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: code_of_conduct.md
Awesome Lists containing this project
README
# AWS Event Mocks
A small library that includes details mocks of AWS Lambda event sources. Useful for use when unit testing your Lambda functions. Supported Event Sources are: SNS, API Gateway, S3, & Scheduled.The library simply uses default event source mock templates and merge it with any overwrite you provide. [Check out the JSON template files](/events) to learn more about the data structure of each event source.
## Usage
### SNS
```js
const createEvent = require('aws-event-mocks');
const mocked = createEvent({
template: 'aws:sns',
merge: {
Records: [{
Sns: {
Message: 'trigger-email'
}
}]
}
});
```### API Gateway
```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:apiGateway',
merge: {
body: {
first_name: 'Sam',
last_name: 'Smith'
}
}
});
```### S3
```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:s3',
merge: {
Records: [{
eventName: 'ObjectCreated:Put',
s3: {
bucket: {
name: 'my-bucket-name'
},
object: {
key: 'object-key'
}
}
}]
}
});
```### Scheduled
```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:scheduled',
merge: {
region: 'us-west-2'
}
});
```### Kinesis
```js
const createEvent = require('aws-event-mocks');
const event = createEvent({
template: 'aws:kinesis',
merge: {
data: new Buffer('this is test data').toString('base64')
}
});