Skip to content
This repository was archived by the owner on Jul 11, 2024. It is now read-only.

Commit d1a46fe

Browse files
chore: add serverless prune plugin (#79)
* chore: add serverless prune plugin * docs: update readme
1 parent df7aef6 commit d1a46fe

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,21 @@ const myFunc = (event, context, callback) => {
146146
export default runWarm(myFunc);
147147
```
148148

149+
### Pruning old versions of deployed functions
150+
151+
The Serverless framework doesn't purge previous versions of functions from AWS, so the number of previous 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) which automatically prunes old versions from AWS. The config for this plugin can be found in `serverless.yml` file. The defaults are:
152+
153+
```yaml
154+
custom:
155+
prune:
156+
automatic: true
157+
number: 5 # Number of versions to keep
158+
```
159+
160+
The above config removes all but the last five stale versions automatically after each deployment.
161+
162+
Go [here](https://medium.com/fluidity/the-dark-side-of-aws-lambda-5c9f620b7dd2) for more on why pruning is useful.
163+
149164
## Environment Variables
150165

151166
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:

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"@types/jest": "^24.0.18",
2626
"@typescript-eslint/eslint-plugin": "^2.2.0",
2727
"@typescript-eslint/parser": "^2.2.0",
28+
"aws-sdk": "^2.529.0",
2829
"babel-core": "^7.0.0-bridge.0",
2930
"babel-jest": "^24.9.0",
3031
"babel-loader": "^8.0.6",
@@ -45,6 +46,7 @@
4546
"serverless-dotenv-plugin": "^2.1.1",
4647
"serverless-offline": "^5.10.1",
4748
"serverless-plugin-warmup": "^4.7.0-rc.1",
49+
"serverless-prune-plugin": "^1.4.1",
4850
"serverless-webpack": "^5.3.1",
4951
"ts-jest": "^24.0.2",
5052
"ts-loader": "^6.1.0",

serverless.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ custom:
4545
- schedule: rate(5 minutes)
4646
prewarm: true
4747
concurrency: 1
48+
prune:
49+
automatic: true
50+
number: 5 # Number of versions to keep
4851

4952
# you can add statements to the Lambda function's IAM Role here
5053
# iamRoleStatements:
@@ -121,3 +124,4 @@ plugins:
121124
- serverless-offline
122125
- serverless-plugin-warmup
123126
- serverless-dotenv-plugin
127+
- serverless-prune-plugin

yarn.lock

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,21 @@ aws-sdk@^2.518.0:
19771977
uuid "3.3.2"
19781978
xml2js "0.4.19"
19791979

1980+
aws-sdk@^2.529.0:
1981+
version "2.529.0"
1982+
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.529.0.tgz#97cc8017fd5d6e3c9270f141cb8efa24796fc9d7"
1983+
integrity sha512-CtRxgI4ZVZ8cdFCddlIVIy06cEW5gzTJBpyouZ/ySgZ6BiYj+0e77LwoNsnQE2nUNWCbydTLn3dbz4ZZMDpuIg==
1984+
dependencies:
1985+
buffer "4.9.1"
1986+
events "1.1.1"
1987+
ieee754 "1.1.8"
1988+
jmespath "0.15.0"
1989+
querystring "0.2.0"
1990+
sax "1.2.1"
1991+
url "0.10.3"
1992+
uuid "3.3.2"
1993+
xml2js "0.4.19"
1994+
19801995
aws-sign2@~0.7.0:
19811996
version "0.7.0"
19821997
resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8"
@@ -2107,7 +2122,7 @@ bl@^1.0.0:
21072122
readable-stream "^2.3.5"
21082123
safe-buffer "^5.1.1"
21092124

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

8309+
serverless-prune-plugin@^1.4.1:
8310+
version "1.4.1"
8311+
resolved "https://registry.yarnpkg.com/serverless-prune-plugin/-/serverless-prune-plugin-1.4.1.tgz#94f43e69989de39647e7dc3e7e0c86db1999aba7"
8312+
integrity sha512-4kXCqdLoAlsQXZPWM2pzZiO0jAqpFQMIoCTkAK4P6JdrMgg8714yAYTzoRD/IZ4f6eS3GLjMoFOCxlrNA9LbKQ==
8313+
dependencies:
8314+
bluebird "^3.4.7"
8315+
82948316
serverless-webpack@^5.3.1:
82958317
version "5.3.1"
82968318
resolved "https://registry.yarnpkg.com/serverless-webpack/-/serverless-webpack-5.3.1.tgz#39c3d0b23f92273702ac418fd33fa7029e085176"

0 commit comments

Comments
 (0)