← All recipes
Moderne licensed

Upgrade Python runtime in CloudFormation templates

Recipe IDorg.openrewrite.python.migrate.UpgradePythonCloudFormationRuntime
Artifactorg.openrewrite.recipe:rewrite-migrate-python

Update Python Lambda runtimes in CloudFormation and SAM templates to a target version. Bumps Runtime: python3.x properties (AWS::Lambda::Function, AWS::Serverless::Function, and the SAM Globals section) and python3.x entries in CompatibleRuntimes lists of Lambda layer versions. Indirection is followed: a YAML anchor aliased from a runtime value is bumped where it is defined, and a parameter referenced from a runtime value (!Ref or Ref:) has its Default and any AllowedValues bumped. Templates are recognized by content — AWSTemplateFormatVersion, an AWS:: Transform, or Resources with AWS:: resource types — so any YAML template is updated regardless of its file name or location. Only runtimes older than the target are changed; a runtime already on a newer version is left as-is.

Single recipeProprietary

Usage

You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.python.migrate.UpgradePythonCloudFormationRuntime --recipe-option "version=3.12"

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-migrate-python:0.11.0

Options

NameTypeDescription
versionrequiredStringThe target Python version as MAJOR.MINOR (for example 3.12). Any patch component is dropped; the minor release is the upgrade target.
e.g. 3.12

Data tables

Structured output this recipe can produce.

  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats