Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add serverless prune plugin #79

Merged
merged 3 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,21 @@ const myFunc = (event, context, callback) => {
export default runWarm(myFunc);
```

### Pruning old versions of deployed functions

The Serverless framework doesn't purge previous versions of functions from AWS, so the number of deployed versions can grow out of hand and eventually filling up your code storage. This starter kit includes [serverless-prune-plugin](https://github.com/claygregory/serverless-prune-plugin) that allows pruning these old versions from AWS automatically. The config for this plugin can be found in `serverless.yml` file:
WajeehZantout marked this conversation as resolved.
Show resolved Hide resolved

```yaml
custom:
prune:
automatic: true
number: 5 # Number of versions to keep
```

The above config allows the removal of all stale versions, except for the last 5, automatically after each deployment.
WajeehZantout marked this conversation as resolved.
Show resolved Hide resolved

For further explanation of why this plugin is useful, check this [article](https://medium.com/fluidity/the-dark-side-of-aws-lambda-5c9f620b7dd2).
WajeehZantout marked this conversation as resolved.
Show resolved Hide resolved

## Environment Variables

If you have environment variables stored in a `.env` file, you can reference them inside your `serverless.yml` and inside your functions. Considering you have a `NAME` variable:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@types/jest": "^24.0.18",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/parser": "^2.2.0",
"aws-sdk": "^2.529.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.9.0",
"babel-loader": "^8.0.6",
Expand All @@ -45,6 +46,7 @@
"serverless-dotenv-plugin": "^2.1.1",
"serverless-offline": "^5.10.1",
"serverless-plugin-warmup": "^4.7.0-rc.1",
"serverless-prune-plugin": "^1.4.1",
"serverless-webpack": "^5.3.1",
"ts-jest": "^24.0.2",
"ts-loader": "^6.1.0",
Expand Down
4 changes: 4 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ custom:
- schedule: rate(5 minutes)
prewarm: true
concurrency: 1
prune:
automatic: true
number: 5 # Number of versions to keep

# you can add statements to the Lambda function's IAM Role here
# iamRoleStatements:
Expand Down Expand Up @@ -121,3 +124,4 @@ plugins:
- serverless-offline
- serverless-plugin-warmup
- serverless-dotenv-plugin
- serverless-prune-plugin
24 changes: 23 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,21 @@ aws-sdk@^2.518.0:
uuid "3.3.2"
xml2js "0.4.19"

aws-sdk@^2.529.0:
version "2.529.0"
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.529.0.tgz#97cc8017fd5d6e3c9270f141cb8efa24796fc9d7"
integrity sha512-CtRxgI4ZVZ8cdFCddlIVIy06cEW5gzTJBpyouZ/ySgZ6BiYj+0e77LwoNsnQE2nUNWCbydTLn3dbz4ZZMDpuIg==
dependencies:
buffer "4.9.1"
events "1.1.1"
ieee754 "1.1.8"
jmespath "0.15.0"
querystring "0.2.0"
sax "1.2.1"
url "0.10.3"
uuid "3.3.2"
xml2js "0.4.19"

aws-sign2@~0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
Expand Down Expand Up @@ -2107,7 +2122,7 @@ bl@^1.0.0:
readable-stream "^2.3.5"
safe-buffer "^5.1.1"

bluebird@^3.5.4, bluebird@^3.5.5:
bluebird@^3.4.7, bluebird@^3.5.4, bluebird@^3.5.5:
version "3.5.5"
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f"
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==
Expand Down Expand Up @@ -8291,6 +8306,13 @@ serverless-plugin-warmup@^4.7.0-rc.1:
dependencies:
fs-extra "^8.0.1"

serverless-prune-plugin@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/serverless-prune-plugin/-/serverless-prune-plugin-1.4.1.tgz#94f43e69989de39647e7dc3e7e0c86db1999aba7"
integrity sha512-4kXCqdLoAlsQXZPWM2pzZiO0jAqpFQMIoCTkAK4P6JdrMgg8714yAYTzoRD/IZ4f6eS3GLjMoFOCxlrNA9LbKQ==
dependencies:
bluebird "^3.4.7"

serverless-webpack@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/serverless-webpack/-/serverless-webpack-5.3.1.tgz#39c3d0b23f92273702ac418fd33fa7029e085176"
Expand Down