apx-aws-lambda 0.3.9__tar.gz → 0.3.11__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.
Files changed (47) hide show
  1. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/PKG-INFO +8 -5
  2. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/README.md +6 -3
  3. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/lambda_.py +198 -1
  4. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/proxy.py +1 -0
  5. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda.egg-info/PKG-INFO +8 -5
  6. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda.egg-info/requires.txt +1 -1
  7. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/pyproject.toml +2 -2
  8. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/tests/test_targets.py +107 -0
  9. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/LICENSE +0 -0
  10. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/__init__.py +0 -0
  11. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/cli.py +0 -0
  12. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
  13. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
  14. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
  15. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +0 -0
  16. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/go/Makefile +0 -0
  17. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/go/cmd/lambda/main.go +0 -0
  18. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/go/template.yaml +0 -0
  19. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/java/Makefile +0 -0
  20. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/java/run.sh +0 -0
  21. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/java/template.yaml +0 -0
  22. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/kotlin/Makefile +0 -0
  23. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/kotlin/run.sh +0 -0
  24. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/kotlin/template.yaml +0 -0
  25. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/node/Makefile +0 -0
  26. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/node/run.sh +0 -0
  27. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/node/template.yaml +0 -0
  28. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/Makefile +0 -0
  29. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/lambda_handler.py +0 -0
  30. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/template.yaml +0 -0
  31. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/python/tools/lambda_requirements.py +0 -0
  32. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/Makefile +0 -0
  33. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/lambda_handler.rb +0 -0
  34. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/_lang/ruby/template.yaml +0 -0
  35. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
  36. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
  37. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
  38. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/overlays/index.json +0 -0
  39. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/plugin.py +0 -0
  40. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/shell.py +0 -0
  41. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda/tools.py +0 -0
  42. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda.egg-info/SOURCES.txt +0 -0
  43. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
  44. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
  45. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/apx_aws_lambda.egg-info/top_level.txt +0 -0
  46. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/setup.cfg +0 -0
  47. {apx_aws_lambda-0.3.9 → apx_aws_lambda-0.3.11}/tests/test_proxy.py +0 -0
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apx-aws-lambda
3
- Version: 0.3.9
3
+ Version: 0.3.11
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.9
10
+ Requires-Dist: action-platform>=0.22.0
11
11
  Requires-Dist: awscli>=1.34
12
12
  Requires-Dist: aws-sam-cli>=1.120
13
13
  Provides-Extra: dev
@@ -48,7 +48,8 @@ action-platform diagnose
48
48
  | | |
49
49
  |---|---|
50
50
  | Overlay | `template.yaml`, `samconfig.toml`, `Makefile` and the language's entry point — `lambda_handler.py` (Mangum) for Python, `run.sh` behind the Lambda Web Adapter layer for Node and Spring (Java, Kotlin), `cmd/lambda/main.go` (`-tags lambda`) for Go, `lambda_handler.rb` (a Rack call, no server) for Ruby —, `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`) |
51
- | Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`) |
51
+ | Readiness | before a deploy, without building or changing anything: the tooling is there, the overlay is applied, the stack name resolves, the credentials work, the stack is not mid-operation or failed (a `ROLLBACK_COMPLETE` first creation is a warning — the deploy deletes it), the deploy role may do what the template needs (simulated with `iam:SimulatePrincipalPolicy` against the stack, the function, its log group, the execution role and every public layer the template references — the Lambda Web Adapter's, for one) and `sam validate --lint` passes. The platform runs it after every release for `dev` and `prod` and refuses a blocked deploy unless forced; `action-platform readiness` runs it on a machine |
52
+ | Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`); a stack left in `ROLLBACK_COMPLETE` by a failed first creation is deleted first |
52
53
  | Rollback | CloudFormation `rollback-stack` — previous stack state |
53
54
  | Diagnose | stack status and the HTTP API url |
54
55
  | Destroy | `sam delete` of the stage's stack; when no stage is left, the app leaves the proxy too (roles and grant) — the token must carry `org.manage`, which a platform deploy by an organization manager does |
@@ -178,11 +179,13 @@ Parameters: `IssuerUrl` (the platform's public url), `Organization` (one proxy s
178
179
 
179
180
  | Role | Trust | Policy |
180
181
  |---|---|---|
181
- | `ap-deploy-<org>-<project>-<app>` | the proxy's function role | CloudFormation on stacks `ap-<org>-<project>-<app>*`; Lambda, API Gateway and logs with the same prefix; `iam:PassRole` on the execution role; SAM's managed bucket |
182
+ | `ap-deploy-<org>-<project>-<app>` | the proxy's function role | CloudFormation on stacks `ap-<org>-<project>-<app>*`; Lambda, API Gateway and logs with the same prefix; `lambda:GetLayerVersion` on the public Lambda Web Adapter layers (account `753240598075`); `iam:PassRole` on the execution role; `iam:SimulatePrincipalPolicy` on itself, for readiness; SAM's managed bucket |
182
183
  | `ap-exec-<org>-<project>-<app>` | `lambda.amazonaws.com` | `AWSLambdaBasicExecutionRole` + the boundary |
183
184
 
184
185
  Both live under `/action-platform/`, carry tags `action-platform:app` and `action-platform:prefix`, and are idempotent: `create` again syncs trust policies, tags and policies without duplicating anything. `delete` removes both and the grants.
185
186
 
187
+ The deploy policy carries a version. An app registered by an older proxy gets its policy rewritten the first time it asks for credentials after the proxy was redeployed, so a wider policy reaches existing apps without re-registering them.
188
+
186
189
  ### The boundary
187
190
 
188
191
  `ActionPlatformBoundary` is one policy for every app, scoped per app by the role's `action-platform:prefix` tag used as a policy variable in the resources:
@@ -202,7 +205,7 @@ POST /apps/{org}/{project}/{app} create both roles; body {"regio
202
205
  GET /apps/{org}/{project}/{app} roles and grants org.manage
203
206
  DELETE /apps/{org}/{project}/{app} delete roles and grants org.manage
204
207
  PUT /apps/{org}/{project}/{app}/grants {"subjects": ["org:acme", …]} org.manage
205
- POST /apps/{org}/{project}/{app}/credentials {"duration": 900..3600} → temporary credentials a grant
208
+ POST /apps/{org}/{project}/{app}/credentials {"duration": 900..3600} → temporary credentials, stack_prefix, execution_role, deploy_role a grant
206
209
  ```
207
210
 
208
211
  Every call except `/health` carries `Authorization: Bearer <platform token>` with `aud` = the proxy url. The proxy checks the signature against the issuer's JWKS, `iss`, `aud`, expiry, and that `organization` is the one it serves. Admin calls need `org.manage` in the token's `scopes`; deploy-job tokens carry no scopes, so a compromised worker cannot widen a grant. `credentials` needs the token's `sub` to start with one of the app's granted subject prefixes.
@@ -28,7 +28,8 @@ action-platform diagnose
28
28
  | | |
29
29
  |---|---|
30
30
  | Overlay | `template.yaml`, `samconfig.toml`, `Makefile` and the language's entry point — `lambda_handler.py` (Mangum) for Python, `run.sh` behind the Lambda Web Adapter layer for Node and Spring (Java, Kotlin), `cmd/lambda/main.go` (`-tags lambda`) for Go, `lambda_handler.rb` (a Rack call, no server) for Ruby —, `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`) |
31
- | Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`) |
31
+ | Readiness | before a deploy, without building or changing anything: the tooling is there, the overlay is applied, the stack name resolves, the credentials work, the stack is not mid-operation or failed (a `ROLLBACK_COMPLETE` first creation is a warning — the deploy deletes it), the deploy role may do what the template needs (simulated with `iam:SimulatePrincipalPolicy` against the stack, the function, its log group, the execution role and every public layer the template references — the Lambda Web Adapter's, for one) and `sam validate --lint` passes. The platform runs it after every release for `dev` and `prod` and refuses a blocked deploy unless forced; `action-platform readiness` runs it on a machine |
32
+ | Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`); a stack left in `ROLLBACK_COMPLETE` by a failed first creation is deleted first |
32
33
  | Rollback | CloudFormation `rollback-stack` — previous stack state |
33
34
  | Diagnose | stack status and the HTTP API url |
34
35
  | Destroy | `sam delete` of the stage's stack; when no stage is left, the app leaves the proxy too (roles and grant) — the token must carry `org.manage`, which a platform deploy by an organization manager does |
@@ -158,11 +159,13 @@ Parameters: `IssuerUrl` (the platform's public url), `Organization` (one proxy s
158
159
 
159
160
  | Role | Trust | Policy |
160
161
  |---|---|---|
161
- | `ap-deploy-<org>-<project>-<app>` | the proxy's function role | CloudFormation on stacks `ap-<org>-<project>-<app>*`; Lambda, API Gateway and logs with the same prefix; `iam:PassRole` on the execution role; SAM's managed bucket |
162
+ | `ap-deploy-<org>-<project>-<app>` | the proxy's function role | CloudFormation on stacks `ap-<org>-<project>-<app>*`; Lambda, API Gateway and logs with the same prefix; `lambda:GetLayerVersion` on the public Lambda Web Adapter layers (account `753240598075`); `iam:PassRole` on the execution role; `iam:SimulatePrincipalPolicy` on itself, for readiness; SAM's managed bucket |
162
163
  | `ap-exec-<org>-<project>-<app>` | `lambda.amazonaws.com` | `AWSLambdaBasicExecutionRole` + the boundary |
163
164
 
164
165
  Both live under `/action-platform/`, carry tags `action-platform:app` and `action-platform:prefix`, and are idempotent: `create` again syncs trust policies, tags and policies without duplicating anything. `delete` removes both and the grants.
165
166
 
167
+ The deploy policy carries a version. An app registered by an older proxy gets its policy rewritten the first time it asks for credentials after the proxy was redeployed, so a wider policy reaches existing apps without re-registering them.
168
+
166
169
  ### The boundary
167
170
 
168
171
  `ActionPlatformBoundary` is one policy for every app, scoped per app by the role's `action-platform:prefix` tag used as a policy variable in the resources:
@@ -182,7 +185,7 @@ POST /apps/{org}/{project}/{app} create both roles; body {"regio
182
185
  GET /apps/{org}/{project}/{app} roles and grants org.manage
183
186
  DELETE /apps/{org}/{project}/{app} delete roles and grants org.manage
184
187
  PUT /apps/{org}/{project}/{app}/grants {"subjects": ["org:acme", …]} org.manage
185
- POST /apps/{org}/{project}/{app}/credentials {"duration": 900..3600} → temporary credentials a grant
188
+ POST /apps/{org}/{project}/{app}/credentials {"duration": 900..3600} → temporary credentials, stack_prefix, execution_role, deploy_role a grant
186
189
  ```
187
190
 
188
191
  Every call except `/health` carries `Authorization: Bearer <platform token>` with `aud` = the proxy url. The proxy checks the signature against the issuer's JWKS, `iss`, `aud`, expiry, and that `organization` is the one it serves. Admin calls need `org.manage` in the token's `scopes`; deploy-job tokens carry no scopes, so a compromised worker cannot widen a grant. `credentials` needs the token's `sub` to start with one of the app's granted subject prefixes.
@@ -5,11 +5,12 @@ Credentials, in order: `proxy_url` + `app` under `[deploy]` — the deploy proxy
5
5
  from __future__ import annotations
6
6
 
7
7
  import os
8
+ import re
8
9
  import tomllib
9
10
  from dataclasses import replace
10
11
 
11
12
  from action_platform.abc import DeployTarget
12
- from action_platform.core.context import Context, DeployResult, Diagnosis
13
+ from action_platform.core.context import Check, Context, DeployResult, Diagnosis
13
14
  from action_platform.core.exception import ActionPlatformError, DeployError
14
15
  from action_platform.logging import logger
15
16
  from action_platform.remote.client import Remote
@@ -155,6 +156,196 @@ class LambdaTarget(DeployTarget):
155
156
  env=self.env(ctx),
156
157
  )
157
158
 
159
+ def readiness(self, ctx: Context) -> list[Check]:
160
+ checks: list[Check] = []
161
+
162
+ for tool, hint in (
163
+ ("sam", "pip install aws-sam-cli"),
164
+ ("aws", "https://aws.amazon.com/cli/"),
165
+ ):
166
+ try:
167
+ shell.require(tool, hint)
168
+ checks.append(Check(f"tool.{tool}", True, "installed"))
169
+ except DeployError as e:
170
+ checks.append(Check(f"tool.{tool}", False, str(e), fix=hint))
171
+
172
+ if not (ctx.repo_root / "template.yaml").exists():
173
+ checks.append(
174
+ Check(
175
+ "template.present",
176
+ False,
177
+ "template.yaml not found",
178
+ fix="apply the aws/lambda overlay: action-platform cloud set aws/lambda",
179
+ )
180
+ )
181
+
182
+ return checks
183
+
184
+ try:
185
+ stack = self._stack(ctx)
186
+ checks.append(Check("stack.name", True, stack))
187
+ except DeployError as e:
188
+ checks.append(Check("stack.name", False, str(e), fix="fill samconfig.toml"))
189
+
190
+ return checks
191
+
192
+ try:
193
+ env = self.env(ctx)
194
+ identity = shell.aws(
195
+ "sts", "get-caller-identity", region=self._region(ctx), env=env
196
+ )
197
+ checks.append(
198
+ Check("aws.credentials", True, identity.get("Arn", "credentials work"))
199
+ )
200
+ except (DeployError, ProxyRefused) as e:
201
+ checks.append(
202
+ Check(
203
+ "aws.credentials",
204
+ False,
205
+ str(e),
206
+ fix="connect the deploy proxy or a role for this app in the AWS Lambda plugin",
207
+ )
208
+ )
209
+
210
+ return checks
211
+
212
+ checks.append(self._stack_state(ctx))
213
+ checks.extend(self._permissions(ctx, env, identity, stack))
214
+ checks.append(self._template_valid(ctx, env))
215
+
216
+ return checks
217
+
218
+ def _stack_state(self, ctx: Context) -> Check:
219
+ status = self._status(ctx)
220
+
221
+ if status is None:
222
+ return Check("stack.state", True, "no stack yet; the deploy creates it")
223
+
224
+ if status == "ROLLBACK_COMPLETE":
225
+ return Check(
226
+ "stack.state",
227
+ True,
228
+ f"{status}: the failed first creation is deleted before the deploy",
229
+ severity="warning",
230
+ )
231
+
232
+ if status.endswith("_IN_PROGRESS"):
233
+ return Check(
234
+ "stack.state",
235
+ False,
236
+ f"{status}: another operation is running on the stack",
237
+ fix="wait for it to finish, or cancel it in CloudFormation",
238
+ )
239
+
240
+ if status.endswith("_FAILED"):
241
+ return Check(
242
+ "stack.state",
243
+ False,
244
+ status,
245
+ fix="the stack needs attention in CloudFormation before a deploy can update it",
246
+ )
247
+
248
+ return Check("stack.state", True, status)
249
+
250
+ def _permissions(
251
+ self, ctx: Context, env: dict[str, str] | None, identity: dict, stack: str
252
+ ) -> list[Check]:
253
+ role = (env or {}).get("AP_DEPLOY_ROLE") or _role_of(identity.get("Arn", ""))
254
+
255
+ if not role:
256
+ return []
257
+
258
+ account = identity.get("Account", "")
259
+ region = self._region(ctx) or "us-east-1"
260
+ wanted: list[tuple[list[str], list[str]]] = [
261
+ (
262
+ ["cloudformation:CreateChangeSet", "cloudformation:DescribeStacks"],
263
+ [f"arn:aws:cloudformation:{region}:{account}:stack/{stack}/*"],
264
+ ),
265
+ (
266
+ ["lambda:CreateFunction", "lambda:UpdateFunctionCode"],
267
+ [f"arn:aws:lambda:{region}:{account}:function:{stack}-ApiFunction"],
268
+ ),
269
+ (
270
+ ["logs:CreateLogGroup"],
271
+ [
272
+ f"arn:aws:logs:{region}:{account}:log-group:/aws/lambda/{stack}-ApiFunction"
273
+ ],
274
+ ),
275
+ ]
276
+ layers = self._layers(ctx, region)
277
+
278
+ if layers:
279
+ wanted.append((["lambda:GetLayerVersion"], layers))
280
+
281
+ execution = (env or {}).get("AP_EXECUTION_ROLE")
282
+
283
+ if execution:
284
+ wanted.append((["iam:PassRole"], [execution]))
285
+
286
+ denied: list[str] = []
287
+
288
+ for actions, resources in wanted:
289
+ try:
290
+ data = shell.aws(
291
+ "iam",
292
+ "simulate-principal-policy",
293
+ "--policy-source-arn",
294
+ role,
295
+ "--action-names",
296
+ *actions,
297
+ "--resource-arns",
298
+ *resources,
299
+ env=env,
300
+ )
301
+ except DeployError as e:
302
+ return [
303
+ Check(
304
+ "aws.permissions",
305
+ True,
306
+ f"not simulated: {str(e)[:200]}",
307
+ severity="warning",
308
+ )
309
+ ]
310
+
311
+ for row in data.get("EvaluationResults") or []:
312
+ if row.get("EvalDecision") != "allowed":
313
+ denied.append(
314
+ f"{row.get('EvalActionName')} on {row.get('EvalResourceName')}"
315
+ )
316
+
317
+ if denied:
318
+ return [
319
+ Check(
320
+ "aws.permissions",
321
+ False,
322
+ f"{role} may not: " + "; ".join(denied),
323
+ fix="widen the deploy role's policy (redeploy the deploy proxy when it created the role)",
324
+ )
325
+ ]
326
+
327
+ return [Check("aws.permissions", True, f"{role} may deploy {stack}")]
328
+
329
+ def _layers(self, ctx: Context, region: str) -> list[str]:
330
+ text = (ctx.repo_root / "template.yaml").read_text(errors="replace")
331
+ text = text.replace("${AWS::Region}", region)
332
+
333
+ return sorted(
334
+ set(re.findall(r"arn:aws:lambda:[\w-]+:\d{12}:layer:[\w-]+:\d+", text))
335
+ )
336
+
337
+ def _template_valid(self, ctx: Context, env: dict[str, str] | None) -> Check:
338
+ try:
339
+ shell.run(
340
+ [*shell.require("sam", ""), "validate", "--lint"],
341
+ cwd=ctx.repo_root,
342
+ env=env,
343
+ )
344
+ except DeployError as e:
345
+ return Check("template.valid", False, str(e), fix="fix template.yaml")
346
+
347
+ return Check("template.valid", True, "sam validate --lint passes")
348
+
158
349
  def _status(self, ctx: Context) -> str | None:
159
350
  """The stack's CloudFormation status, or None when there is no stack."""
160
351
  try:
@@ -325,6 +516,12 @@ class LambdaTarget(DeployTarget):
325
516
  return None
326
517
 
327
518
 
519
+ def _role_of(arn: str) -> str | None:
520
+ found = re.match(r"^arn:aws:sts::(\d+):assumed-role/([^/]+)/", arn)
521
+
522
+ return f"arn:aws:iam::{found.group(1)}:role/{found.group(2)}" if found else None
523
+
524
+
328
525
  def assume_role(
329
526
  ctx: Context, role_arn: str, session_name: str, region: str | None
330
527
  ) -> dict[str, str]:
@@ -120,6 +120,7 @@ class ProxyClient:
120
120
  "AWS_SESSION_TOKEN": data["session_token"],
121
121
  "AP_STACK_PREFIX": data.get("stack_prefix", ""),
122
122
  "AP_EXECUTION_ROLE": data.get("execution_role", ""),
123
+ "AP_DEPLOY_ROLE": data.get("deploy_role", ""),
123
124
  }
124
125
 
125
126
  def _call(
@@ -1,13 +1,13 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apx-aws-lambda
3
- Version: 0.3.9
3
+ Version: 0.3.11
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.9
10
+ Requires-Dist: action-platform>=0.22.0
11
11
  Requires-Dist: awscli>=1.34
12
12
  Requires-Dist: aws-sam-cli>=1.120
13
13
  Provides-Extra: dev
@@ -48,7 +48,8 @@ action-platform diagnose
48
48
  | | |
49
49
  |---|---|
50
50
  | Overlay | `template.yaml`, `samconfig.toml`, `Makefile` and the language's entry point — `lambda_handler.py` (Mangum) for Python, `run.sh` behind the Lambda Web Adapter layer for Node and Spring (Java, Kotlin), `cmd/lambda/main.go` (`-tags lambda`) for Go, `lambda_handler.rb` (a Rack call, no server) for Ruby —, `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`) |
51
- | Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`) |
51
+ | Readiness | before a deploy, without building or changing anything: the tooling is there, the overlay is applied, the stack name resolves, the credentials work, the stack is not mid-operation or failed (a `ROLLBACK_COMPLETE` first creation is a warning — the deploy deletes it), the deploy role may do what the template needs (simulated with `iam:SimulatePrincipalPolicy` against the stack, the function, its log group, the execution role and every public layer the template references — the Lambda Web Adapter's, for one) and `sam validate --lint` passes. The platform runs it after every release for `dev` and `prod` and refuses a blocked deploy unless forced; `action-platform readiness` runs it on a machine |
52
+ | Deploy | `sam build` + `sam deploy --config-env <stage>` (`dev` → `default`, `prod` → `prod`); a stack left in `ROLLBACK_COMPLETE` by a failed first creation is deleted first |
52
53
  | Rollback | CloudFormation `rollback-stack` — previous stack state |
53
54
  | Diagnose | stack status and the HTTP API url |
54
55
  | Destroy | `sam delete` of the stage's stack; when no stage is left, the app leaves the proxy too (roles and grant) — the token must carry `org.manage`, which a platform deploy by an organization manager does |
@@ -178,11 +179,13 @@ Parameters: `IssuerUrl` (the platform's public url), `Organization` (one proxy s
178
179
 
179
180
  | Role | Trust | Policy |
180
181
  |---|---|---|
181
- | `ap-deploy-<org>-<project>-<app>` | the proxy's function role | CloudFormation on stacks `ap-<org>-<project>-<app>*`; Lambda, API Gateway and logs with the same prefix; `iam:PassRole` on the execution role; SAM's managed bucket |
182
+ | `ap-deploy-<org>-<project>-<app>` | the proxy's function role | CloudFormation on stacks `ap-<org>-<project>-<app>*`; Lambda, API Gateway and logs with the same prefix; `lambda:GetLayerVersion` on the public Lambda Web Adapter layers (account `753240598075`); `iam:PassRole` on the execution role; `iam:SimulatePrincipalPolicy` on itself, for readiness; SAM's managed bucket |
182
183
  | `ap-exec-<org>-<project>-<app>` | `lambda.amazonaws.com` | `AWSLambdaBasicExecutionRole` + the boundary |
183
184
 
184
185
  Both live under `/action-platform/`, carry tags `action-platform:app` and `action-platform:prefix`, and are idempotent: `create` again syncs trust policies, tags and policies without duplicating anything. `delete` removes both and the grants.
185
186
 
187
+ The deploy policy carries a version. An app registered by an older proxy gets its policy rewritten the first time it asks for credentials after the proxy was redeployed, so a wider policy reaches existing apps without re-registering them.
188
+
186
189
  ### The boundary
187
190
 
188
191
  `ActionPlatformBoundary` is one policy for every app, scoped per app by the role's `action-platform:prefix` tag used as a policy variable in the resources:
@@ -202,7 +205,7 @@ POST /apps/{org}/{project}/{app} create both roles; body {"regio
202
205
  GET /apps/{org}/{project}/{app} roles and grants org.manage
203
206
  DELETE /apps/{org}/{project}/{app} delete roles and grants org.manage
204
207
  PUT /apps/{org}/{project}/{app}/grants {"subjects": ["org:acme", …]} org.manage
205
- POST /apps/{org}/{project}/{app}/credentials {"duration": 900..3600} → temporary credentials a grant
208
+ POST /apps/{org}/{project}/{app}/credentials {"duration": 900..3600} → temporary credentials, stack_prefix, execution_role, deploy_role a grant
206
209
  ```
207
210
 
208
211
  Every call except `/health` carries `Authorization: Bearer <platform token>` with `aud` = the proxy url. The proxy checks the signature against the issuer's JWKS, `iss`, `aud`, expiry, and that `organization` is the one it serves. Admin calls need `org.manage` in the token's `scopes`; deploy-job tokens carry no scopes, so a compromised worker cannot widen a grant. `credentials` needs the token's `sub` to start with one of the app's granted subject prefixes.
@@ -1,4 +1,4 @@
1
- action-platform>=0.17.9
1
+ action-platform>=0.22.0
2
2
  awscli>=1.34
3
3
  aws-sam-cli>=1.120
4
4
 
@@ -1,12 +1,12 @@
1
1
  [project]
2
2
  name = "apx-aws-lambda"
3
- version = "0.3.9"
3
+ version = "0.3.11"
4
4
  description = "AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
7
7
  requires-python = ">=3.11"
8
8
  authors = [{ name = "Action Platform", email = "cloud@actionplatform.io" }]
9
- dependencies = ["action-platform>=0.17.9", "awscli>=1.34", "aws-sam-cli>=1.120"]
9
+ dependencies = ["action-platform>=0.22.0", "awscli>=1.34", "aws-sam-cli>=1.120"]
10
10
 
11
11
  [project.optional-dependencies]
12
12
  dev = ["pytest>=8", "ruff>=0.6", "action-platform[mcp]", "boto3>=1.34", "cryptography>=42"]
@@ -144,6 +144,113 @@ class LambdaTargetTest(unittest.TestCase):
144
144
  ["aws", "cloudformation", "delete-stack"], [c[:3] for c in self.calls]
145
145
  )
146
146
 
147
+ def test_readiness_reports_credentials_state_permissions_and_template(self):
148
+ (self.root / "template.yaml").write_text(
149
+ "Resources:\n Fn:\n Properties:\n Layers:\n"
150
+ " - !Sub arn:aws:lambda:${AWS::Region}:753240598075:layer:LambdaAdapterLayerArm64:25\n"
151
+ )
152
+ target = LambdaTarget(region="us-east-1")
153
+ target._env = {
154
+ "AP_DEPLOY_ROLE": "arn:aws:iam::1:role/action-platform/ap-deploy-x",
155
+ "AP_EXECUTION_ROLE": "arn:aws:iam::1:role/action-platform/ap-exec-x",
156
+ "AP_STACK_PREFIX": "ap-x",
157
+ }
158
+ simulated: list[list[str]] = []
159
+
160
+ def run(args, cwd=None, env=None):
161
+ self.calls.append([Path(args[0]).name, *args[1:]])
162
+ key = " ".join(args[1:3])
163
+
164
+ if key == "sts get-caller-identity":
165
+ return json.dumps(
166
+ {"Account": "1", "Arn": "arn:aws:sts::1:assumed-role/ap-deploy-x/p"}
167
+ )
168
+
169
+ if key == "cloudformation describe-stacks":
170
+ return json.dumps({"Stacks": [{"StackStatus": "UPDATE_COMPLETE"}]})
171
+
172
+ if key == "iam simulate-principal-policy":
173
+ simulated.append(args)
174
+ actions = args[
175
+ args.index("--action-names") + 1 : args.index("--resource-arns")
176
+ ]
177
+ resources = args[
178
+ args.index("--resource-arns") + 1 : args.index("--output")
179
+ ]
180
+
181
+ return json.dumps(
182
+ {
183
+ "EvaluationResults": [
184
+ {
185
+ "EvalActionName": a,
186
+ "EvalResourceName": r,
187
+ "EvalDecision": "implicitDeny"
188
+ if a == "lambda:GetLayerVersion"
189
+ else "allowed",
190
+ }
191
+ for a in actions
192
+ for r in resources
193
+ ]
194
+ }
195
+ )
196
+
197
+ return "{}"
198
+
199
+ with mock.patch.multiple(
200
+ shell, run=run, require=lambda tool, hint: [f"/usr/bin/{tool}"]
201
+ ):
202
+ checks = {c.id: c for c in target.readiness(self.ctx("prod"))}
203
+
204
+ self.assertTrue(checks["aws.credentials"].ok)
205
+ self.assertEqual(checks["stack.name"].detail, "ap-x-prod")
206
+ self.assertTrue(checks["stack.state"].ok)
207
+ self.assertFalse(checks["aws.permissions"].ok)
208
+ self.assertIn("lambda:GetLayerVersion", checks["aws.permissions"].detail)
209
+ self.assertIn("LambdaAdapterLayerArm64:25", checks["aws.permissions"].detail)
210
+ self.assertTrue(checks["template.valid"].ok)
211
+ self.assertTrue(
212
+ any("iam:PassRole" in args for args in simulated),
213
+ "the execution role's PassRole is simulated",
214
+ )
215
+ self.assertNotIn(["sam", "build"], [c[:2] for c in self.calls])
216
+
217
+ def test_readiness_flags_a_stack_with_an_operation_in_progress(self):
218
+ target = LambdaTarget(region="us-east-1")
219
+
220
+ with self.fake(
221
+ {
222
+ "sts get-caller-identity": {
223
+ "Account": "1",
224
+ "Arn": "arn:aws:iam::1:user/me",
225
+ },
226
+ "cloudformation describe-stacks": {
227
+ "Stacks": [{"StackStatus": "UPDATE_IN_PROGRESS"}]
228
+ },
229
+ }
230
+ ):
231
+ checks = {c.id: c for c in target.readiness(self.ctx("dev"))}
232
+
233
+ self.assertFalse(checks["stack.state"].ok)
234
+ self.assertIn("UPDATE_IN_PROGRESS", checks["stack.state"].detail)
235
+ self.assertNotIn("aws.permissions", checks)
236
+
237
+ def test_readiness_without_credentials_stops_there(self):
238
+ target = LambdaTarget(region="us-east-1")
239
+
240
+ def run(args, cwd=None, env=None):
241
+ if " ".join(args[1:3]) == "sts get-caller-identity":
242
+ raise DeployError("aws sts failed: Unable to locate credentials")
243
+
244
+ return "{}"
245
+
246
+ with mock.patch.multiple(
247
+ shell, run=run, require=lambda tool, hint: [f"/usr/bin/{tool}"]
248
+ ):
249
+ checks = target.readiness(self.ctx("dev"))
250
+
251
+ self.assertEqual(checks[-1].id, "aws.credentials")
252
+ self.assertFalse(checks[-1].ok)
253
+
147
254
  def test_diagnose_reads_the_stack(self):
148
255
  with self.fake(
149
256
  {
File without changes