simple_aws_lambda 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ .. _about_author:
2
+
3
+ About the Author
4
+ ------------------------------------------------------------------------------
5
+ ::
6
+
7
+ (\ (\
8
+ ( -.-)o
9
+ o_(")(")
10
+
11
+ **Sanhe Hu** is a seasoned software engineer with a deep passion for Python development since 2010. As an author and maintainer of `150+ open-source Python projects <https://pypi.org/user/machugwu/>`_, with over `15 million monthly downloads <https://github.com/MacHu-GWU>`_, I bring a wealth of experience to the table. As a Senior Solution Architect and Subject Matter Expert in AI, Data, Amazon Web Services, Cloud Engineering, DevOps, I thrive on helping clients with platform design, enterprise architecture, and strategic roadmaps.
12
+
13
+ Talk is cheap, show me the code:
14
+
15
+ - My Github: https://github.com/MacHu-GWU
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sanhe Hu <husanhe@email.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,134 @@
1
+ Metadata-Version: 2.4
2
+ Name: simple_aws_lambda
3
+ Version: 0.3.1
4
+ Summary: Objective Oriented Python SDK for AWS Lambda.
5
+ Author-email: Sanhe Hu <husanhe@gmail.com>
6
+ Maintainer-email: Sanhe Hu <husanhe@gmail.com>
7
+ License-Expression: MIT
8
+ Project-URL: Homepage, https://github.com/MacHu-GWU/simple_aws_lambda-project
9
+ Project-URL: Documentation, https://simple-aws-lambda.readthedocs.io/en/latest/
10
+ Project-URL: Repository, https://github.com/MacHu-GWU/simple_aws_lambda-project
11
+ Project-URL: Issues, https://github.com/MacHu-GWU/simple_aws_lambda-project/issues
12
+ Project-URL: Changelog, https://github.com/MacHu-GWU/simple_aws_lambda-project/blob/main/release-history.rst
13
+ Project-URL: Download, https://pypi.org/pypi/simple-aws-lambda#files
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Natural Language :: English
17
+ Classifier: Operating System :: Microsoft :: Windows
18
+ Classifier: Operating System :: MacOS
19
+ Classifier: Operating System :: Unix
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Requires-Python: <4.0,>=3.11
26
+ Description-Content-Type: text/x-rst
27
+ License-File: LICENSE.txt
28
+ License-File: AUTHORS.rst
29
+ Requires-Dist: boto3<2.0.0,>=1.35.99
30
+ Requires-Dist: iterproxy<1.0.0,>=0.3.1
31
+ Requires-Dist: func_args<2.0.0,>=1.0.1
32
+ Provides-Extra: dev
33
+ Requires-Dist: rich<15.0.0,>=14.3.4; extra == "dev"
34
+ Requires-Dist: boto3-stubs[lambda]<2.0.0,>=1.35.99; extra == "dev"
35
+ Provides-Extra: test
36
+ Requires-Dist: pytest<10.0.0,>=9.1.1; extra == "test"
37
+ Requires-Dist: pytest-cov<8.0.0,>=7.1.0; extra == "test"
38
+ Requires-Dist: moto<6.0.0,>=5.1.10; extra == "test"
39
+ Provides-Extra: doc
40
+ Requires-Dist: Sphinx<9.0.0,>=8.2.3; extra == "doc"
41
+ Requires-Dist: sphinx-copybutton<1.0.0,>=0.5.2; extra == "doc"
42
+ Requires-Dist: sphinx-design<1.0.0,>=0.7.0; extra == "doc"
43
+ Requires-Dist: sphinx-jinja<3.0.0,>=2.0.2; extra == "doc"
44
+ Requires-Dist: furo==2025.12.19; extra == "doc"
45
+ Requires-Dist: pygments<3.0.0,>=2.18.0; extra == "doc"
46
+ Requires-Dist: ipython<8.19.0,>=8.18.1; extra == "doc"
47
+ Requires-Dist: ipykernel<8.0.0,>=7.3.0; extra == "doc"
48
+ Requires-Dist: nbsphinx<1.0.0,>=0.9.8; extra == "doc"
49
+ Requires-Dist: rstobj<3.0.0,>=2.0.0; extra == "doc"
50
+ Requires-Dist: docfly<4.0.0,>=3.0.3; extra == "doc"
51
+ Provides-Extra: mise
52
+ Requires-Dist: PyGithub<3.0.0,>=2.8.0; extra == "mise"
53
+ Requires-Dist: httpx2<3.0.0,>=2.13.1; extra == "mise"
54
+ Dynamic: license-file
55
+
56
+
57
+ .. image:: https://readthedocs.org/projects/simple-aws-lambda/badge/?version=latest
58
+ :target: https://simple-aws-lambda.readthedocs.io/en/latest/
59
+ :alt: Documentation Status
60
+
61
+ .. image:: https://github.com/MacHu-GWU/simple_aws_lambda-project/actions/workflows/main.yml/badge.svg
62
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/actions?query=workflow:CI
63
+
64
+ .. image:: https://codecov.io/gh/MacHu-GWU/simple_aws_lambda-project/branch/main/graph/badge.svg
65
+ :target: https://codecov.io/gh/MacHu-GWU/simple_aws_lambda-project
66
+
67
+ .. image:: https://img.shields.io/pypi/v/simple-aws-lambda.svg
68
+ :target: https://pypi.python.org/pypi/simple-aws-lambda
69
+
70
+ .. image:: https://img.shields.io/pypi/l/simple-aws-lambda.svg
71
+ :target: https://pypi.python.org/pypi/simple-aws-lambda
72
+
73
+ .. image:: https://img.shields.io/pypi/pyversions/simple-aws-lambda.svg
74
+ :target: https://pypi.python.org/pypi/simple-aws-lambda
75
+
76
+ .. image:: https://img.shields.io/badge/✍️_Release_History!--None.svg?style=social&logo=github
77
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/blob/main/release-history.rst
78
+
79
+ .. image:: https://img.shields.io/badge/⭐_Star_me_on_GitHub!--None.svg?style=social&logo=github
80
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project
81
+
82
+ ------
83
+
84
+ .. image:: https://img.shields.io/badge/Link-API-blue.svg
85
+ :target: https://simple-aws-lambda.readthedocs.io/en/latest/py-modindex.html
86
+
87
+ .. image:: https://img.shields.io/badge/Link-Install-blue.svg
88
+ :target: `install`_
89
+
90
+ .. image:: https://img.shields.io/badge/Link-GitHub-blue.svg
91
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project
92
+
93
+ .. image:: https://img.shields.io/badge/Link-Submit_Issue-blue.svg
94
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/issues
95
+
96
+ .. image:: https://img.shields.io/badge/Link-Request_Feature-blue.svg
97
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/issues
98
+
99
+ .. image:: https://img.shields.io/badge/Link-Download-blue.svg
100
+ :target: https://pypi.org/pypi/simple-aws-lambda#files
101
+
102
+
103
+ Welcome to ``simple_aws_lambda`` Documentation
104
+ ==============================================================================
105
+ .. image:: https://simple-aws-lambda.readthedocs.io/en/latest/_static/simple_aws_lambda-logo.png
106
+ :target: https://simple-aws-lambda.readthedocs.io/en/latest/
107
+
108
+ simple_aws_lambda is a Pythonic library that provides a simplified, high-level interface for AWS Lambda operations. Built on top of boto3, it offers intuitive data models, property-based access patterns, and comprehensive type hints to make working with AWS Lambda resources more developer-friendly and maintainable.
109
+
110
+ **Key Features:**
111
+
112
+ `Data Models <https://simple-aws-lambda.readthedocs.io/en/latest/02-Data-Model/index.html>`_ - Transform raw boto3 responses into Pythonic objects with property-based access, following the Raw Data Storage, Property-Based Access, and Core Data Extraction patterns to ensure API resilience and clean interfaces.
113
+
114
+ `Better Client <https://simple-aws-lambda.readthedocs.io/en/latest/01-Quick-Start/index.html>`_ - Enhance the standard boto3 Lambda client with idempotent operations, automatic pagination, better error handling, and direct return of data model objects instead of raw dictionaries.
115
+
116
+ `Recipes <https://simple-aws-lambda.readthedocs.io/en/latest/03-Cleanup-Old-Layer-Versions/index.html>`_ - Provide high-level functions for common Lambda layer management tasks such as version cleanup, cross-account access management, and intelligent layer discovery that combine multiple API calls with best practices.
117
+
118
+
119
+ .. _install:
120
+
121
+ Install
122
+ ------------------------------------------------------------------------------
123
+
124
+ ``simple_aws_lambda`` is released on PyPI, so all you need is to:
125
+
126
+ .. code-block:: console
127
+
128
+ $ pip install simple-aws-lambda
129
+
130
+ To upgrade to latest version:
131
+
132
+ .. code-block:: console
133
+
134
+ $ pip install --upgrade simple-aws-lambda
@@ -0,0 +1,79 @@
1
+
2
+ .. image:: https://readthedocs.org/projects/simple-aws-lambda/badge/?version=latest
3
+ :target: https://simple-aws-lambda.readthedocs.io/en/latest/
4
+ :alt: Documentation Status
5
+
6
+ .. image:: https://github.com/MacHu-GWU/simple_aws_lambda-project/actions/workflows/main.yml/badge.svg
7
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/actions?query=workflow:CI
8
+
9
+ .. image:: https://codecov.io/gh/MacHu-GWU/simple_aws_lambda-project/branch/main/graph/badge.svg
10
+ :target: https://codecov.io/gh/MacHu-GWU/simple_aws_lambda-project
11
+
12
+ .. image:: https://img.shields.io/pypi/v/simple-aws-lambda.svg
13
+ :target: https://pypi.python.org/pypi/simple-aws-lambda
14
+
15
+ .. image:: https://img.shields.io/pypi/l/simple-aws-lambda.svg
16
+ :target: https://pypi.python.org/pypi/simple-aws-lambda
17
+
18
+ .. image:: https://img.shields.io/pypi/pyversions/simple-aws-lambda.svg
19
+ :target: https://pypi.python.org/pypi/simple-aws-lambda
20
+
21
+ .. image:: https://img.shields.io/badge/✍️_Release_History!--None.svg?style=social&logo=github
22
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/blob/main/release-history.rst
23
+
24
+ .. image:: https://img.shields.io/badge/⭐_Star_me_on_GitHub!--None.svg?style=social&logo=github
25
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project
26
+
27
+ ------
28
+
29
+ .. image:: https://img.shields.io/badge/Link-API-blue.svg
30
+ :target: https://simple-aws-lambda.readthedocs.io/en/latest/py-modindex.html
31
+
32
+ .. image:: https://img.shields.io/badge/Link-Install-blue.svg
33
+ :target: `install`_
34
+
35
+ .. image:: https://img.shields.io/badge/Link-GitHub-blue.svg
36
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project
37
+
38
+ .. image:: https://img.shields.io/badge/Link-Submit_Issue-blue.svg
39
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/issues
40
+
41
+ .. image:: https://img.shields.io/badge/Link-Request_Feature-blue.svg
42
+ :target: https://github.com/MacHu-GWU/simple_aws_lambda-project/issues
43
+
44
+ .. image:: https://img.shields.io/badge/Link-Download-blue.svg
45
+ :target: https://pypi.org/pypi/simple-aws-lambda#files
46
+
47
+
48
+ Welcome to ``simple_aws_lambda`` Documentation
49
+ ==============================================================================
50
+ .. image:: https://simple-aws-lambda.readthedocs.io/en/latest/_static/simple_aws_lambda-logo.png
51
+ :target: https://simple-aws-lambda.readthedocs.io/en/latest/
52
+
53
+ simple_aws_lambda is a Pythonic library that provides a simplified, high-level interface for AWS Lambda operations. Built on top of boto3, it offers intuitive data models, property-based access patterns, and comprehensive type hints to make working with AWS Lambda resources more developer-friendly and maintainable.
54
+
55
+ **Key Features:**
56
+
57
+ `Data Models <https://simple-aws-lambda.readthedocs.io/en/latest/02-Data-Model/index.html>`_ - Transform raw boto3 responses into Pythonic objects with property-based access, following the Raw Data Storage, Property-Based Access, and Core Data Extraction patterns to ensure API resilience and clean interfaces.
58
+
59
+ `Better Client <https://simple-aws-lambda.readthedocs.io/en/latest/01-Quick-Start/index.html>`_ - Enhance the standard boto3 Lambda client with idempotent operations, automatic pagination, better error handling, and direct return of data model objects instead of raw dictionaries.
60
+
61
+ `Recipes <https://simple-aws-lambda.readthedocs.io/en/latest/03-Cleanup-Old-Layer-Versions/index.html>`_ - Provide high-level functions for common Lambda layer management tasks such as version cleanup, cross-account access management, and intelligent layer discovery that combine multiple API calls with best practices.
62
+
63
+
64
+ .. _install:
65
+
66
+ Install
67
+ ------------------------------------------------------------------------------
68
+
69
+ ``simple_aws_lambda`` is released on PyPI, so all you need is to:
70
+
71
+ .. code-block:: console
72
+
73
+ $ pip install simple-aws-lambda
74
+
75
+ To upgrade to latest version:
76
+
77
+ .. code-block:: console
78
+
79
+ $ pip install --upgrade simple-aws-lambda
@@ -0,0 +1,129 @@
1
+ # [project] table: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/
2
+ [project]
3
+ name = "simple_aws_lambda"
4
+ # Bump before each release (https://semver.org/), then ``mise run inst`` to update ``uv.lock``.
5
+ version = "0.3.1"
6
+ description = "Objective Oriented Python SDK for AWS Lambda."
7
+ # An SPDX license expression (PEP 639); keep ``LICENSE.txt`` in sync.
8
+ # Read: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#license-and-license-files
9
+ # Valid identifiers: https://spdx.org/licenses/
10
+ license = "MIT"
11
+ license-files = ["LICENSE.txt", "AUTHORS.rst"]
12
+ authors = [
13
+ { name = "Sanhe Hu", email = "husanhe@gmail.com" },
14
+ ]
15
+ maintainers = [
16
+ { name = "Sanhe Hu", email = "husanhe@gmail.com" },
17
+ ]
18
+ keywords = []
19
+ readme = "README.rst"
20
+ requires-python = ">=3.11,<4.0"
21
+ # Read: https://pypi.org/classifiers/
22
+ classifiers = [
23
+ "Development Status :: 4 - Beta",
24
+ "Intended Audience :: Developers",
25
+ "Natural Language :: English",
26
+ "Operating System :: Microsoft :: Windows",
27
+ "Operating System :: MacOS",
28
+ "Operating System :: Unix",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Programming Language :: Python :: 3.13",
33
+ "Programming Language :: Python :: 3.14",
34
+ ]
35
+
36
+ # --- Dependencies ---
37
+ # Edit these lists, then ``mise run inst`` to update ``uv.lock`` and ``.venv``.
38
+ dependencies = [
39
+ "boto3>=1.35.99,<2.0.0",
40
+ "iterproxy>=0.3.1,<1.0.0",
41
+ "func_args>=1.0.1,<2.0.0",
42
+ ]
43
+
44
+ # --- Optional dependencies (extras) ---
45
+ # Read: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-optional-dependencies
46
+ # Each one must support every Python version in ``requires-python``.
47
+ [project.optional-dependencies]
48
+
49
+ # local development
50
+ dev = [
51
+ "rich>=14.3.4,<15.0.0",
52
+ "boto3-stubs[lambda]>=1.35.99,<2.0.0", # IDE autocompletion for the lambda client
53
+ ]
54
+
55
+ # tests and coverage
56
+ test = [
57
+ "pytest>=9.1.1,<10.0.0",
58
+ "pytest-cov>=7.1.0,<8.0.0",
59
+ "moto>=5.1.10,<6.0.0", # mock AWS, so tests never call real AWS
60
+ ]
61
+
62
+ # docs build
63
+ doc = [
64
+ "Sphinx>=8.2.3,<9.0.0", # held below 9 until its autodoc rewrite is verified
65
+ "sphinx-copybutton>=0.5.2,<1.0.0", # copy button on code blocks
66
+ "sphinx-design>=0.7.0,<1.0.0", # cards, tabs, grids
67
+ "sphinx-jinja>=2.0.2,<3.0.0", # jinja in reST
68
+ "furo==2025.12.19", # theme
69
+ "pygments>=2.18.0,<3.0.0", # syntax highlighting
70
+ "ipython>=8.18.1,<8.19.0", # notebook execution
71
+ "ipykernel>=7.3.0,<8.0.0", # notebook kernel
72
+ "nbsphinx>=0.9.8,<1.0.0", # notebooks as doc pages
73
+ "rstobj>=2.0.0,<3.0.0", # reST from Python
74
+ "docfly>=3.0.3,<4.0.0", # toctree and API reference
75
+ ]
76
+
77
+ # mise tasks
78
+ mise = [
79
+ "PyGithub>=2.8.0,<3.0.0", # GitHub API client
80
+ "httpx2>=2.13.1,<3.0.0", # Codecov and Read the Docs APIs
81
+ ]
82
+
83
+ [project.urls]
84
+ Homepage = "https://github.com/MacHu-GWU/simple_aws_lambda-project"
85
+ Documentation = "https://simple-aws-lambda.readthedocs.io/en/latest/"
86
+ Repository = "https://github.com/MacHu-GWU/simple_aws_lambda-project"
87
+ Issues = "https://github.com/MacHu-GWU/simple_aws_lambda-project/issues"
88
+ Changelog = "https://github.com/MacHu-GWU/simple_aws_lambda-project/blob/main/release-history.rst"
89
+ Download = "https://pypi.org/pypi/simple-aws-lambda#files"
90
+
91
+ # Read: https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#creating-executable-scripts
92
+ [project.scripts]
93
+
94
+ [tool.setuptools.packages.find]
95
+ where = ["."]
96
+ include = [
97
+ "simple_aws_lambda*",
98
+ ]
99
+ exclude = [
100
+ "simple_aws_lambda.tests",
101
+ "simple_aws_lambda.tests.*",
102
+ "simple_aws_lambda.docs",
103
+ "simple_aws_lambda.docs.*",
104
+ ]
105
+
106
+ # --- ruff: ``mise run format`` / ``mise run lint`` ---
107
+ [tool.ruff]
108
+ extend-exclude = [
109
+ "simple_aws_lambda/vendor",
110
+ ".claude/skills/*/assets", # templates, not valid Python
111
+ ]
112
+
113
+ [tool.ruff.lint.per-file-ignores]
114
+ # re-export modules
115
+ "**/__init__.py" = ["F401"]
116
+ "**/api.py" = ["F401"]
117
+
118
+ # --- pytest 9+ native table ---
119
+ # Read: https://docs.pytest.org/en/stable/reference/customize.html#pyproject-toml
120
+ [tool.pytest]
121
+ testpaths = ["tests"]
122
+ # strict = true # only with a pinned pytest
123
+ # filterwarnings = ["error"]
124
+ # markers = ["slow: tests that take more than a few seconds"]
125
+
126
+ # --- Build (``mise run build``); setuptools 77+ for PEP 639 ``license`` ---
127
+ [build-system]
128
+ requires = ["setuptools>=77.0"]
129
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ # -*- coding: utf-8 -*-
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Public API. Users import from here::
5
+
6
+ from simple_aws_lambda.api import list_layers
7
+ import simple_aws_lambda.api as simple_aws_lambda
8
+ """
9
+
10
+ from .model import LatestMatchingLayerVersion
11
+ from .model import Layer
12
+ from .model import LayerIterproxy
13
+ from .model import LayerContent
14
+ from .model import LayerVersion
15
+ from .model import LayerVersionIterproxy
16
+ from .client import list_layers
17
+ from .client import list_layer_versions
18
+ from .client import get_layer_version
19
+ from .recipe import get_latest_layer_version
20
+ from .recipe import cleanup_old_layer_versions
21
+ from .recipe import grant_aws_account_or_aws_organization_lambda_layer_version_access
22
+ from .recipe import revoke_aws_account_or_aws_organization_lambda_layer_version_access
@@ -0,0 +1,140 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ """
4
+ Improve the original lambda boto3 API.
5
+
6
+ Ref:
7
+
8
+ - https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda.html
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import typing as T
14
+
15
+ import botocore.exceptions
16
+ from func_args.api import OPT
17
+ from func_args.api import remove_optional
18
+
19
+ from .model import Layer
20
+ from .model import LayerVersion
21
+ from .model import LayerIterproxy
22
+ from .model import LayerVersionIterproxy
23
+
24
+ if T.TYPE_CHECKING: # pragma: no cover
25
+ from mypy_boto3_lambda.client import LambdaClient
26
+
27
+
28
+ def list_layers(
29
+ lambda_client: LambdaClient,
30
+ compatible_runtime: str = OPT,
31
+ compatible_architecture: str = OPT,
32
+ max_items: int = 9999,
33
+ page_size: int = 50,
34
+ ) -> LayerIterproxy:
35
+ """
36
+ List available AWS Lambda layers in the account.
37
+
38
+ Ref:
39
+
40
+ - `list_layers <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/list_layers.html>`_
41
+ """
42
+
43
+ def func():
44
+ paginator = lambda_client.get_paginator("list_layers")
45
+ response_iterator = paginator.paginate(
46
+ **remove_optional(
47
+ CompatibleRuntime=compatible_runtime,
48
+ CompatibleArchitecture=compatible_architecture,
49
+ PaginationConfig={
50
+ "MaxItems": max_items,
51
+ "PageSize": page_size,
52
+ },
53
+ )
54
+ )
55
+ for response in response_iterator:
56
+ for _data in response.get("Layers", []):
57
+ yield Layer(_data=_data)
58
+
59
+ return LayerIterproxy(func())
60
+
61
+
62
+ def list_layer_versions(
63
+ lambda_client: LambdaClient,
64
+ layer_name: str,
65
+ compatible_runtime: str = OPT,
66
+ compatible_architecture: str = OPT,
67
+ max_items: int = 9999,
68
+ page_size: int = 50,
69
+ _sort_descending: bool = False,
70
+ ) -> LayerVersionIterproxy:
71
+ """
72
+ List all versions of Lambda layers in the account.
73
+
74
+ :param _sort_descending: if True, load all layer versions in to memory and
75
+ then sort them in memory in descending order by version number. This is
76
+ the default behavior of official AWS API. However, the test tool moto does not
77
+ implement it correctly (it returns in ascending order). So this parameter
78
+ is a workaround for moto only. You don't need to set this parameter
79
+ when you run against real AWS API.
80
+
81
+ .. note::
82
+
83
+ this API always returns the latest version first.
84
+
85
+ Ref:
86
+
87
+ - `list_layer_versions <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/list_layer_versions.html>`_
88
+ """
89
+
90
+ def func():
91
+ paginator = lambda_client.get_paginator("list_layer_versions")
92
+ response_iterator = paginator.paginate(
93
+ **remove_optional(
94
+ LayerName=layer_name,
95
+ CompatibleRuntime=compatible_runtime,
96
+ CompatibleArchitecture=compatible_architecture,
97
+ PaginationConfig={
98
+ "MaxItems": max_items,
99
+ "PageSize": page_size,
100
+ },
101
+ )
102
+ )
103
+ for response in response_iterator:
104
+ for _data in response.get("LayerVersions", []):
105
+ yield LayerVersion(_data=_data)
106
+
107
+ if _sort_descending:
108
+ return LayerVersionIterproxy(
109
+ sorted(
110
+ func(),
111
+ key=lambda v: v.version,
112
+ reverse=True,
113
+ )
114
+ )
115
+ else:
116
+ return LayerVersionIterproxy(func())
117
+
118
+
119
+ def get_layer_version(
120
+ lambda_client: LambdaClient,
121
+ layer_name: str,
122
+ version_number: int,
123
+ ) -> LayerVersion | None:
124
+ """
125
+ Retrieve details for a specific Lambda layer version.
126
+
127
+ Ref:
128
+
129
+ - `get_layer_version <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/lambda/client/get_layer_version.html>`_
130
+ """
131
+ try:
132
+ response = lambda_client.get_layer_version(
133
+ LayerName=layer_name,
134
+ VersionNumber=version_number,
135
+ )
136
+ return LayerVersion(_data=response)
137
+ except botocore.exceptions.ClientError as e:
138
+ if e.response["Error"]["Code"] == "ResourceNotFoundException":
139
+ return None
140
+ raise # pragma: no cover