apx-aws-lambda 0.3.2__py3-none-any.whl → 0.3.4__py3-none-any.whl
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.
- apx_aws_lambda/lambda_.py +29 -15
- apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile +12 -2
- apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/tools/lambda_requirements.py +93 -0
- apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml +3 -0
- apx_aws_lambda/plugin.py +15 -2
- apx_aws_lambda/shell.py +6 -14
- {apx_aws_lambda-0.3.2.dist-info → apx_aws_lambda-0.3.4.dist-info}/METADATA +4 -4
- {apx_aws_lambda-0.3.2.dist-info → apx_aws_lambda-0.3.4.dist-info}/RECORD +12 -11
- {apx_aws_lambda-0.3.2.dist-info → apx_aws_lambda-0.3.4.dist-info}/WHEEL +0 -0
- {apx_aws_lambda-0.3.2.dist-info → apx_aws_lambda-0.3.4.dist-info}/entry_points.txt +0 -0
- {apx_aws_lambda-0.3.2.dist-info → apx_aws_lambda-0.3.4.dist-info}/licenses/LICENSE +0 -0
- {apx_aws_lambda-0.3.2.dist-info → apx_aws_lambda-0.3.4.dist-info}/top_level.txt +0 -0
apx_aws_lambda/lambda_.py
CHANGED
|
@@ -37,27 +37,41 @@ class LambdaTarget(DeployTarget):
|
|
|
37
37
|
self.config = config
|
|
38
38
|
self.role_arn = role_arn or os.environ.get("AWS_ROLE_ARN")
|
|
39
39
|
self.session_name = session_name
|
|
40
|
-
self.
|
|
41
|
-
|
|
42
|
-
if proxy_url
|
|
43
|
-
else None
|
|
44
|
-
)
|
|
40
|
+
self.proxy_url = proxy_url
|
|
41
|
+
self.app = app
|
|
45
42
|
self._env: dict[str, str] | None = None
|
|
46
43
|
|
|
44
|
+
def proxy(self, ctx: Context) -> ProxyClient | None:
|
|
45
|
+
"""The deploy proxy, when one is named: `[deploy] proxy_url` and `app` in platform.toml, else what the platform set for the organization (`AP_AWS_LAMBDA_PROXY_URL`, `AP_APP` in `ctx.env`), else the process environment."""
|
|
46
|
+
url = (
|
|
47
|
+
self.proxy_url
|
|
48
|
+
or ctx.env.get("AP_AWS_LAMBDA_PROXY_URL")
|
|
49
|
+
or os.environ.get("AP_AWS_LAMBDA_PROXY_URL")
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
if not url:
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
app = self.app or ctx.env.get("AP_APP") or os.environ.get("AP_APP", "")
|
|
56
|
+
|
|
57
|
+
return ProxyClient(url, app)
|
|
58
|
+
|
|
47
59
|
def env(self, ctx: Context) -> dict[str, str] | None:
|
|
48
60
|
"""The environment `aws` and `sam` run with: the proxy's credentials, else temporary credentials from `role_arn`, else the caller's own."""
|
|
49
|
-
if self.
|
|
61
|
+
if self._env is not None:
|
|
62
|
+
return self._env
|
|
63
|
+
|
|
64
|
+
proxy = self.proxy(ctx)
|
|
65
|
+
|
|
66
|
+
if proxy is None and not self.role_arn:
|
|
50
67
|
return None
|
|
51
68
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
)
|
|
60
|
-
self._env = {**os.environ, **granted}
|
|
69
|
+
granted = (
|
|
70
|
+
proxy.env(ctx)
|
|
71
|
+
if proxy is not None
|
|
72
|
+
else assume_role(ctx, self.role_arn or "", self.session_name, self.region)
|
|
73
|
+
)
|
|
74
|
+
self._env = {**os.environ, **granted}
|
|
61
75
|
|
|
62
76
|
return self._env
|
|
63
77
|
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
# SAM build recipes (BuildMethod: makefile). Deps go to a layer, code to the function.
|
|
2
|
+
# The layer is built for the function's platform (arm64, python3.12) from wheels only,
|
|
3
|
+
# so the build host — a laptop, CI, the platform's worker — does not matter.
|
|
4
|
+
|
|
5
|
+
LAYER_PLATFORM ?= manylinux2014_aarch64
|
|
6
|
+
LAYER_PYTHON ?= 3.12
|
|
2
7
|
|
|
3
8
|
build-ApiFunction:
|
|
4
9
|
cp -r app "$(ARTIFACTS_DIR)/app"
|
|
@@ -7,5 +12,10 @@ build-ApiFunction:
|
|
|
7
12
|
|
|
8
13
|
build-DepsLayer:
|
|
9
14
|
mkdir -p "$(ARTIFACTS_DIR)/python"
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
python -m pip install --quiet --upgrade pip >/dev/null
|
|
16
|
+
python tools/lambda_requirements.py "$(ARTIFACTS_DIR)/requirements.txt"
|
|
17
|
+
python -m pip install --quiet --target "$(ARTIFACTS_DIR)/python" \
|
|
18
|
+
--platform "$(LAYER_PLATFORM)" --python-version "$(LAYER_PYTHON)" \
|
|
19
|
+
--implementation cp --only-binary=:all: \
|
|
20
|
+
mangum -r "$(ARTIFACTS_DIR)/requirements.txt"
|
|
21
|
+
rm -f "$(ARTIFACTS_DIR)/requirements.txt"
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"""Requirements for the Lambda layer without poetry on the build host: pins from poetry.lock when it exists, otherwise the main dependencies of pyproject.toml (PEP 621 or poetry's caret/tilde constraints turned into PEP 440)."""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import sys
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import tomllib
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def caret(version: str) -> str:
|
|
11
|
+
parts = [int(p) for p in re.findall(r"\d+", version)]
|
|
12
|
+
upper = list(parts)
|
|
13
|
+
|
|
14
|
+
for i, p in enumerate(parts):
|
|
15
|
+
if p != 0 or i == len(parts) - 1:
|
|
16
|
+
upper = parts[:i] + [p + 1] + [0] * (len(parts) - i - 1)
|
|
17
|
+
break
|
|
18
|
+
|
|
19
|
+
return f">={version},<{'.'.join(str(p) for p in upper)}"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def tilde(version: str) -> str:
|
|
23
|
+
parts = [int(p) for p in re.findall(r"\d+", version)]
|
|
24
|
+
upper = parts[:1] + [parts[1] + 1] if len(parts) > 1 else [parts[0] + 1]
|
|
25
|
+
|
|
26
|
+
return f">={version},<{'.'.join(str(p) for p in upper)}"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def constraint(spec: str) -> str:
|
|
30
|
+
spec = spec.strip()
|
|
31
|
+
|
|
32
|
+
if spec in ("*", ""):
|
|
33
|
+
return ""
|
|
34
|
+
|
|
35
|
+
if spec.startswith("^"):
|
|
36
|
+
return caret(spec[1:])
|
|
37
|
+
|
|
38
|
+
if spec.startswith("~") and not spec.startswith("~="):
|
|
39
|
+
return tilde(spec[1:])
|
|
40
|
+
|
|
41
|
+
if re.match(r"^\d", spec):
|
|
42
|
+
return f"=={spec}"
|
|
43
|
+
|
|
44
|
+
return spec
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def from_poetry(deps: dict) -> list[str]:
|
|
48
|
+
rows = []
|
|
49
|
+
|
|
50
|
+
for name, spec in deps.items():
|
|
51
|
+
if name.lower() == "python":
|
|
52
|
+
continue
|
|
53
|
+
|
|
54
|
+
extras = ""
|
|
55
|
+
version = spec
|
|
56
|
+
|
|
57
|
+
if isinstance(spec, dict):
|
|
58
|
+
if spec.get("optional"):
|
|
59
|
+
continue
|
|
60
|
+
|
|
61
|
+
version = spec.get("version", "*")
|
|
62
|
+
extras = (
|
|
63
|
+
f"[{','.join(spec['extras'])}]" if spec.get("extras") else ""
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
rows.append(f"{name}{extras}{constraint(str(version))}")
|
|
67
|
+
|
|
68
|
+
return rows
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def main(out: str) -> None:
|
|
72
|
+
lock = Path("poetry.lock")
|
|
73
|
+
|
|
74
|
+
if lock.exists():
|
|
75
|
+
data = tomllib.loads(lock.read_text())
|
|
76
|
+
rows = [
|
|
77
|
+
f"{p['name']}=={p['version']}"
|
|
78
|
+
for p in data.get("package", [])
|
|
79
|
+
if "main" in (p.get("groups") or ["main"])
|
|
80
|
+
]
|
|
81
|
+
else:
|
|
82
|
+
pyproject = tomllib.loads(Path("pyproject.toml").read_text())
|
|
83
|
+
rows = list(pyproject.get("project", {}).get("dependencies") or [])
|
|
84
|
+
rows += from_poetry(
|
|
85
|
+
pyproject.get("tool", {}).get("poetry", {}).get("dependencies")
|
|
86
|
+
or {}
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
Path(out).write_text("\n".join(rows) + "\n")
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if __name__ == "__main__":
|
|
93
|
+
main(sys.argv[1])
|
apx_aws_lambda/plugin.py
CHANGED
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
|
|
7
|
-
from action_platform.abc import Plugin, Surface
|
|
7
|
+
from action_platform.abc import Option, Plugin, Surface
|
|
8
8
|
|
|
9
9
|
from apx_aws_lambda import cli
|
|
10
10
|
from apx_aws_lambda.tools import register_tools
|
|
@@ -12,15 +12,28 @@ from apx_aws_lambda.tools import register_tools
|
|
|
12
12
|
|
|
13
13
|
class AwsLambdaPlugin(Plugin):
|
|
14
14
|
slug = "aws-lambda"
|
|
15
|
+
name = "AWS Lambda"
|
|
15
16
|
description = (
|
|
16
17
|
"Deploy to AWS Lambda with SAM; read CloudFormation stacks and functions"
|
|
17
18
|
)
|
|
18
|
-
min_core = "0.17"
|
|
19
|
+
min_core = "0.17.9"
|
|
19
20
|
needs = [
|
|
20
21
|
"tool: aws, sam (bundled as Python packages when not on PATH)",
|
|
21
22
|
"env: AWS_REGION; credentials from proxy_url (the deploy proxy in your account, no keys), role_arn (OIDC, no keys) or the AWS CLI chain (SSO, profile, instance role)",
|
|
22
23
|
"net: *.amazonaws.com, the proxy url when set",
|
|
23
24
|
]
|
|
25
|
+
options = [
|
|
26
|
+
Option(
|
|
27
|
+
"proxy_url",
|
|
28
|
+
"Deploy proxy URL",
|
|
29
|
+
"url",
|
|
30
|
+
help=(
|
|
31
|
+
"The deploy proxy installed in your AWS account: it decides which app may deploy and hands the worker short-lived credentials, so the platform never holds an access key. "
|
|
32
|
+
"Install it once with proxy/deploy.sh <platform url> <organization> from this repository; the Function URL it prints goes here."
|
|
33
|
+
),
|
|
34
|
+
required=True,
|
|
35
|
+
),
|
|
36
|
+
]
|
|
24
37
|
|
|
25
38
|
@property
|
|
26
39
|
def overlays(self) -> Path:
|
apx_aws_lambda/shell.py
CHANGED
|
@@ -12,7 +12,6 @@ from pathlib import Path
|
|
|
12
12
|
from typing import Any
|
|
13
13
|
|
|
14
14
|
from action_platform.core.exception import DeployError
|
|
15
|
-
from action_platform.settings import settings
|
|
16
15
|
|
|
17
16
|
MODULES = {"aws": "awscli", "sam": "samcli"}
|
|
18
17
|
|
|
@@ -32,19 +31,12 @@ def require(tool: str, hint: str) -> list[str]:
|
|
|
32
31
|
raise DeployError(f"{tool} is not installed: {hint}")
|
|
33
32
|
|
|
34
33
|
|
|
35
|
-
def module_env(
|
|
36
|
-
"""
|
|
37
|
-
if
|
|
38
|
-
return
|
|
34
|
+
def module_env(env: dict[str, str] | None) -> dict[str, str]:
|
|
35
|
+
"""The child's environment: the caller's, or the process's, with SAM's telemetry off."""
|
|
36
|
+
if env is None:
|
|
37
|
+
return {**os.environ, "SAM_CLI_TELEMETRY": "0"}
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
current = merged.get("PYTHONPATH", "")
|
|
42
|
-
plugins = str(settings.PLUGINS_DIR)
|
|
43
|
-
|
|
44
|
-
if plugins not in current.split(os.pathsep):
|
|
45
|
-
merged["PYTHONPATH"] = os.pathsep.join(p for p in (plugins, current) if p)
|
|
46
|
-
|
|
47
|
-
return merged
|
|
39
|
+
return {"SAM_CLI_TELEMETRY": "0", **env}
|
|
48
40
|
|
|
49
41
|
|
|
50
42
|
def run(
|
|
@@ -53,7 +45,7 @@ def run(
|
|
|
53
45
|
result = subprocess.run(
|
|
54
46
|
args,
|
|
55
47
|
cwd=cwd,
|
|
56
|
-
env=module_env(
|
|
48
|
+
env=module_env(env),
|
|
57
49
|
capture_output=True,
|
|
58
50
|
text=True,
|
|
59
51
|
check=False,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: apx-aws-lambda
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
|
|
5
5
|
Author-email: Action Platform <cloud@actionplatform.io>
|
|
6
6
|
License-Expression: Apache-2.0
|
|
7
7
|
Requires-Python: >=3.11
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
|
-
Requires-Dist: action-platform>=0.17
|
|
10
|
+
Requires-Dist: action-platform>=0.17.9
|
|
11
11
|
Requires-Dist: awscli>=1.34
|
|
12
12
|
Requires-Dist: aws-sam-cli>=1.120
|
|
13
13
|
Provides-Extra: dev
|
|
@@ -71,7 +71,7 @@ The target looks for credentials in this order:
|
|
|
71
71
|
|
|
72
72
|
| Under `[deploy]` | How | Who decides what the app may do |
|
|
73
73
|
|---|---|---|
|
|
74
|
-
| `proxy_url` + `app` | the deploy proxy in your account exchanges a platform token for the app's deploy-role credentials | the proxy's grants, in your account |
|
|
74
|
+
| `proxy_url` + `app` — or the organization's proxy url set on the platform (Plugins → AWS Lambda), which every deploy job carries as `AP_AWS_LAMBDA_PROXY_URL` with `AP_APP` | the deploy proxy in your account exchanges a platform token for the app's deploy-role credentials | the proxy's grants, in your account |
|
|
75
75
|
| `role_arn` | `sts assume-role-with-web-identity` with a platform token | the role's trust and permission policies |
|
|
76
76
|
| neither | the AWS CLI's own chain: SSO, profile, instance role | whatever that identity may do |
|
|
77
77
|
|
|
@@ -101,7 +101,7 @@ action-platform aws-lambda proxy show $P acme/shop/orders
|
|
|
101
101
|
|
|
102
102
|
`create` makes the app's two roles and grants deploy to the app itself; `grant` replaces the list of subject prefixes that may deploy — `org:acme` means anyone in the organization, `org:acme:project:shop` any app of the project, the full subject only deploys the platform runs for that app.
|
|
103
103
|
|
|
104
|
-
**3.
|
|
104
|
+
**3. Tell the platform (or the repository) where it is.** On the hosted platform, **Plugins** → **AWS Lambda** → **Configure** keeps the proxy url for the whole organization; every deploy job then carries it, together with the app's `org/project/app`, so the repository needs nothing beyond `target = "aws/lambda"`. From a machine, or to override per repository:
|
|
105
105
|
|
|
106
106
|
```toml
|
|
107
107
|
[deploy]
|
|
@@ -1,24 +1,25 @@
|
|
|
1
1
|
apx_aws_lambda/__init__.py,sha256=Q0-IuA8uSNSj-dfiZsLHG509XAkVn9y5IMdbXdgGsMw,212
|
|
2
2
|
apx_aws_lambda/cli.py,sha256=RVjgXFVvY9Tpj8X-bEIMn64TtLr43n3X2BQMIwMPCi4,4234
|
|
3
|
-
apx_aws_lambda/lambda_.py,sha256=
|
|
4
|
-
apx_aws_lambda/plugin.py,sha256=
|
|
3
|
+
apx_aws_lambda/lambda_.py,sha256=zYe7nzuygbx2-NyPpYxzU5VizPG6Q6sWQuaWfuN5uZM,10084
|
|
4
|
+
apx_aws_lambda/plugin.py,sha256=shRZyfV97_I137lhlaUF6RNEx7OMpmst3zCS_93tLqs,1681
|
|
5
5
|
apx_aws_lambda/proxy.py,sha256=rDDYFECSlKAVtIufGa5NqPT-_dQLVtAePkc9sFitxn4,4407
|
|
6
|
-
apx_aws_lambda/shell.py,sha256=
|
|
6
|
+
apx_aws_lambda/shell.py,sha256=2qeuaDyjfAifOOzNrKXDG4xMyVydzg4pgNjw77cdFrE,2040
|
|
7
7
|
apx_aws_lambda/tools.py,sha256=i1vSfBslaiw8wUhgTctI_V4FHYSDiaGMDhMe0JxLs1g,2322
|
|
8
8
|
apx_aws_lambda/overlays/index.json,sha256=AON1411d4v-2mUNJ96sFwe-L4HrHKLW6l0YSFc3_iQc,208
|
|
9
9
|
apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json,sha256=a6I40TxR4sS4IiMoZy5DIh2IitMPSYC7VV9iUgxccEU,539
|
|
10
10
|
apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py,sha256=efTbxDeSLieLxJVjzrPWKZYHJt-iwdmAgmTvE_TrVk4,853
|
|
11
11
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md,sha256=YfO3YLdDO74w3rkQ7oBulSvxGLX6piYv5ojUy9cvfZs,1637
|
|
12
12
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml,sha256=_FbMTTbbyfFa_WjCIb4nxPSGTd4lZxrzuvuiynseoG8,820
|
|
13
|
-
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml,sha256=
|
|
13
|
+
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml,sha256=Od-ZL2_2FVONGYNvx6OtpGZuGwDBWk52S31in9MtZKM,3045
|
|
14
14
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml,sha256=cRjBTRhJRtX7HVRSnLqGaPP-0SsIWzJoPTXd7v7tq48,2074
|
|
15
|
-
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile,sha256=
|
|
15
|
+
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile,sha256=z2yb-2xKp4wVq1PH6u6_B_X_DQmapzqlhuIhAdpbRM4,948
|
|
16
16
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/lambda_handler.py,sha256=2yRHnW5hDfQoJNcE9RHxsThusl-94hM4OUGj5OPssmA,603
|
|
17
|
+
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/tools/lambda_requirements.py,sha256=RScOXVRcA4R9z4CTkoYfNQreej4_tqEQZU_E3kIdg9k,2430
|
|
17
18
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json,sha256=yow1_lHYADDu1bn8SJMCqXptuVsWCJ31gtc9iqMnnbI,2657
|
|
18
19
|
apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json,sha256=odQnKozS_9c2v28aOBocBSuVuowb3_xRe3ZGSKFCHcM,564
|
|
19
|
-
apx_aws_lambda-0.3.
|
|
20
|
-
apx_aws_lambda-0.3.
|
|
21
|
-
apx_aws_lambda-0.3.
|
|
22
|
-
apx_aws_lambda-0.3.
|
|
23
|
-
apx_aws_lambda-0.3.
|
|
24
|
-
apx_aws_lambda-0.3.
|
|
20
|
+
apx_aws_lambda-0.3.4.dist-info/licenses/LICENSE,sha256=WcDWtpGI54c3iNg7UddKYdRlt9oUzbMjUzdgKqsE8SI,11263
|
|
21
|
+
apx_aws_lambda-0.3.4.dist-info/METADATA,sha256=hv88o6-4SX95RAghOHH1QyneXA0Ch10yA0DCnV4fAXA,12709
|
|
22
|
+
apx_aws_lambda-0.3.4.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
23
|
+
apx_aws_lambda-0.3.4.dist-info/entry_points.txt,sha256=3uAwnYt-VgVll4NPMHp0r36oxHXeivvg1N8w5s5x43I,152
|
|
24
|
+
apx_aws_lambda-0.3.4.dist-info/top_level.txt,sha256=hAm2-VyixplJdw19PaHTNxZzi9x3yL3lXgsKbVUvgLg,15
|
|
25
|
+
apx_aws_lambda-0.3.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|