Skip to content

Commit

Permalink
Merge pull request #1 from superandrew213/remove-bluebird-dependency
Browse files Browse the repository at this point in the history
Remove bluebird dependency
  • Loading branch information
jeremydaly committed Jul 15, 2018
2 parents 4b61398 + da83b7f commit 1fadb47
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ He also mentioned that if you want to keep several concurrent functions warm, th

You can read the key takeaways from his talk [here](https://www.jeremydaly.com/15-key-takeaways-from-the-serverless-talk-at-aws-startup-day/).

Following these "best practices", I created **Lambda Warmer**. It is a lightweight module that can be added to your Lambda functions to manage "warming" events as well as handling automatic fan-out for initializing *concurrent functions*. Just instrument your code and schedule your CloudWatch Events.
Following these "best practices", I created **Lambda Warmer**. It is a lightweight module (no dependencies) that can be added to your Lambda functions to manage "warming" events as well as handling automatic fan-out for initializing *concurrent functions*. Just instrument your code and schedule your CloudWatch Events.

**NOTE:** Lambda Warmer will invoke the function multiple times using the AWS-SDK in order to scale concurrency (if you want to). Your functions MUST have `lambda:InvokeFunction` permissions so that they can invoke themselves. Following the Principle of Least Privilege, you should limit the `Resource` to the function itself, e.g.:

Expand All @@ -31,7 +31,7 @@ Following these "best practices", I created **Lambda Warmer**. It is a lightweig

## Installation

Install Lambda Warmer from NPM as a project dependency. Lambda Warmer uses Bluebird as its only dependency to manage delays.
Install Lambda Warmer from NPM as a project dependency.

```
npm i lambda-warmer
Expand Down
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
* @license MIT
*/

const Promise = require('bluebird')

const id = Date.now().toString() + '-' + ('0000' + Math.floor(Math.random()*1000).toString()).substr(-4)

let warm = false
let lastAccess = null

const funcName = process.env.AWS_LAMBDA_FUNCTION_NAME

const delay = ms => new Promise(res => setTimeout(res, ms))

module.exports = (event,cfg = {}) => {

let config = Object.assign({}, {
Expand Down Expand Up @@ -100,7 +100,7 @@ module.exports = (event,cfg = {}) => {
.then((res) => true)

} else if (invokeCount > 1) {
return Promise.delay(config.delay).then(() => true)
return delay(config.delay).then(() => true)
}

return Promise.resolve(true)
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
},
"homepage": "https://github.com/jeremydaly/lambda-warmer#readme",
"dependencies": {
"bluebird": "^3.5.1"
},
"devDependencies": {
"aws-sdk": "^2.273.1",
Expand Down

0 comments on commit 1fadb47

Please sign in to comment.