apx-aws-lambda 1.2.2__tar.gz → 1.3.0__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 (37) hide show
  1. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/PKG-INFO +34 -11
  2. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/README.md +33 -10
  3. apx_aws_lambda-1.3.0/apx_aws_lambda/abc.py +83 -0
  4. apx_aws_lambda-1.3.0/apx_aws_lambda/checks.py +254 -0
  5. apx_aws_lambda-1.3.0/apx_aws_lambda/credentials.py +114 -0
  6. apx_aws_lambda-1.3.0/apx_aws_lambda/health.py +41 -0
  7. apx_aws_lambda-1.3.0/apx_aws_lambda/lambda_.py +242 -0
  8. apx_aws_lambda-1.3.0/apx_aws_lambda/sam.py +53 -0
  9. apx_aws_lambda-1.3.0/apx_aws_lambda/spec.py +180 -0
  10. apx_aws_lambda-1.3.0/apx_aws_lambda/stack.py +133 -0
  11. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda.egg-info/PKG-INFO +34 -11
  12. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda.egg-info/SOURCES.txt +7 -0
  13. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/pyproject.toml +1 -1
  14. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/tests/test_targets.py +154 -10
  15. apx_aws_lambda-1.2.2/apx_aws_lambda/lambda_.py +0 -677
  16. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/LICENSE +0 -0
  17. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/__init__.py +0 -0
  18. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/cli.py +0 -0
  19. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/connect/template.yaml +0 -0
  20. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
  21. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
  22. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
  23. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +0 -0
  24. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/Makefile +0 -0
  25. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
  26. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
  27. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
  28. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml +0 -0
  29. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/overlays/index.json +0 -0
  30. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/plugin.py +0 -0
  31. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/shell.py +0 -0
  32. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda/tools.py +0 -0
  33. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
  34. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
  35. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda.egg-info/requires.txt +0 -0
  36. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/apx_aws_lambda.egg-info/top_level.txt +0 -0
  37. {apx_aws_lambda-1.2.2 → apx_aws_lambda-1.3.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: apx-aws-lambda
3
- Version: 1.2.2
3
+ Version: 1.3.0
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
@@ -33,6 +33,7 @@ action-platform diagnose
33
33
  - [What the plugin does](#what-the-plugin-does)
34
34
  - [Credentials without keys](#credentials-without-keys)
35
35
  - [A connected account (recommended)](#a-connected-account-recommended)
36
+ - [Updating the connect stack](#updating-the-connect-stack)
36
37
  - [A role of your own (OIDC)](#a-role-of-your-own-oidc)
37
38
  - [The AWS CLI's own credentials](#the-aws-clis-own-credentials)
38
39
  - [Where the deploy runs](#where-the-deploy-runs)
@@ -44,9 +45,9 @@ action-platform diagnose
44
45
 
45
46
  | | |
46
47
  |---|---|
47
- | Overlay | `template.yaml`, `samconfig.toml`, a one-line `Makefile` (`ap-build package`), `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). One template for every language: the Lambda Web Adapter layer runs the project as an HTTP server on `$PORT` — `run.sh` from `ap-build` (Python `python3.12`, Node `nodejs22.x`, Java/Kotlin `java21`, Ruby `ruby3.3`) or the static `bootstrap` on `provided.al2023` (Go). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`) |
48
- | 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 |
49
- | 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. Every line `sam` prints reaches the platform's run log as it appears — the deploy form, the run dialog, `action-platform logs -f` |
48
+ | Overlay | `template.yaml`, `samconfig.toml`, a one-line `Makefile` (`ap-build package`), `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). One template for every language: the Lambda Web Adapter layer runs the project as an HTTP server on `$PORT` — `run.sh` from `ap-build` (Python `python3.12`, Node `nodejs22.x`, Java/Kotlin `java21`, Ruby `ruby3.3`) or the static `bootstrap` on `provided.al2023` (Go). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`). Template parameters the target fills: `Stage` (the scope's name), and for a connected account `PermissionsBoundaryArn` and `RolePath` |
49
+ | 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 failed first creation — `ROLLBACK_COMPLETE` or `ROLLBACK_FAILED` — is a warning: the deploy deletes it), the overlay takes a connected account's boundary and role path, 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 each of the app's scopes and refuses a blocked deploy unless forced; `action-platform readiness` runs it on a machine |
50
+ | Deploy | `sam build` + `sam deploy --config-env <stage>` (scope `prod` → `prod`, any other → `default`). A stack left by a failed first creation (`ROLLBACK_COMPLETE`, `ROLLBACK_FAILED`) is deleted first; when that delete fails on a resource that was never created, the stack is deleted again with it retained. On a connected account, an overlay without `PermissionsBoundaryArn` and `RolePath` stops the deploy before the build. Every line `sam` prints reaches the platform's run log as it appears — the deploy form, the run dialog, `action-platform logs -f` |
50
51
  | Rollback | CloudFormation `rollback-stack` — previous stack state |
51
52
  | Diagnose | stack status and the HTTP API url |
52
53
  | Destroy | `sam delete` of the stage's stack, the execution role SAM created with it |
@@ -59,6 +60,7 @@ action-platform diagnose
59
60
  [deploy]
60
61
  target = "aws/lambda"
61
62
  region = "us-east-1" # optional; samconfig.toml / AWS_REGION otherwise
63
+ health = "/health" # optional; checked through the HTTP API after the deploy, "" skips it
62
64
  ```
63
65
 
64
66
  Deploying itself goes through the core's `deploy` / `rollback` / `diagnose`, which drive the target.
@@ -70,20 +72,24 @@ The target looks for credentials in this order:
70
72
  | Under `[deploy]` | How | Who decides what the app may do |
71
73
  |---|---|---|
72
74
  | `role_arn` | `sts assume-role-with-web-identity` with a platform token | the role's trust and permission policies |
73
- | neither, and the organization's deploy role set on the platform (Plugins → AWS Lambda), which every deploy job carries as `AP_AWS_LAMBDA_ROLE_ARN` with `AP_APP` | `sts assume-role-with-web-identity` on the connect stack's role with the platform's token for the app | the token's session tag and the role's policy, in your account |
75
+ | neither, and the organization's AWS account ID (or deploy role ARN) set on the platform (Plugins → AWS Lambda), which every deploy job carries as `AP_AWS_LAMBDA_ROLE_ARN` with `AP_APP` | `sts assume-role-with-web-identity` on the connect stack's role with the platform's token for the app | the token's session tag and the role's policy, in your account |
74
76
  | neither | the AWS CLI's own chain: SSO, profile, instance role | whatever that identity may do |
75
77
 
76
78
  ### A connected account (recommended)
77
79
 
78
80
  One CloudFormation stack, IAM only — no function, no table, nothing to upgrade. AWS itself trusts the platform's OIDC tokens; the token's session tag keeps each deploy inside its app.
79
81
 
80
- **1. Create the stack** — once per AWS account, with your own AWS credentials (not the root account). On the platform: Plugins → AWS Lambda → Configure → **Connect AWS** copies the command and opens AWS CloudShell (the AWS sign-in first); paste, press Enter, and paste the account ID it prints into the field. Or in the console: CloudFormation → Create stack → *Upload a template file* → [`apx_aws_lambda/connect/template.yaml`](apx_aws_lambda/connect/template.yaml), parameters `IssuerUrl` (the platform's public url) and `Organization` (its slug), acknowledge IAM; or from a machine:
82
+ **1. Create the stack** — once per AWS account, with an IAM user or role that may create IAM resources (not the root account). On the platform: Plugins → AWS Lambda → Configure → **Connect AWS**. The button copies a command and opens AWS CloudShell, behind the AWS sign-in; paste the command and press Enter. It downloads this release's [`connect/template.yaml`](apx_aws_lambda/connect/template.yaml) from GitHub, deploys it as the stack `action-platform-connect` in `us-east-1` with the platform's url and the organization's slug, and prints the account ID.
83
+
84
+ Without the button, the same stack from a machine logged in to the account:
81
85
 
82
86
  ```bash
83
87
  action-platform aws-lambda connect https://platform.example.com acme # --region, --stack-name, --oidc-provider-arn
84
88
  ```
85
89
 
86
- **2. Tell the platform** — Plugins → AWS Lambda → Configure → **AWS account ID** = the 12-digit account ID (or the stack's `DeployRoleArn` output). Every app of the organization whose `platform.toml` says `target = "aws/lambda"` deploys from then on; nothing to register per app.
90
+ or in the console: CloudFormation → Create stack → *Upload a template file* → [`apx_aws_lambda/connect/template.yaml`](apx_aws_lambda/connect/template.yaml), parameters `IssuerUrl` (the platform's public url) and `Organization` (its slug), acknowledge IAM.
91
+
92
+ **2. Tell the platform** — Plugins → AWS Lambda → Configure → **AWS account ID** = the 12 digits the command printed (the stack's `DeployRoleArn` output works too). Every app of the organization whose `platform.toml` says `target = "aws/lambda"` deploys from then on; nothing to register per app.
87
93
 
88
94
  What the stack creates:
89
95
 
@@ -91,11 +97,15 @@ What the stack creates:
91
97
  |---|---|
92
98
  | IAM OIDC provider | trusts `IssuerUrl` for audience `sts.amazonaws.com`; pass `OidcProviderArn` when the account already has one for the platform |
93
99
  | `ActionPlatformAppBoundary` (`/action-platform/`) | the cap on every execution role an app's stack creates — logs `/aws/lambda/<prefix>*`; S3 buckets, DynamoDB tables, SQS queues, SNS topics, Lambda functions `<prefix>-*`; Secrets Manager secrets and SSM parameters `<prefix>/*`; X-Ray — `<prefix>` being the role's `action-platform:prefix` tag. An app's own `template.yaml` still declares what its function needs; the boundary caps it |
94
- | `ActionPlatformDeploy` role (`/action-platform/`) | trust: `AssumeRoleWithWebIdentity` for `sub` `org:<org>:*`, and `TagSession` only for the one tag `action-platform:prefix` with a value `ap-<org>-*`. Policy: every resource under `${aws:PrincipalTag/action-platform:prefix}` — CloudFormation stacks, Lambda, logs; API Gateway; the public Lambda Web Adapter layers; SAM's bucket; `iam:CreateRole` on `<prefix>-*` only with the boundary attached and the app's own prefix tag, `iam:PassRole` of those roles to Lambda only; `iam:SimulatePrincipalPolicy` on itself |
100
+ | `ActionPlatformDeploy` role (`/action-platform/`) | trust: `AssumeRoleWithWebIdentity` for `sub` `org:<org>:*`, and `TagSession` only for the one tag `action-platform:prefix` with a value `ap-<org>-*`. Policy: every resource under `${aws:PrincipalTag/action-platform:prefix}` — CloudFormation stacks, Lambda, logs; API Gateway; the public Lambda Web Adapter layers; SAM's bucket; IAM on roles under the path `/action-platform/<prefix>/` only — `iam:CreateRole` with the boundary attached and the app's own prefix tag, `iam:PassRole` to Lambda only; `iam:SimulatePrincipalPolicy` on itself |
101
+
102
+ How a deploy runs: the platform signs a token for the app with the claim `https://aws.amazon.com/tags` → `principal_tags.action-platform:prefix = ap-<org>-<project>-<app>`; the target assumes the deploy role with it, names the stack `ap-<org>-<project>-<app>-<scope>`, passes `PermissionsBoundaryArn` and `RolePath=/action-platform/<prefix>/` to the overlay's template and tags the stack with the prefix, so the execution role SAM creates carries the boundary and the tag and lives under the app's path. The path, not the name, tells an app's roles apart: CloudFormation cuts a generated role name to 64 characters, which can drop the prefix from it. `sam delete` removes that role with the stack. Who may deploy which app is the platform's decision — it only signs a token for an app the job or the caller is for.
95
103
 
96
- How a deploy runs: the platform signs a token for the app with the claim `https://aws.amazon.com/tags` → `principal_tags.action-platform:prefix = ap-<org>-<project>-<app>`; the target assumes the deploy role with it, names the stack `ap-<org>-<project>-<app>-<scope>`, passes `PermissionsBoundaryArn` to the overlay's template and tags the stack with the prefix, so the execution role SAM creates carries both the boundary and the tag. `sam delete` removes that role with the stack. Who may deploy which app is the platform's decision — it only signs a token for an app the job or the caller is for.
104
+ Readiness simulates the deploy role with the session tag, the boundary and `iam:PassedToService` as context entries, and flags an overlay without the `PermissionsBoundaryArn` or `RolePath` parameter. An app whose overlay predates them applies it again: Configuration → **Deploy target**, or `action-platform cloud set aws/lambda`. The stack's policy is the one place to widen or narrow what deploys may do.
97
105
 
98
- Readiness simulates the deploy role with the session tag and the boundary as context entries, and flags an overlay without the `PermissionsBoundaryArn` parameter (apply the overlay again). The stack's policy is the one place to widen or narrow what deploys may do: edit and update the stack.
106
+ ### Updating the connect stack
107
+
108
+ The command pins the template to the plugin's release. After the platform moves to a plugin whose connect template changed, run **Connect AWS** again (or `action-platform aws-lambda connect …`): CloudFormation updates `action-platform-connect` in place, and the account ID stays the same.
99
109
 
100
110
  ### A role of your own (OIDC)
101
111
 
@@ -157,7 +167,8 @@ Independent of how credentials are obtained:
157
167
  - `aws` and `sam` — on PATH when present; otherwise the `awscli` and `aws-sam-cli` packages the plugin depends on run as `python -m`, which is how the hosted platform deploys without the CLIs in its image.
158
168
  - `AWS_REGION` or `region` under `[deploy]`.
159
169
  - Network: `*.amazonaws.com`.
160
- - Connecting the account: credentials for it, once — the console, or `aws` for `action-platform aws-lambda connect`.
170
+ - Connecting the account: credentials for it that may create IAM resources, once — AWS CloudShell through the Connect AWS button, the console, or `aws` for `action-platform aws-lambda connect`.
171
+ - `action-platform` 0.32.0 or newer: the Connect AWS button is an option action of the core.
161
172
 
162
173
  ## Development
163
174
 
@@ -167,3 +178,15 @@ pytest
167
178
  ```
168
179
 
169
180
  The tests fake `aws` and `sam`; nothing reaches AWS.
181
+
182
+ | Module | Responsibility (ABC in `abc.py`) |
183
+ |---|---|
184
+ | `lambda_.py` | `LambdaTarget`: the core's `DeployTarget` contract, composing the parts below through `parts(spec, access)` |
185
+ | `spec.py` | `Spec`: samconfig, stack, region and — for a connected account — prefix, deploy role, boundary, resolved once per call without calling AWS |
186
+ | `credentials.py` | `Credentials`: `OwnRole` (`[deploy] role_arn`), `ConnectedAccount`, `CliChain` — which identity `aws` and `sam` act as |
187
+ | `stack.py` | `Stack`: the CloudFormation stack — status, outputs, clearing a failed first creation, rollback |
188
+ | `sam.py` | `Sam`: build, deploy, delete, validate |
189
+ | `health.py` | `Health`: the function answers its health route after the deploy |
190
+ | `checks.py` | `Readiness`: one class per check |
191
+ | `shell.py` | running `aws` and `sam`, streaming `sam`'s output to the job log |
192
+ | `tools.py`, `cli.py` | read-only views for MCP and the terminal; `connect` |
@@ -15,6 +15,7 @@ action-platform diagnose
15
15
  - [What the plugin does](#what-the-plugin-does)
16
16
  - [Credentials without keys](#credentials-without-keys)
17
17
  - [A connected account (recommended)](#a-connected-account-recommended)
18
+ - [Updating the connect stack](#updating-the-connect-stack)
18
19
  - [A role of your own (OIDC)](#a-role-of-your-own-oidc)
19
20
  - [The AWS CLI's own credentials](#the-aws-clis-own-credentials)
20
21
  - [Where the deploy runs](#where-the-deploy-runs)
@@ -26,9 +27,9 @@ action-platform diagnose
26
27
 
27
28
  | | |
28
29
  |---|---|
29
- | Overlay | `template.yaml`, `samconfig.toml`, a one-line `Makefile` (`ap-build package`), `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). One template for every language: the Lambda Web Adapter layer runs the project as an HTTP server on `$PORT` — `run.sh` from `ap-build` (Python `python3.12`, Node `nodejs22.x`, Java/Kotlin `java21`, Ruby `ruby3.3`) or the static `bootstrap` on `provided.al2023` (Go). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`) |
30
- | 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 |
31
- | 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. Every line `sam` prints reaches the platform's run log as it appears — the deploy form, the run dialog, `action-platform logs -f` |
30
+ | Overlay | `template.yaml`, `samconfig.toml`, a one-line `Makefile` (`ap-build package`), `requirements/` (IAM examples), `.github/workflows/deploy.yml` (optional). One template for every language: the Lambda Web Adapter layer runs the project as an HTTP server on `$PORT` — `run.sh` from `ap-build` (Python `python3.12`, Node `nodejs22.x`, Java/Kotlin `java21`, Ruby `ruby3.3`) or the static `bootstrap` on `provided.al2023` (Go). Every `web/*` template of the official repository deploys; the health route is `/health` (API Gateway keeps `/ping` for itself on `execute-api`). Template parameters the target fills: `Stage` (the scope's name), and for a connected account `PermissionsBoundaryArn` and `RolePath` |
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 failed first creation — `ROLLBACK_COMPLETE` or `ROLLBACK_FAILED` — is a warning: the deploy deletes it), the overlay takes a connected account's boundary and role path, 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 each of the app's scopes and refuses a blocked deploy unless forced; `action-platform readiness` runs it on a machine |
32
+ | Deploy | `sam build` + `sam deploy --config-env <stage>` (scope `prod` → `prod`, any other → `default`). A stack left by a failed first creation (`ROLLBACK_COMPLETE`, `ROLLBACK_FAILED`) is deleted first; when that delete fails on a resource that was never created, the stack is deleted again with it retained. On a connected account, an overlay without `PermissionsBoundaryArn` and `RolePath` stops the deploy before the build. Every line `sam` prints reaches the platform's run log as it appears — the deploy form, the run dialog, `action-platform logs -f` |
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, the execution role SAM created with it |
@@ -41,6 +42,7 @@ action-platform diagnose
41
42
  [deploy]
42
43
  target = "aws/lambda"
43
44
  region = "us-east-1" # optional; samconfig.toml / AWS_REGION otherwise
45
+ health = "/health" # optional; checked through the HTTP API after the deploy, "" skips it
44
46
  ```
45
47
 
46
48
  Deploying itself goes through the core's `deploy` / `rollback` / `diagnose`, which drive the target.
@@ -52,20 +54,24 @@ The target looks for credentials in this order:
52
54
  | Under `[deploy]` | How | Who decides what the app may do |
53
55
  |---|---|---|
54
56
  | `role_arn` | `sts assume-role-with-web-identity` with a platform token | the role's trust and permission policies |
55
- | neither, and the organization's deploy role set on the platform (Plugins → AWS Lambda), which every deploy job carries as `AP_AWS_LAMBDA_ROLE_ARN` with `AP_APP` | `sts assume-role-with-web-identity` on the connect stack's role with the platform's token for the app | the token's session tag and the role's policy, in your account |
57
+ | neither, and the organization's AWS account ID (or deploy role ARN) set on the platform (Plugins → AWS Lambda), which every deploy job carries as `AP_AWS_LAMBDA_ROLE_ARN` with `AP_APP` | `sts assume-role-with-web-identity` on the connect stack's role with the platform's token for the app | the token's session tag and the role's policy, in your account |
56
58
  | neither | the AWS CLI's own chain: SSO, profile, instance role | whatever that identity may do |
57
59
 
58
60
  ### A connected account (recommended)
59
61
 
60
62
  One CloudFormation stack, IAM only — no function, no table, nothing to upgrade. AWS itself trusts the platform's OIDC tokens; the token's session tag keeps each deploy inside its app.
61
63
 
62
- **1. Create the stack** — once per AWS account, with your own AWS credentials (not the root account). On the platform: Plugins → AWS Lambda → Configure → **Connect AWS** copies the command and opens AWS CloudShell (the AWS sign-in first); paste, press Enter, and paste the account ID it prints into the field. Or in the console: CloudFormation → Create stack → *Upload a template file* → [`apx_aws_lambda/connect/template.yaml`](apx_aws_lambda/connect/template.yaml), parameters `IssuerUrl` (the platform's public url) and `Organization` (its slug), acknowledge IAM; or from a machine:
64
+ **1. Create the stack** — once per AWS account, with an IAM user or role that may create IAM resources (not the root account). On the platform: Plugins → AWS Lambda → Configure → **Connect AWS**. The button copies a command and opens AWS CloudShell, behind the AWS sign-in; paste the command and press Enter. It downloads this release's [`connect/template.yaml`](apx_aws_lambda/connect/template.yaml) from GitHub, deploys it as the stack `action-platform-connect` in `us-east-1` with the platform's url and the organization's slug, and prints the account ID.
65
+
66
+ Without the button, the same stack from a machine logged in to the account:
63
67
 
64
68
  ```bash
65
69
  action-platform aws-lambda connect https://platform.example.com acme # --region, --stack-name, --oidc-provider-arn
66
70
  ```
67
71
 
68
- **2. Tell the platform** — Plugins → AWS Lambda → Configure → **AWS account ID** = the 12-digit account ID (or the stack's `DeployRoleArn` output). Every app of the organization whose `platform.toml` says `target = "aws/lambda"` deploys from then on; nothing to register per app.
72
+ or in the console: CloudFormation → Create stack → *Upload a template file* → [`apx_aws_lambda/connect/template.yaml`](apx_aws_lambda/connect/template.yaml), parameters `IssuerUrl` (the platform's public url) and `Organization` (its slug), acknowledge IAM.
73
+
74
+ **2. Tell the platform** — Plugins → AWS Lambda → Configure → **AWS account ID** = the 12 digits the command printed (the stack's `DeployRoleArn` output works too). Every app of the organization whose `platform.toml` says `target = "aws/lambda"` deploys from then on; nothing to register per app.
69
75
 
70
76
  What the stack creates:
71
77
 
@@ -73,11 +79,15 @@ What the stack creates:
73
79
  |---|---|
74
80
  | IAM OIDC provider | trusts `IssuerUrl` for audience `sts.amazonaws.com`; pass `OidcProviderArn` when the account already has one for the platform |
75
81
  | `ActionPlatformAppBoundary` (`/action-platform/`) | the cap on every execution role an app's stack creates — logs `/aws/lambda/<prefix>*`; S3 buckets, DynamoDB tables, SQS queues, SNS topics, Lambda functions `<prefix>-*`; Secrets Manager secrets and SSM parameters `<prefix>/*`; X-Ray — `<prefix>` being the role's `action-platform:prefix` tag. An app's own `template.yaml` still declares what its function needs; the boundary caps it |
76
- | `ActionPlatformDeploy` role (`/action-platform/`) | trust: `AssumeRoleWithWebIdentity` for `sub` `org:<org>:*`, and `TagSession` only for the one tag `action-platform:prefix` with a value `ap-<org>-*`. Policy: every resource under `${aws:PrincipalTag/action-platform:prefix}` — CloudFormation stacks, Lambda, logs; API Gateway; the public Lambda Web Adapter layers; SAM's bucket; `iam:CreateRole` on `<prefix>-*` only with the boundary attached and the app's own prefix tag, `iam:PassRole` of those roles to Lambda only; `iam:SimulatePrincipalPolicy` on itself |
82
+ | `ActionPlatformDeploy` role (`/action-platform/`) | trust: `AssumeRoleWithWebIdentity` for `sub` `org:<org>:*`, and `TagSession` only for the one tag `action-platform:prefix` with a value `ap-<org>-*`. Policy: every resource under `${aws:PrincipalTag/action-platform:prefix}` — CloudFormation stacks, Lambda, logs; API Gateway; the public Lambda Web Adapter layers; SAM's bucket; IAM on roles under the path `/action-platform/<prefix>/` only — `iam:CreateRole` with the boundary attached and the app's own prefix tag, `iam:PassRole` to Lambda only; `iam:SimulatePrincipalPolicy` on itself |
83
+
84
+ How a deploy runs: the platform signs a token for the app with the claim `https://aws.amazon.com/tags` → `principal_tags.action-platform:prefix = ap-<org>-<project>-<app>`; the target assumes the deploy role with it, names the stack `ap-<org>-<project>-<app>-<scope>`, passes `PermissionsBoundaryArn` and `RolePath=/action-platform/<prefix>/` to the overlay's template and tags the stack with the prefix, so the execution role SAM creates carries the boundary and the tag and lives under the app's path. The path, not the name, tells an app's roles apart: CloudFormation cuts a generated role name to 64 characters, which can drop the prefix from it. `sam delete` removes that role with the stack. Who may deploy which app is the platform's decision — it only signs a token for an app the job or the caller is for.
77
85
 
78
- How a deploy runs: the platform signs a token for the app with the claim `https://aws.amazon.com/tags` → `principal_tags.action-platform:prefix = ap-<org>-<project>-<app>`; the target assumes the deploy role with it, names the stack `ap-<org>-<project>-<app>-<scope>`, passes `PermissionsBoundaryArn` to the overlay's template and tags the stack with the prefix, so the execution role SAM creates carries both the boundary and the tag. `sam delete` removes that role with the stack. Who may deploy which app is the platform's decision — it only signs a token for an app the job or the caller is for.
86
+ Readiness simulates the deploy role with the session tag, the boundary and `iam:PassedToService` as context entries, and flags an overlay without the `PermissionsBoundaryArn` or `RolePath` parameter. An app whose overlay predates them applies it again: Configuration → **Deploy target**, or `action-platform cloud set aws/lambda`. The stack's policy is the one place to widen or narrow what deploys may do.
79
87
 
80
- Readiness simulates the deploy role with the session tag and the boundary as context entries, and flags an overlay without the `PermissionsBoundaryArn` parameter (apply the overlay again). The stack's policy is the one place to widen or narrow what deploys may do: edit and update the stack.
88
+ ### Updating the connect stack
89
+
90
+ The command pins the template to the plugin's release. After the platform moves to a plugin whose connect template changed, run **Connect AWS** again (or `action-platform aws-lambda connect …`): CloudFormation updates `action-platform-connect` in place, and the account ID stays the same.
81
91
 
82
92
  ### A role of your own (OIDC)
83
93
 
@@ -139,7 +149,8 @@ Independent of how credentials are obtained:
139
149
  - `aws` and `sam` — on PATH when present; otherwise the `awscli` and `aws-sam-cli` packages the plugin depends on run as `python -m`, which is how the hosted platform deploys without the CLIs in its image.
140
150
  - `AWS_REGION` or `region` under `[deploy]`.
141
151
  - Network: `*.amazonaws.com`.
142
- - Connecting the account: credentials for it, once — the console, or `aws` for `action-platform aws-lambda connect`.
152
+ - Connecting the account: credentials for it that may create IAM resources, once — AWS CloudShell through the Connect AWS button, the console, or `aws` for `action-platform aws-lambda connect`.
153
+ - `action-platform` 0.32.0 or newer: the Connect AWS button is an option action of the core.
143
154
 
144
155
  ## Development
145
156
 
@@ -149,3 +160,15 @@ pytest
149
160
  ```
150
161
 
151
162
  The tests fake `aws` and `sam`; nothing reaches AWS.
163
+
164
+ | Module | Responsibility (ABC in `abc.py`) |
165
+ |---|---|
166
+ | `lambda_.py` | `LambdaTarget`: the core's `DeployTarget` contract, composing the parts below through `parts(spec, access)` |
167
+ | `spec.py` | `Spec`: samconfig, stack, region and — for a connected account — prefix, deploy role, boundary, resolved once per call without calling AWS |
168
+ | `credentials.py` | `Credentials`: `OwnRole` (`[deploy] role_arn`), `ConnectedAccount`, `CliChain` — which identity `aws` and `sam` act as |
169
+ | `stack.py` | `Stack`: the CloudFormation stack — status, outputs, clearing a failed first creation, rollback |
170
+ | `sam.py` | `Sam`: build, deploy, delete, validate |
171
+ | `health.py` | `Health`: the function answers its health route after the deploy |
172
+ | `checks.py` | `Readiness`: one class per check |
173
+ | `shell.py` | running `aws` and `sam`, streaming `sam`'s output to the job log |
174
+ | `tools.py`, `cli.py` | read-only views for MCP and the terminal; `connect` |
@@ -0,0 +1,83 @@
1
+ """The responsibilities an aws/lambda deploy is made of, one contract each; `LambdaTarget` composes an implementation of every one."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from abc import ABC, abstractmethod
6
+ from dataclasses import dataclass
7
+ from typing import TYPE_CHECKING
8
+
9
+ if TYPE_CHECKING:
10
+ from action_platform.core.context import Check
11
+
12
+ from apx_aws_lambda.spec import Spec
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class Access:
17
+ """How `aws` and `sam` run: `env` holds temporary credentials (None: the caller's own), `deploy_role` the role they act as when it is known up front."""
18
+
19
+ env: dict[str, str] | None
20
+ deploy_role: str | None = None
21
+
22
+
23
+ class Credentials(ABC):
24
+ """Which AWS identity the deploy acts as."""
25
+
26
+ @abstractmethod
27
+ def access(self, spec: Spec) -> Access: ...
28
+
29
+
30
+ class Stack(ABC):
31
+ """The scope's CloudFormation stack."""
32
+
33
+ @abstractmethod
34
+ def status(self) -> str | None:
35
+ """Its status, or None when there is no stack."""
36
+
37
+ @abstractmethod
38
+ def describe(self) -> dict | None:
39
+ """The stack as CloudFormation describes it (status, outputs), or None."""
40
+
41
+ @abstractmethod
42
+ def clear_failed_creation(self) -> None:
43
+ """Delete a stack left by a first creation that failed, so the deploy can create it again."""
44
+
45
+ @abstractmethod
46
+ def rollback(self) -> None: ...
47
+
48
+ @abstractmethod
49
+ def failure(self) -> str | None:
50
+ """Why the latest operation failed: each FAILED resource and its reason."""
51
+
52
+
53
+ class Sam(ABC):
54
+ """The SAM CLI on the repository."""
55
+
56
+ @abstractmethod
57
+ def build(self) -> None: ...
58
+
59
+ @abstractmethod
60
+ def deploy(self) -> None: ...
61
+
62
+ @abstractmethod
63
+ def delete(self) -> None: ...
64
+
65
+ @abstractmethod
66
+ def validate(self) -> None: ...
67
+
68
+
69
+ class Health(ABC):
70
+ """Whether the deployed application answers."""
71
+
72
+ @abstractmethod
73
+ def answers(self, url: str) -> str | None:
74
+ """None when `url` answers 2xx in time; otherwise what it did instead."""
75
+
76
+
77
+ class Readiness(ABC):
78
+ """One check a deploy needs to pass, run without building or changing anything."""
79
+
80
+ id: str
81
+
82
+ @abstractmethod
83
+ def run(self, spec: Spec) -> Check: ...
@@ -0,0 +1,254 @@
1
+ """Readiness, one class per check, run in the order the target lists them: tooling, the overlay, the stack name, the credentials, the boundary, the stack's state, the deploy role's permissions, the template."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+
7
+ from action_platform.core.context import Check
8
+ from action_platform.core.exception import DeployError
9
+
10
+ from apx_aws_lambda import shell
11
+ from apx_aws_lambda.abc import Access, Readiness, Sam, Stack
12
+ from apx_aws_lambda.spec import PREFIX_TAG, Spec
13
+ from apx_aws_lambda.stack import FAILED_CREATION
14
+
15
+
16
+ class ToolCheck(Readiness):
17
+ def __init__(self, tool: str, hint: str) -> None:
18
+ self.tool = tool
19
+ self.hint = hint
20
+ self.id = f"tool.{tool}"
21
+
22
+ def run(self, spec: Spec) -> Check:
23
+ try:
24
+ shell.require(self.tool, self.hint)
25
+ except DeployError as e:
26
+ return Check(self.id, False, str(e), fix=self.hint)
27
+
28
+ return Check(self.id, True, "installed")
29
+
30
+
31
+ class TemplateCheck(Readiness):
32
+ id = "template.present"
33
+
34
+ def run(self, spec: Spec) -> Check:
35
+ if spec.template.exists():
36
+ return Check(self.id, True, "template.yaml is there")
37
+
38
+ return Check(
39
+ self.id,
40
+ False,
41
+ "template.yaml not found",
42
+ fix="apply the aws/lambda overlay: action-platform cloud set aws/lambda",
43
+ )
44
+
45
+
46
+ class StackNameCheck(Readiness):
47
+ id = "stack.name"
48
+
49
+ def run(self, spec: Spec) -> Check:
50
+ try:
51
+ return Check(self.id, True, spec.stack)
52
+ except DeployError as e:
53
+ return Check(self.id, False, str(e), fix="fill samconfig.toml")
54
+
55
+
56
+ class CredentialsCheck(Readiness):
57
+ """Who the deploy acts as; `identity` keeps the answer for the permissions check."""
58
+
59
+ id = "aws.credentials"
60
+
61
+ def __init__(self, access: Access) -> None:
62
+ self.access = access
63
+ self.identity: dict = {}
64
+
65
+ def run(self, spec: Spec) -> Check:
66
+ try:
67
+ self.identity = shell.aws(
68
+ "sts", "get-caller-identity", region=spec.region, env=self.access.env
69
+ )
70
+ except DeployError as e:
71
+ return Check(
72
+ self.id,
73
+ False,
74
+ str(e),
75
+ fix="connect the AWS account in the AWS Lambda plugin",
76
+ )
77
+
78
+ return Check(self.id, True, self.identity.get("Arn", "credentials work"))
79
+
80
+
81
+ class BoundaryCheck(Readiness):
82
+ id = "template.boundary"
83
+
84
+ def run(self, spec: Spec) -> Check:
85
+ if spec.takes_boundary:
86
+ return Check(self.id, True, "the execution role takes the boundary")
87
+
88
+ return Check(
89
+ self.id,
90
+ False,
91
+ "template.yaml lacks the PermissionsBoundaryArn or RolePath parameter: a connected account creates the execution role only within its boundary, under the app's path",
92
+ fix="apply the aws/lambda overlay again: action-platform cloud set aws/lambda",
93
+ )
94
+
95
+
96
+ class StackStateCheck(Readiness):
97
+ id = "stack.state"
98
+
99
+ def __init__(self, stack: Stack) -> None:
100
+ self.stack = stack
101
+
102
+ def run(self, spec: Spec) -> Check:
103
+ status = self.stack.status()
104
+
105
+ if status is None:
106
+ return Check(self.id, True, "no stack yet; the deploy creates it")
107
+
108
+ if status in FAILED_CREATION:
109
+ return Check(
110
+ self.id,
111
+ True,
112
+ f"{status}: the failed first creation is deleted before the deploy",
113
+ severity="warning",
114
+ )
115
+
116
+ if status.endswith("_IN_PROGRESS"):
117
+ return Check(
118
+ self.id,
119
+ False,
120
+ f"{status}: another operation is running on the stack",
121
+ fix="wait for it to finish, or cancel it in CloudFormation",
122
+ )
123
+
124
+ if status.endswith("_FAILED"):
125
+ return Check(
126
+ self.id,
127
+ False,
128
+ status,
129
+ fix="the stack needs attention in CloudFormation before a deploy can update it",
130
+ )
131
+
132
+ return Check(self.id, True, status)
133
+
134
+
135
+ class PermissionsCheck(Readiness):
136
+ """The deploy role simulated against what the template needs — for a connected account with the session tag, the boundary and the service the execution role goes to as context."""
137
+
138
+ id = "aws.permissions"
139
+
140
+ def __init__(self, access: Access, credentials: CredentialsCheck) -> None:
141
+ self.access = access
142
+ self.credentials = credentials
143
+
144
+ def run(self, spec: Spec) -> Check | None:
145
+ identity = self.credentials.identity
146
+ role = self.access.deploy_role or role_of(identity.get("Arn", ""))
147
+
148
+ if not role:
149
+ return None
150
+
151
+ stack = spec.stack
152
+ account = identity.get("Account", "")
153
+ region = spec.region or "us-east-1"
154
+ wanted: list[tuple[list[str], list[str]]] = [
155
+ (
156
+ ["cloudformation:CreateChangeSet", "cloudformation:DescribeStacks"],
157
+ [f"arn:aws:cloudformation:{region}:{account}:stack/{stack}/*"],
158
+ ),
159
+ (
160
+ ["lambda:CreateFunction", "lambda:UpdateFunctionCode"],
161
+ [f"arn:aws:lambda:{region}:{account}:function:{stack}-ApiFunction"],
162
+ ),
163
+ (
164
+ ["logs:CreateLogGroup"],
165
+ [
166
+ f"arn:aws:logs:{region}:{account}:log-group:/aws/lambda/{stack}-ApiFunction"
167
+ ],
168
+ ),
169
+ ]
170
+ layers = layers_of(spec, region)
171
+
172
+ if layers:
173
+ wanted.append((["lambda:GetLayerVersion"], layers))
174
+
175
+ context: list[str] = []
176
+
177
+ if spec.connected:
178
+ execution = f"arn:aws:iam::{account}:role{spec.connected.role_path}{stack}-ApiFunctionRole"
179
+ wanted.append((["iam:CreateRole", "iam:PassRole"], [execution]))
180
+ context = [
181
+ "--context-entries",
182
+ f"ContextKeyName=aws:PrincipalTag/{PREFIX_TAG},ContextKeyValues={spec.connected.prefix},ContextKeyType=string",
183
+ f"ContextKeyName=iam:PermissionsBoundary,ContextKeyValues={spec.connected.boundary},ContextKeyType=string",
184
+ "ContextKeyName=iam:PassedToService,ContextKeyValues=lambda.amazonaws.com,ContextKeyType=string",
185
+ ]
186
+
187
+ denied: list[str] = []
188
+
189
+ for actions, resources in wanted:
190
+ try:
191
+ data = shell.aws(
192
+ "iam",
193
+ "simulate-principal-policy",
194
+ "--policy-source-arn",
195
+ role,
196
+ "--action-names",
197
+ *actions,
198
+ "--resource-arns",
199
+ *resources,
200
+ *context,
201
+ env=self.access.env,
202
+ )
203
+ except DeployError as e:
204
+ return Check(
205
+ self.id,
206
+ True,
207
+ f"not simulated: {str(e)[:200]}",
208
+ severity="warning",
209
+ )
210
+
211
+ for row in data.get("EvaluationResults") or []:
212
+ if row.get("EvalDecision") != "allowed":
213
+ denied.append(
214
+ f"{row.get('EvalActionName')} on {row.get('EvalResourceName')}"
215
+ )
216
+
217
+ if denied:
218
+ return Check(
219
+ self.id,
220
+ False,
221
+ f"{role} may not: " + "; ".join(denied),
222
+ fix="widen the deploy role's policy (update the connect stack when it created the role)",
223
+ )
224
+
225
+ return Check(self.id, True, f"{role} may deploy {stack}")
226
+
227
+
228
+ class TemplateValidCheck(Readiness):
229
+ id = "template.valid"
230
+
231
+ def __init__(self, sam: Sam) -> None:
232
+ self.sam = sam
233
+
234
+ def run(self, spec: Spec) -> Check:
235
+ try:
236
+ self.sam.validate()
237
+ except DeployError as e:
238
+ return Check(self.id, False, str(e), fix="fix template.yaml")
239
+
240
+ return Check(self.id, True, "sam validate --lint passes")
241
+
242
+
243
+ def role_of(arn: str) -> str | None:
244
+ found = re.match(r"^arn:aws:sts::(\d+):assumed-role/([^/]+)/", arn)
245
+
246
+ return f"arn:aws:iam::{found.group(1)}:role/{found.group(2)}" if found else None
247
+
248
+
249
+ def layers_of(spec: Spec, region: str) -> list[str]:
250
+ text = spec.template.read_text(errors="replace").replace("${AWS::Region}", region)
251
+
252
+ return sorted(
253
+ set(re.findall(r"arn:aws:lambda:[\w-]+:\d{12}:layer:[\w-]+:\d+", text))
254
+ )