Skip to content

serverless.star

Move Serverless Framework services to a new Lambda runtime.

AWS retires Lambda runtimes on a schedule, so this is a recurring fleet-wide change. Edits are line-based, so comments and variables in serverless.yml stay as they were.

load("@fleet//serverless.star", "files", "set_runtime")
Function What it does
files Lists the repo's Serverless configs.
set_runtime Sets the Lambda runtime of the provider and of every function that overrides it.

files

files(repo)

Lists the repo's Serverless configs.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: The sorted paths of every serverless.yml and serverless.yaml outside node_modules.

Example

files(repo)
# returns ["serverless.yml", "services/jobs/serverless.yaml"]

serverless.yml

service: api

services/jobs/serverless.yaml

service: jobs

Source

set_runtime

set_runtime(repo, runtime, from_runtime = None)

Sets the Lambda runtime of the provider and of every function that overrides it.

Arguments

Name Description
repo The repo passed to change(repo).
runtime The new runtime, such as nodejs20.x or python3.12.
from_runtime When set, only this runtime is replaced, so functions on other languages stay as they are.

Returns: The list of paths that changed.

Example

set_runtime(repo, "nodejs20.x", from_runtime = "nodejs16.x")
# returns ["serverless.yml"]

serverless.yml

service: api
provider:
  name: aws
  runtime: nodejs16.x  # retired
functions:
  hello:
    handler: handler.hello
  report:
    handler: report.main
    runtime: python3.12

serverless.yml

service: api
provider:
  name: aws
  runtime: nodejs20.x  # retired
functions:
  hello:
    handler: handler.hello
  report:
    handler: report.main
    runtime: python3.12

Used in: serverless-runtime

Source