aws-lambda-mock-context
Advanced tools
Comparing version 1.0.0 to 1.1.0
25
index.js
@@ -7,19 +7,28 @@ 'use strict'; | ||
var defer = require('pinkie-defer'); | ||
var objectAssign = require('object-assign'); | ||
var pkg = require('./package.json'); | ||
module.exports = function () { | ||
module.exports = function (opts) { | ||
var id = uuid.v1(); | ||
var stream = uuid.v4().replace(/-/g, ''); | ||
var account = uuid.v1().replace(/-/g, '').substr(0, 12); | ||
opts = objectAssign({ | ||
region: 'us-west-1', | ||
account: '123456789012', | ||
functionName: pkg.name, | ||
functionVersion: '$LATEST', | ||
memoryLimitInMB: '128' | ||
}, opts); | ||
var deferred = defer(); | ||
return { | ||
functionName: pkg.name, | ||
functionVersion: '$LATEST', | ||
invokedFunctionArn: format('arn:aws:lambda:us-west-1:%s:function:%s', account, pkg.name), | ||
memoryLimitInMB: '128', | ||
functionName: opts.functionName, | ||
functionVersion: opts.functionVersion, | ||
invokedFunctionArn: format('arn:aws:lambda:%s:%s:function:%s:%s', opts.region, opts.account, opts.functionName, opts.alias || opts.functionVersion), | ||
memoryLimitInMB: opts.memoryLimitInMB, | ||
awsRequestId: id, | ||
logGroupName: format('/aws/lambda/%s', pkg.name), | ||
logStreamName: format('%s/[$LATEST]/%s', moment().format('YYYY/MM/DD'), stream), | ||
invokeid: id, | ||
logGroupName: format('/aws/lambda/%s', opts.functionName), | ||
logStreamName: format('%s/[%s]/%s', moment().format('YYYY/MM/DD'), opts.functionVersion, stream), | ||
succeed: function (result) { | ||
@@ -26,0 +35,0 @@ deferred.resolve(result); |
{ | ||
"name": "aws-lambda-mock-context", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "AWS Lambda mock context object", | ||
@@ -17,3 +17,7 @@ "main": "index.js", | ||
"context", | ||
"mock" | ||
"ctx", | ||
"function", | ||
"mocking", | ||
"mock", | ||
"promise" | ||
], | ||
@@ -32,2 +36,3 @@ "files": [ | ||
"node-uuid": "^1.4.3", | ||
"object-assign": "^4.0.1", | ||
"pinkie-defer": "^1.0.0", | ||
@@ -39,8 +44,3 @@ "pinkie-promise": "^1.0.0" | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"ignores": [ | ||
"test.js" | ||
] | ||
} | ||
} |
@@ -8,3 +8,3 @@ # aws-lambda-mock-context [![Build Status](https://travis-ci.org/SamVerschueren/aws-lambda-mock-context.svg?branch=master)](https://travis-ci.org/SamVerschueren/aws-lambda-mock-context) | ||
```bash | ||
``` | ||
npm install --save aws-lambda-mock-context | ||
@@ -17,5 +17,5 @@ ``` | ||
```js | ||
var context = require('aws-lambda-mock-context'); | ||
const context = require('aws-lambda-mock-context'); | ||
var ctx = context(); | ||
const ctx = context(); | ||
@@ -25,6 +25,6 @@ index.handler({hello: 'world'}, ctx); | ||
ctx.Promise | ||
.then(function () { | ||
.then(() => { | ||
//=> succeed() called | ||
}) | ||
.catch(function (err) { | ||
.catch(err => { | ||
//=> fail() called | ||
@@ -35,2 +35,50 @@ }); | ||
## API | ||
### context(options) | ||
#### options | ||
##### region | ||
Type: `string` | ||
Default: `us-west-1` | ||
The AWS region. | ||
##### account | ||
Type: `string` | ||
Default: `123456789012` | ||
The account number. | ||
##### functionName | ||
Type: `string` | ||
Default: `aws-lambda-mock-context` | ||
The name of the function. | ||
##### functionVersion | ||
Type: `string` | ||
Default: `$LATEST` | ||
The version of the function. | ||
##### memoryLimitInMB | ||
Type: `string` | ||
Default: `128` | ||
The memory limit. | ||
##### alias | ||
Type: `string` | ||
The alias of the function. | ||
## Related | ||
@@ -37,0 +85,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4631
16034
46
88
5
+ Addedobject-assign@^4.0.1
+ Addedobject-assign@4.1.1(transitive)