Upgrade Python runtime in CloudFormation templates
org.openrewrite.python.migrate.UpgradePythonCloudFormationRuntimeArtifactorg.openrewrite.recipe:rewrite-migrate-pythonUpdate 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.
Add to your build
~/.gradle/gradle.properties
codeGenomeUsername=you@example.com
codeGenomeToken=YOUR_DOWNLOAD_TOKEN
build.gradle.kts
plugins {
id("org.openrewrite.rewrite") version("latest.release")
}
rewrite {
activeRecipe("org.openrewrite.python.migrate.UpgradePythonCloudFormationRuntime")
}
repositories {
mavenCentral()
maven {
url = uri("https://artifacts.codegenomeproject.org/maven")
credentials {
username = providers.gradleProperty("codeGenomeUsername").get()
password = providers.gradleProperty("codeGenomeToken").get()
}
}
}
dependencies {
rewrite("org.openrewrite.recipe:rewrite-migrate-python:0.14.0")
}
Then run
./gradlew rewriteRunThis recipe has required options, which a build sets in a rewrite.yml recipe that you activate instead.
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:RELEASEOptions
| Name | Type | Description |
|---|---|---|
versionrequired | String | The 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