logo

⚡️ serverless-provisioned-concurrency-autoscaling

npm build license pr Known Vulnerabilities

Serverless Plugin for AWS Lambda Provisioned Concurrency Auto Scaling configuration.

Related blog post can be found on the Neiman Marcus Medium page.

Usage

Add the NPM package to your project:

$ npm install serverless-provisioned-concurrency-autoscaling

Add the plugin to your serverless.yml:

Use version 1.9.1 for Serverless 1/ Serverless 2.

Use version 2.0.1 for Serverless 3.

plugins:
- serverless-provisioned-concurrency-autoscaling

Configuration

Add concurrencyAutoscaling parameters under each function you wish to autoscale in your serverless.yml.

Add customMetric: true if you want to use Maximum instead of Average statistic.

Minimal Configuration

functions:
hello:
handler: handler.hello
provisionedConcurrency: 1
concurrencyAutoscaling: true

Full Configuration

functions:
world:
handler: handler.world
provisionedConcurrency: 1
concurrencyAutoscaling:
enabled: true
alias: provisioned
maximum: 10
minimum: 1
usage: 0.75
scaleInCooldown: 0
scaleOutCooldown: 0
customMetric:
statistic: maximum
scheduledActions:
- name: OpenOfficeTime
startTime: "2025-01-01T00:00:00.000Z"
endTime: "2025-01-01T23:59:59.999Z"
timezone: "America/Chicago"
schedule: "cron(30 8 ? * 1-6 *)"
action:
maximum: 100
minimum: 10
- name: CloseOfficeTime
startTime: "2025-01-01T00:00:00.000Z"
endTime: "2025-01-01T23:59:59.999Z"
timezone: "America/Chicago"
schedule: "cron(30 17 ? * 1-6 *)"
action:
maximum: 10
minimum: 1
- name: BlackFridayPeak1
startTime: "2025-01-02T00:00:00.000Z"
endTime: "2025-01-02T23:59:59.999Z"
timezone: "America/New_York"
schedule: "at(2025-01-02T12:34:56)"
action:
maximum: 50
minimum: 5
- name: BlackFridayPeak2
startTime: "2025-01-03T00:00:00.000Z"
endTime: "2025-01-03T23:59:59.999Z"
timezone: "Europe/Warsaw"
schedule: "rate(1 hour)"
action:
maximum: 50
minimum: 5

That's it! With the next deployment, serverless will add Cloudformation resources to scale provisioned concurrency!

You must provide at least provisionedConcurrency and concurrencyAutoscaling to enable autoscaling. Set concurrencyAutoscaling to a boolean, or object with configuration. Any omitted configuration will use module defaults.

Defaults

alias: provisioned
maximum: 10
minimum: 1
usage: 0.75
scaleInCooldown: 0
scaleOutCooldown: 0

Change in Default Behavior: Starting in v1.7.0, the default scaleInCooldown is zero, not 120. This is backwards compatible, but different default behavior. This is in line with AWS' default scaleInCooldown.

Scheduled Actions

For more details on Scheduled Actions formats see the AWS CloudFormation ScheduledAction description.

Description of scheduledActions's properties:

AttributeDescriptionRequiredExample
endTimeThe date and time that the action is scheduled to end, in UTC.no2025-12-31T23:59:59.999Z
startTimeThe date and time that the action is scheduled to begin, in UTC.no2025-01-01T00:00:00.000Z
timezoneTimezone for startTime and endTime. Needs to be the canonical names of the IANA (supported by Yoda-Time).noAmerica/Chicago
nameThe name of the scheduled action unique among all other scheduled actions on the specified scalable target.yesOpenOfficeHourScheduleStart
scheduleOne of three string formats: at, cron or rate (see next table).yescron(* 30 8 * 1-6 *)
actionObject of minimum and maximum properties. At least one is required.yesminimum: 100
maximum: 105

Description of schedule's properties:

For more details on schedule syntax see:

AttributeDescriptionFormatExample
atA start (a point in time)at(yyyy-mm-ddThh:mm:ss)at(2025-01-02T00:00:00)
cronA cron syntax for recurring schedulecron(fields)cron(30 17 ? * 1-6 *)
rateA raterate(value unit)rate(16 minuets)

Known Issues/Limitations

N/A

Authors

Contributors

Conduct / Contributing / License

  • Refer to our contribution guidelines to contribute to this project. See CONTRIBUTING.md.
  • All contributions must follow our code of conduct. See CONDUCT.md.
  • This project is licensed under the Apache 2.0 license. See LICENSE.

Acknowledgments