From da099e46d76d697a87071dcfa5293b505d86edf1 Mon Sep 17 00:00:00 2001 From: Piotr Roszatycki Date: Thu, 12 Nov 2026 18:26:44 +0100 Subject: [PATCH] Examples of Lambda: the public layers of a version of Pyjoyment, with the variable pyjoyment_version The variable takes the layers of the latest release of Pyjoyment-Lambda-Layers whose tag has the version, as pyjoyment-0_3_0-python3_15, and in lambda_zip the layer of Python of the same release, and without it the aliases of the index of the latest release, as before. The cookbook and the skill deploy name the layers with the version of Pyjoyment. Closes #562 Co-Authored-By: Claude Opus 5.5 --- docs/guides/cookbook.rst | 19 ++++++--- examples/lambda/README.md | 8 ++++ examples/lambda/function.tf | 2 +- examples/lambda/layers.tf | 51 ++++++++++++++++++++++-- examples/lambda/variables.tf | 6 +++ examples/lambda_stream/README.md | 8 ++++ examples/lambda_stream/function.tf | 2 +- examples/lambda_stream/layers.tf | 51 ++++++++++++++++++++++-- examples/lambda_stream/variables.tf | 6 +++ examples/lambda_zip/README.md | 9 +++++ examples/lambda_zip/function.tf | 2 +- examples/lambda_zip/layers.tf | 51 ++++++++++++++++++++++-- examples/lambda_zip/variables.tf | 6 +++ plugins/pyjoyment/skills/deploy/SKILL.md | 11 +++-- 14 files changed, 208 insertions(+), 24 deletions(-) diff --git a/docs/guides/cookbook.rst b/docs/guides/cookbook.rst index 77eddda4..c0861b38 100644 --- a/docs/guides/cookbook.rst +++ b/docs/guides/cookbook.rst @@ -1172,8 +1172,9 @@ layers, built by the same generator, as public layers of the account ``959435416781`` in the commercial regions of AWS: of Python, as ``python3_14-arm64`` or ``python3_15t-x86_64``, of one version and one architecture, for ``provided.al2023``, and of Pyjoyment, as -``pyjoyment-python3_14``, for both architectures, with the layer of Python or -on the runtime ``python3.14``. With ``--function-only``, the generator writes +``pyjoyment-0_3_0-python3_14`` of Pyjoyment 0.3.0, for both architectures, +with the layer of Python or on the runtime ``python3.14``. With +``--function-only``, the generator writes ``function.zip`` alone, for them, and tells the version of Pyjoyment of the dependencies of the application, which the description of the layer of Pyjoyment says too. The layer of Pyjoyment has `Pyjo-AWS @@ -1193,10 +1194,14 @@ namespace ``Pyjo``, as ``Pyjo-MCP``, stays in the function. [write] /home/sri/myapp/dist/function.zip A function takes a layer by the ARN of a version, as -``arn:aws:lambda::959435416781:layer:pyjoyment-python3_14:``, +``arn:aws:lambda::959435416781:layer:pyjoyment-0_3_0-python3_14:``, which the index of the layers of each release, ``layers.json``, gives as -``{layer: {region: arn}}``. The index of the latest release is always at the -same URL, which a one-liner reads with a JSON Pointer. +``{layer: {region: arn}}``. A release has the layers of one version of +Pyjoyment, which come after the release of Pyjoyment, and its tag has the +version and the date, as ``0.3.0+2026.11.05``. Its index has the same layers +under the names without the version too, as ``pyjoyment-python3_14``, so that +the index of the latest release, which is always at the same URL, gives the +layers of the latest Pyjoyment, which a one-liner reads with a JSON Pointer. .. code-block:: console @@ -1206,7 +1211,9 @@ The directories `examples/lambda `_ and `examples/lambda_zip `_ of the -repository deploy such functions with OpenTofu. +repository deploy such functions with OpenTofu, with the layers of the latest +release, or of the latest release of a version of Pyjoyment, as the one that +``--function-only`` tells, of the variable ``pyjoyment_version``. The same function runs locally, mounted in an application with :mod:`Pyjo.App.Lambda`, in a process of its own, which gets its invocations diff --git a/examples/lambda/README.md b/examples/lambda/README.md index d7b0cf05..10db0aca 100644 --- a/examples/lambda/README.md +++ b/examples/lambda/README.md @@ -55,6 +55,14 @@ the version of Pyjoyment of the dependencies, which the description of the layer says too: the inline metadata of the script takes Pyjoyment of the checkout, which can be newer than the one of the latest release. +`-var pyjoyment_version=0.3.0` takes the layer of the latest release of that +version of Pyjoyment, `pyjoyment-0_3_0-python3_15`, for a function of the +checkout of an older version. Its release is the latest one whose tag has the +version and the date, as `0.3.0+2026.11.05`, in the list of the API of GitHub, +which answers 60 requests an hour of an address without a token. The layers of +a version come after its release, so the checkout of a version that is not +released yet takes the layers of its own build. + `-var public_layers=false` takes the layer of the build in the place of the public one, which the generator writes without `--function-only`: diff --git a/examples/lambda/function.tf b/examples/lambda/function.tf index d0a6997e..288d1adb 100644 --- a/examples/lambda/function.tf +++ b/examples/lambda/function.tf @@ -26,7 +26,7 @@ resource "aws_lambda_layer_version" "pyjoyment" { locals { pyjoyment_layer = ( var.pyjoyment_layer != null ? var.pyjoyment_layer - : var.public_layers ? local.public_layers["pyjoyment-${local.python_name}"][data.aws_region.current.region] + : var.public_layers ? local.public_layers[local.pyjoyment_name][data.aws_region.current.region] : aws_lambda_layer_version.pyjoyment.arn ) } diff --git a/examples/lambda/layers.tf b/examples/lambda/layers.tf index c5738b4f..0aaf07ef 100644 --- a/examples/lambda/layers.tf +++ b/examples/lambda/layers.tf @@ -1,15 +1,58 @@ -# The index of the public layers of the latest release of Pyjoyment-Lambda-Layers, {layer: {region: arn}}, behind a -# redirection of GitHub, which the provider follows +# The releases of Pyjoyment-Lambda-Layers, for the public layers of a version of Pyjoyment, whose tags have the version +# and the date, as 0.3.0+2026.11.05, as GitHub has no latest release of a prefix. The API of GitHub answers 60 requests +# an hour of an address without a token, and 100 releases at most, in an order of its own +data "http" "releases" { + url = "https://api.github.com/repos/pyjoyment/Pyjoyment-Lambda-Layers/releases?per_page=100" + + request_headers = { + Accept = "application/vnd.github+json" + } + + lifecycle { + enabled = var.public_layers && var.pyjoyment_version != null + + postcondition { + condition = self.status_code == 200 + error_message = "The API of GitHub answers ${self.status_code}: ${self.response_body}" + } + } +} + +# The tag of the latest release of the version, the last of its releases sorted by the time of their publication +locals { + releases = var.public_layers && var.pyjoyment_version != null ? sort([ + for release in jsondecode(data.http.releases.response_body) : "${release.published_at} ${release.tag_name}" + if startswith(release.tag_name, "${var.pyjoyment_version}+") + ]) : [] + release = length(local.releases) > 0 ? split(" ", local.releases[length(local.releases) - 1])[1] : null +} + +# The index of the public layers of the release, {layer: {region: arn}}, or of the latest release, behind a redirection +# of GitHub, which the provider follows data "http" "layers" { - url = "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json" + url = ( + local.release != null + ? "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/download/${urlencode(local.release)}/layers.json" + : "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json" + ) lifecycle { enabled = var.public_layers + + precondition { + condition = var.pyjoyment_version == null || local.release != null + error_message = "No release of Pyjoyment-Lambda-Layers of the latest 100 has the layers of the version of Pyjoyment, which come after its release. The variable \"public_layers\" set to false takes the layers of the build." + } } } -# The layer of Pyjoyment of the version of Python of the runtime, as pyjoyment-python3_14 +# The layer of Pyjoyment of the version of Python of the runtime, as pyjoyment-0_3_0-python3_14 of a version of +# Pyjoyment, or its alias pyjoyment-python3_14 in the index of the latest release locals { public_layers = var.public_layers ? jsondecode(data.http.layers.response_body) : {} python_name = replace(var.runtime, ".", "_") + pyjoyment_name = ( + var.pyjoyment_version != null ? "pyjoyment-${replace(var.pyjoyment_version, ".", "_")}-${local.python_name}" + : "pyjoyment-${local.python_name}" + ) } diff --git a/examples/lambda/variables.tf b/examples/lambda/variables.tf index e0dd516e..cc2ae252 100644 --- a/examples/lambda/variables.tf +++ b/examples/lambda/variables.tf @@ -28,6 +28,12 @@ variable "public_layers" { default = true } +variable "pyjoyment_version" { + description = "The version of Pyjoyment of the public layers, as \"0.3.0\", the one that \"--function-only\" tells, or the latest one" + type = string + default = null +} + variable "multi_value_headers" { description = "Whether the load balancer sends the headers and the parameters of the query with all their values" type = bool diff --git a/examples/lambda_stream/README.md b/examples/lambda_stream/README.md index bc4c4ea6..615e631b 100644 --- a/examples/lambda_stream/README.md +++ b/examples/lambda_stream/README.md @@ -66,6 +66,14 @@ the version of Pyjoyment of the dependencies, which the description of the layer says too: the inline metadata of the script takes Pyjoyment of the checkout, which can be newer than the one of the latest release. +`-var pyjoyment_version=0.3.0` takes the layer of the latest release of that +version of Pyjoyment, `pyjoyment-0_3_0-python3_15`, for a function of the +checkout of an older version. Its release is the latest one whose tag has the +version and the date, as `0.3.0+2026.11.05`, in the list of the API of GitHub, +which answers 60 requests an hour of an address without a token. The layers of +a version come after its release, so the checkout of a version that is not +released yet takes the layers of its own build. + `-var public_layers=false` takes the layer of the build in the place of the public one, which the generator writes without `--function-only`: diff --git a/examples/lambda_stream/function.tf b/examples/lambda_stream/function.tf index b1ef3f68..1866d1cc 100644 --- a/examples/lambda_stream/function.tf +++ b/examples/lambda_stream/function.tf @@ -26,7 +26,7 @@ resource "aws_lambda_layer_version" "pyjoyment" { locals { pyjoyment_layer = ( var.pyjoyment_layer != null ? var.pyjoyment_layer - : var.public_layers ? local.public_layers["pyjoyment-${local.python_name}"][data.aws_region.current.region] + : var.public_layers ? local.public_layers[local.pyjoyment_name][data.aws_region.current.region] : aws_lambda_layer_version.pyjoyment.arn ) } diff --git a/examples/lambda_stream/layers.tf b/examples/lambda_stream/layers.tf index c5738b4f..0aaf07ef 100644 --- a/examples/lambda_stream/layers.tf +++ b/examples/lambda_stream/layers.tf @@ -1,15 +1,58 @@ -# The index of the public layers of the latest release of Pyjoyment-Lambda-Layers, {layer: {region: arn}}, behind a -# redirection of GitHub, which the provider follows +# The releases of Pyjoyment-Lambda-Layers, for the public layers of a version of Pyjoyment, whose tags have the version +# and the date, as 0.3.0+2026.11.05, as GitHub has no latest release of a prefix. The API of GitHub answers 60 requests +# an hour of an address without a token, and 100 releases at most, in an order of its own +data "http" "releases" { + url = "https://api.github.com/repos/pyjoyment/Pyjoyment-Lambda-Layers/releases?per_page=100" + + request_headers = { + Accept = "application/vnd.github+json" + } + + lifecycle { + enabled = var.public_layers && var.pyjoyment_version != null + + postcondition { + condition = self.status_code == 200 + error_message = "The API of GitHub answers ${self.status_code}: ${self.response_body}" + } + } +} + +# The tag of the latest release of the version, the last of its releases sorted by the time of their publication +locals { + releases = var.public_layers && var.pyjoyment_version != null ? sort([ + for release in jsondecode(data.http.releases.response_body) : "${release.published_at} ${release.tag_name}" + if startswith(release.tag_name, "${var.pyjoyment_version}+") + ]) : [] + release = length(local.releases) > 0 ? split(" ", local.releases[length(local.releases) - 1])[1] : null +} + +# The index of the public layers of the release, {layer: {region: arn}}, or of the latest release, behind a redirection +# of GitHub, which the provider follows data "http" "layers" { - url = "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json" + url = ( + local.release != null + ? "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/download/${urlencode(local.release)}/layers.json" + : "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json" + ) lifecycle { enabled = var.public_layers + + precondition { + condition = var.pyjoyment_version == null || local.release != null + error_message = "No release of Pyjoyment-Lambda-Layers of the latest 100 has the layers of the version of Pyjoyment, which come after its release. The variable \"public_layers\" set to false takes the layers of the build." + } } } -# The layer of Pyjoyment of the version of Python of the runtime, as pyjoyment-python3_14 +# The layer of Pyjoyment of the version of Python of the runtime, as pyjoyment-0_3_0-python3_14 of a version of +# Pyjoyment, or its alias pyjoyment-python3_14 in the index of the latest release locals { public_layers = var.public_layers ? jsondecode(data.http.layers.response_body) : {} python_name = replace(var.runtime, ".", "_") + pyjoyment_name = ( + var.pyjoyment_version != null ? "pyjoyment-${replace(var.pyjoyment_version, ".", "_")}-${local.python_name}" + : "pyjoyment-${local.python_name}" + ) } diff --git a/examples/lambda_stream/variables.tf b/examples/lambda_stream/variables.tf index 9cf5608f..91e0a26f 100644 --- a/examples/lambda_stream/variables.tf +++ b/examples/lambda_stream/variables.tf @@ -27,3 +27,9 @@ variable "public_layers" { type = bool default = true } + +variable "pyjoyment_version" { + description = "The version of Pyjoyment of the public layers, as \"0.3.0\", the one that \"--function-only\" tells, or the latest one" + type = string + default = null +} diff --git a/examples/lambda_zip/README.md b/examples/lambda_zip/README.md index 28a7590c..9d3da31f 100644 --- a/examples/lambda_zip/README.md +++ b/examples/lambda_zip/README.md @@ -61,6 +61,15 @@ description of the layer of Pyjoyment says too: the inline metadata of the script takes Pyjoyment of the checkout, which can be newer than the one of the latest release. +`-var pyjoyment_version=0.3.0` takes the layers of the latest release of that +version of Pyjoyment, `pyjoyment-0_3_0-python3_15` and the layer of Python of +the same release, for a function of the checkout of an older version. Its +release is the latest one whose tag has the version and the date, as +`0.3.0+2026.11.05`, in the list of the API of GitHub, which answers 60 requests +an hour of an address without a token. The layers of a version come after its +release, so the checkout of a version that is not released yet takes the layers +of its own build. + `-var public_layers=false` takes the layers of the build in the place of the public ones, which the generator writes without `--function-only`, with the Python that runs it, or the one of `--python`: diff --git a/examples/lambda_zip/function.tf b/examples/lambda_zip/function.tf index 4d20f7fb..828d660d 100644 --- a/examples/lambda_zip/function.tf +++ b/examples/lambda_zip/function.tf @@ -45,7 +45,7 @@ locals { ) pyjoyment_layer = ( var.pyjoyment_layer != null ? var.pyjoyment_layer - : var.public_layers ? local.public_layers["pyjoyment-${local.python_name}"][local.region] + : var.public_layers ? local.public_layers[local.pyjoyment_name][local.region] : aws_lambda_layer_version.pyjoyment.arn ) } diff --git a/examples/lambda_zip/layers.tf b/examples/lambda_zip/layers.tf index 01c2d1af..dc47ad95 100644 --- a/examples/lambda_zip/layers.tf +++ b/examples/lambda_zip/layers.tf @@ -1,15 +1,58 @@ -# The index of the public layers of the latest release of Pyjoyment-Lambda-Layers, {layer: {region: arn}}, behind a -# redirection of GitHub, which the provider follows +# The releases of Pyjoyment-Lambda-Layers, for the public layers of a version of Pyjoyment, whose tags have the version +# and the date, as 0.3.0+2026.11.05, as GitHub has no latest release of a prefix. The API of GitHub answers 60 requests +# an hour of an address without a token, and 100 releases at most, in an order of its own +data "http" "releases" { + url = "https://api.github.com/repos/pyjoyment/Pyjoyment-Lambda-Layers/releases?per_page=100" + + request_headers = { + Accept = "application/vnd.github+json" + } + + lifecycle { + enabled = var.public_layers && var.pyjoyment_version != null + + postcondition { + condition = self.status_code == 200 + error_message = "The API of GitHub answers ${self.status_code}: ${self.response_body}" + } + } +} + +# The tag of the latest release of the version, the last of its releases sorted by the time of their publication +locals { + releases = var.public_layers && var.pyjoyment_version != null ? sort([ + for release in jsondecode(data.http.releases.response_body) : "${release.published_at} ${release.tag_name}" + if startswith(release.tag_name, "${var.pyjoyment_version}+") + ]) : [] + release = length(local.releases) > 0 ? split(" ", local.releases[length(local.releases) - 1])[1] : null +} + +# The index of the public layers of the release, {layer: {region: arn}}, or of the latest release, behind a redirection +# of GitHub, which the provider follows data "http" "layers" { - url = "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json" + url = ( + local.release != null + ? "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/download/${urlencode(local.release)}/layers.json" + : "https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json" + ) lifecycle { enabled = var.public_layers + + precondition { + condition = var.pyjoyment_version == null || local.release != null + error_message = "No release of Pyjoyment-Lambda-Layers of the latest 100 has the layers of the version of Pyjoyment, which come after its release. The variable \"public_layers\" set to false takes the layers of the build." + } } } -# The names of the layers of the version of Python, as python3_15-arm64 and pyjoyment-python3_15 +# The names of the layers of the version of Python, as python3_15-arm64, and pyjoyment-0_3_0-python3_15 of a version of +# Pyjoyment, or its alias pyjoyment-python3_15 in the index of the latest release locals { public_layers = var.public_layers ? jsondecode(data.http.layers.response_body) : {} python_name = "python${replace(var.python, ".", "_")}" + pyjoyment_name = ( + var.pyjoyment_version != null ? "pyjoyment-${replace(var.pyjoyment_version, ".", "_")}-${local.python_name}" + : "pyjoyment-${local.python_name}" + ) } diff --git a/examples/lambda_zip/variables.tf b/examples/lambda_zip/variables.tf index a740fb0a..136f633c 100644 --- a/examples/lambda_zip/variables.tf +++ b/examples/lambda_zip/variables.tf @@ -22,6 +22,12 @@ variable "public_layers" { default = true } +variable "pyjoyment_version" { + description = "The version of Pyjoyment of the public layers, as \"0.3.0\", the one that \"--function-only\" tells, or the latest one" + type = string + default = null +} + variable "python" { description = "The version of Python of the public layers, as \"3.15\" or \"3.15t\"" type = string diff --git a/plugins/pyjoyment/skills/deploy/SKILL.md b/plugins/pyjoyment/skills/deploy/SKILL.md index febbb88b..f0b626c3 100644 --- a/plugins/pyjoyment/skills/deploy/SKILL.md +++ b/plugins/pyjoyment/skills/deploy/SKILL.md @@ -165,11 +165,16 @@ kubectl apply -k kubernetes/prod - The public layers of [Pyjoyment-Lambda-Layers](https://github.com/pyjoyment/Pyjoyment-Lambda-Layers), as `python3_14-arm64` of Python for `provided.al2023` and - `pyjoyment-python3_14` of Pyjoyment, also for the runtime `python3.14`, are - taken by the ARN of a version, which the index of the latest release gives: + `pyjoyment-0_3_0-python3_14` of Pyjoyment 0.3.0, also for the runtime + `python3.14`, are taken by the ARN of a version, which the index of a + release gives, with the aliases of the latest Pyjoyment, as + `pyjoyment-python3_14`, in the index of the latest release: `python -m Pyjo 'g("https://github.com/pyjoyment/Pyjoyment-Lambda-Layers/releases/latest/download/layers.json").json("/pyjoyment-python3_14/eu-central-1")'`. `--function-only` tells the version of Pyjoyment of the dependencies, which - the layer of Pyjoyment is to have. The public layer of Pyjoyment has + the layer of Pyjoyment is to have: the layers of an older version are in + the latest release whose tag has it, as `0.3.0+2026.11.05`, and those of a + version come after its release, so a function of an unreleased checkout + takes a layer of its own build. The public layer of Pyjoyment has Pyjo-AWS too: `--layer-package Pyjo-AWS` leaves it out of the function, as the layer of its own build does, while another distribution of the namespace `Pyjo`, as Pyjo-MCP, stays in the function.