apx-aws-lambda 0.5.0__tar.gz → 1.0.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 (35) hide show
  1. apx_aws_lambda-1.0.0/PKG-INFO +169 -0
  2. apx_aws_lambda-1.0.0/README.md +151 -0
  3. apx_aws_lambda-1.0.0/apx_aws_lambda/cli.py +115 -0
  4. apx_aws_lambda-1.0.0/apx_aws_lambda/connect/template.yaml +216 -0
  5. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/lambda_.py +112 -64
  6. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/DEPLOY.md +1 -1
  7. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/template.yaml +4 -4
  8. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/plugin.py +7 -7
  9. apx_aws_lambda-1.0.0/apx_aws_lambda.egg-info/PKG-INFO +169 -0
  10. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda.egg-info/SOURCES.txt +1 -2
  11. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda.egg-info/requires.txt +0 -2
  12. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/pyproject.toml +4 -4
  13. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/tests/test_targets.py +145 -5
  14. apx_aws_lambda-0.5.0/PKG-INFO +0 -249
  15. apx_aws_lambda-0.5.0/README.md +0 -229
  16. apx_aws_lambda-0.5.0/apx_aws_lambda/cli.py +0 -139
  17. apx_aws_lambda-0.5.0/apx_aws_lambda/proxy.py +0 -161
  18. apx_aws_lambda-0.5.0/apx_aws_lambda.egg-info/PKG-INFO +0 -249
  19. apx_aws_lambda-0.5.0/tests/test_proxy.py +0 -362
  20. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/LICENSE +0 -0
  21. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/__init__.py +0 -0
  22. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/cookiecutter.json +0 -0
  23. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/hooks/post_gen_project.py +0 -0
  24. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/.github/workflows/deploy.yml +0 -0
  25. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/Makefile +0 -0
  26. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/policy.json +0 -0
  27. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/requirements/trust.json +0 -0
  28. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/cloud/aws/lambda/{{cookiecutter.project_slug}}/samconfig.toml +0 -0
  29. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/overlays/index.json +0 -0
  30. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/shell.py +0 -0
  31. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda/tools.py +0 -0
  32. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda.egg-info/dependency_links.txt +0 -0
  33. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda.egg-info/entry_points.txt +0 -0
  34. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/apx_aws_lambda.egg-info/top_level.txt +0 -0
  35. {apx_aws_lambda-0.5.0 → apx_aws_lambda-1.0.0}/setup.cfg +0 -0
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: apx-aws-lambda
3
+ Version: 1.0.0
4
+ Summary: AWS Lambda for Action Platform: the aws/lambda deploy target (SAM) with its overlay, and tools to read stacks and functions.
5
+ Author-email: Action Platform <cloud@actionplatform.io>
6
+ License-Expression: Apache-2.0
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: action-platform>=0.23.0
11
+ Requires-Dist: awscli>=1.34
12
+ Requires-Dist: aws-sam-cli>=1.120
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest>=8; extra == "dev"
15
+ Requires-Dist: ruff>=0.6; extra == "dev"
16
+ Requires-Dist: action-platform[mcp]; extra == "dev"
17
+ Dynamic: license-file
18
+
19
+ # apx-aws-lambda
20
+
21
+ AWS Lambda for [Action Platform](https://github.com/actionplatform/action-platform): the `aws/lambda` deploy target (SAM), its overlay, read-only tools and commands, and an IAM-only **connect stack** for your AWS account so that no AWS key ever lives on the platform, on a machine or in a repository — and nothing of ours runs in the account. `apx-` is the prefix every Action Platform extension carries.
22
+
23
+ ```bash
24
+ action-platform plugin install aws-lambda
25
+ action-platform cloud set aws/lambda # overlay files come from this plugin
26
+ action-platform deploy --dry-run # preflight: credentials, sam validate
27
+ action-platform deploy # sam build + sam deploy --config-env <stage>
28
+ action-platform diagnose
29
+ ```
30
+
31
+ ## Contents
32
+
33
+ - [What the plugin does](#what-the-plugin-does)
34
+ - [Credentials without keys](#credentials-without-keys)
35
+ - [A connected account (recommended)](#a-connected-account-recommended)
36
+ - [A role of your own (OIDC)](#a-role-of-your-own-oidc)
37
+ - [The AWS CLI's own credentials](#the-aws-clis-own-credentials)
38
+ - [Where the deploy runs](#where-the-deploy-runs)
39
+ - [Tools and commands](#tools-and-commands)
40
+ - [Requirements](#requirements)
41
+ - [Development](#development)
42
+
43
+ ## What the plugin does
44
+
45
+ | | |
46
+ |---|---|
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` |
50
+ | Rollback | CloudFormation `rollback-stack` — previous stack state |
51
+ | Diagnose | stack status and the HTTP API url |
52
+ | Destroy | `sam delete` of the stage's stack, the execution role SAM created with it |
53
+ | Tools | `aws_lambda_stacks`, `aws_lambda_functions` |
54
+ | Commands | `action-platform aws-lambda connect\|stacks\|functions` |
55
+
56
+ `[deploy]` in `platform.toml`:
57
+
58
+ ```toml
59
+ [deploy]
60
+ target = "aws/lambda"
61
+ region = "us-east-1" # optional; samconfig.toml / AWS_REGION otherwise
62
+ ```
63
+
64
+ Deploying itself goes through the core's `deploy` / `rollback` / `diagnose`, which drive the target.
65
+
66
+ ## Credentials without keys
67
+
68
+ The target looks for credentials in this order:
69
+
70
+ | Under `[deploy]` | How | Who decides what the app may do |
71
+ |---|---|---|
72
+ | `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 |
74
+ | neither | the AWS CLI's own chain: SSO, profile, instance role | whatever that identity may do |
75
+
76
+ ### A connected account (recommended)
77
+
78
+ 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
+
80
+ **1. Create the stack** — once per AWS account, with your own AWS credentials (not the root account). Either 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:
81
+
82
+ ```bash
83
+ action-platform aws-lambda connect https://platform.example.com acme # --region, --stack-name, --oidc-provider-arn
84
+ ```
85
+
86
+ **2. Tell the platform** — Plugins → AWS Lambda → Configure → **Deploy role ARN** = 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.
87
+
88
+ What the stack creates:
89
+
90
+ | Resource | Purpose |
91
+ |---|---|
92
+ | IAM OIDC provider | trusts `IssuerUrl` for audience `sts.amazonaws.com`; pass `OidcProviderArn` when the account already has one for the platform |
93
+ | `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 |
95
+
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>-dev|prod`, 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.
97
+
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.
99
+
100
+ ### A role of your own (OIDC)
101
+
102
+ Instead of the connect stack, register the platform as an identity provider once per account and write the trust policy yourself:
103
+
104
+ ```bash
105
+ aws iam create-open-id-connect-provider --url https://platform.example.com --client-id-list sts.amazonaws.com
106
+ ```
107
+
108
+ ```json
109
+ {
110
+ "Version": "2012-10-17",
111
+ "Statement": [{
112
+ "Effect": "Allow",
113
+ "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/platform.example.com" },
114
+ "Action": "sts:AssumeRoleWithWebIdentity",
115
+ "Condition": {
116
+ "StringEquals": { "platform.example.com:aud": "sts.amazonaws.com" },
117
+ "StringLike": { "platform.example.com:sub": "org:acme:project:shop:app:orders" }
118
+ }
119
+ }]
120
+ }
121
+ ```
122
+
123
+ `requirements/policy.json` from the overlay is a starting permission policy. Then:
124
+
125
+ ```toml
126
+ [deploy]
127
+ target = "aws/lambda"
128
+ role_arn = "arn:aws:iam::123456789012:role/shop-deploy"
129
+ ```
130
+
131
+ `sub` is `org:<org>:project:<project>:app:<app>` for a deploy the platform runs; `org:<org>` plus an `actor` claim for `action-platform deploy` from a logged-in machine (`StringLike` with `org:acme:*` covers both).
132
+
133
+ ### The AWS CLI's own credentials
134
+
135
+ With neither `role_arn` nor a connected account, `aws` and `sam` use what the machine has: `aws sso login`, a profile, an instance role. Still no key in a file when you use SSO — but nothing ties the identity to one app.
136
+
137
+ ## Where the deploy runs
138
+
139
+ Independent of how credentials are obtained:
140
+
141
+ | Where | Token for the role comes from |
142
+ |---|---|
143
+ | the platform's worker (a deploy job) | signed by the platform for that app: `sub = org:…:project:…:app:…`, the `action-platform:prefix` session tag |
144
+ | a logged-in machine (`action-platform deploy`) | `POST /api/v1/identity/token` with the user's login: `sub = org:<org>`, `actor`, `scopes` |
145
+ | the overlay's `.github/workflows/deploy.yml` | GitHub's own OIDC — optional, unrelated to the platform; delete the workflow when the platform deploys |
146
+
147
+ ## Tools and commands
148
+
149
+ | | |
150
+ |---|---|
151
+ | `aws_lambda_stacks` / `action-platform aws-lambda stacks [prefix]` | CloudFormation stacks |
152
+ | `aws_lambda_functions` / `action-platform aws-lambda functions [prefix]` | Lambda functions |
153
+ | `action-platform aws-lambda connect <platform url> <organization>` | the connect stack, in the account the CLI is logged in to |
154
+
155
+ ## Requirements
156
+
157
+ - `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
+ - `AWS_REGION` or `region` under `[deploy]`.
159
+ - Network: `*.amazonaws.com`.
160
+ - Connecting the account: credentials for it, once — the console, or `aws` for `action-platform aws-lambda connect`.
161
+
162
+ ## Development
163
+
164
+ ```bash
165
+ pip install -e ".[dev]"
166
+ pytest
167
+ ```
168
+
169
+ The tests fake `aws` and `sam`; nothing reaches AWS.
@@ -0,0 +1,151 @@
1
+ # apx-aws-lambda
2
+
3
+ AWS Lambda for [Action Platform](https://github.com/actionplatform/action-platform): the `aws/lambda` deploy target (SAM), its overlay, read-only tools and commands, and an IAM-only **connect stack** for your AWS account so that no AWS key ever lives on the platform, on a machine or in a repository — and nothing of ours runs in the account. `apx-` is the prefix every Action Platform extension carries.
4
+
5
+ ```bash
6
+ action-platform plugin install aws-lambda
7
+ action-platform cloud set aws/lambda # overlay files come from this plugin
8
+ action-platform deploy --dry-run # preflight: credentials, sam validate
9
+ action-platform deploy # sam build + sam deploy --config-env <stage>
10
+ action-platform diagnose
11
+ ```
12
+
13
+ ## Contents
14
+
15
+ - [What the plugin does](#what-the-plugin-does)
16
+ - [Credentials without keys](#credentials-without-keys)
17
+ - [A connected account (recommended)](#a-connected-account-recommended)
18
+ - [A role of your own (OIDC)](#a-role-of-your-own-oidc)
19
+ - [The AWS CLI's own credentials](#the-aws-clis-own-credentials)
20
+ - [Where the deploy runs](#where-the-deploy-runs)
21
+ - [Tools and commands](#tools-and-commands)
22
+ - [Requirements](#requirements)
23
+ - [Development](#development)
24
+
25
+ ## What the plugin does
26
+
27
+ | | |
28
+ |---|---|
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` |
32
+ | Rollback | CloudFormation `rollback-stack` — previous stack state |
33
+ | Diagnose | stack status and the HTTP API url |
34
+ | Destroy | `sam delete` of the stage's stack, the execution role SAM created with it |
35
+ | Tools | `aws_lambda_stacks`, `aws_lambda_functions` |
36
+ | Commands | `action-platform aws-lambda connect\|stacks\|functions` |
37
+
38
+ `[deploy]` in `platform.toml`:
39
+
40
+ ```toml
41
+ [deploy]
42
+ target = "aws/lambda"
43
+ region = "us-east-1" # optional; samconfig.toml / AWS_REGION otherwise
44
+ ```
45
+
46
+ Deploying itself goes through the core's `deploy` / `rollback` / `diagnose`, which drive the target.
47
+
48
+ ## Credentials without keys
49
+
50
+ The target looks for credentials in this order:
51
+
52
+ | Under `[deploy]` | How | Who decides what the app may do |
53
+ |---|---|---|
54
+ | `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 |
56
+ | neither | the AWS CLI's own chain: SSO, profile, instance role | whatever that identity may do |
57
+
58
+ ### A connected account (recommended)
59
+
60
+ 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
+
62
+ **1. Create the stack** — once per AWS account, with your own AWS credentials (not the root account). Either 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:
63
+
64
+ ```bash
65
+ action-platform aws-lambda connect https://platform.example.com acme # --region, --stack-name, --oidc-provider-arn
66
+ ```
67
+
68
+ **2. Tell the platform** — Plugins → AWS Lambda → Configure → **Deploy role ARN** = 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.
69
+
70
+ What the stack creates:
71
+
72
+ | Resource | Purpose |
73
+ |---|---|
74
+ | IAM OIDC provider | trusts `IssuerUrl` for audience `sts.amazonaws.com`; pass `OidcProviderArn` when the account already has one for the platform |
75
+ | `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 |
77
+
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>-dev|prod`, 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.
79
+
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.
81
+
82
+ ### A role of your own (OIDC)
83
+
84
+ Instead of the connect stack, register the platform as an identity provider once per account and write the trust policy yourself:
85
+
86
+ ```bash
87
+ aws iam create-open-id-connect-provider --url https://platform.example.com --client-id-list sts.amazonaws.com
88
+ ```
89
+
90
+ ```json
91
+ {
92
+ "Version": "2012-10-17",
93
+ "Statement": [{
94
+ "Effect": "Allow",
95
+ "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/platform.example.com" },
96
+ "Action": "sts:AssumeRoleWithWebIdentity",
97
+ "Condition": {
98
+ "StringEquals": { "platform.example.com:aud": "sts.amazonaws.com" },
99
+ "StringLike": { "platform.example.com:sub": "org:acme:project:shop:app:orders" }
100
+ }
101
+ }]
102
+ }
103
+ ```
104
+
105
+ `requirements/policy.json` from the overlay is a starting permission policy. Then:
106
+
107
+ ```toml
108
+ [deploy]
109
+ target = "aws/lambda"
110
+ role_arn = "arn:aws:iam::123456789012:role/shop-deploy"
111
+ ```
112
+
113
+ `sub` is `org:<org>:project:<project>:app:<app>` for a deploy the platform runs; `org:<org>` plus an `actor` claim for `action-platform deploy` from a logged-in machine (`StringLike` with `org:acme:*` covers both).
114
+
115
+ ### The AWS CLI's own credentials
116
+
117
+ With neither `role_arn` nor a connected account, `aws` and `sam` use what the machine has: `aws sso login`, a profile, an instance role. Still no key in a file when you use SSO — but nothing ties the identity to one app.
118
+
119
+ ## Where the deploy runs
120
+
121
+ Independent of how credentials are obtained:
122
+
123
+ | Where | Token for the role comes from |
124
+ |---|---|
125
+ | the platform's worker (a deploy job) | signed by the platform for that app: `sub = org:…:project:…:app:…`, the `action-platform:prefix` session tag |
126
+ | a logged-in machine (`action-platform deploy`) | `POST /api/v1/identity/token` with the user's login: `sub = org:<org>`, `actor`, `scopes` |
127
+ | the overlay's `.github/workflows/deploy.yml` | GitHub's own OIDC — optional, unrelated to the platform; delete the workflow when the platform deploys |
128
+
129
+ ## Tools and commands
130
+
131
+ | | |
132
+ |---|---|
133
+ | `aws_lambda_stacks` / `action-platform aws-lambda stacks [prefix]` | CloudFormation stacks |
134
+ | `aws_lambda_functions` / `action-platform aws-lambda functions [prefix]` | Lambda functions |
135
+ | `action-platform aws-lambda connect <platform url> <organization>` | the connect stack, in the account the CLI is logged in to |
136
+
137
+ ## Requirements
138
+
139
+ - `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
+ - `AWS_REGION` or `region` under `[deploy]`.
141
+ - Network: `*.amazonaws.com`.
142
+ - Connecting the account: credentials for it, once — the console, or `aws` for `action-platform aws-lambda connect`.
143
+
144
+ ## Development
145
+
146
+ ```bash
147
+ pip install -e ".[dev]"
148
+ pytest
149
+ ```
150
+
151
+ The tests fake `aws` and `sam`; nothing reaches AWS.
@@ -0,0 +1,115 @@
1
+ """`action-platform aws-lambda …`: the same reads as the tools, from the terminal."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+
7
+ import typer
8
+ from rich.console import Console
9
+ from rich.table import Table
10
+
11
+ from apx_aws_lambda import shell
12
+
13
+ app = typer.Typer(
14
+ help="AWS Lambda: connect an account, stacks, functions.",
15
+ no_args_is_help=True,
16
+ )
17
+ console = Console()
18
+ CONNECT_TEMPLATE = Path(__file__).parent / "connect" / "template.yaml"
19
+
20
+
21
+ def _table(columns: list[str], rows: list[list[str]]) -> None:
22
+ table = Table(box=None, pad_edge=False)
23
+
24
+ for c in columns:
25
+ table.add_column(c)
26
+
27
+ for r in rows:
28
+ table.add_row(*r)
29
+
30
+ console.print(table)
31
+
32
+
33
+ @app.command("connect")
34
+ def connect(
35
+ issuer: str = typer.Argument(..., help="The platform's public url"),
36
+ organization: str = typer.Argument(..., help="The organization slug"),
37
+ region: str = typer.Option("us-east-1", help="Region the stack lives in"),
38
+ stack_name: str = typer.Option("action-platform-connect"),
39
+ oidc_provider_arn: str = typer.Option(
40
+ "", help="An IAM OIDC provider for the platform that already exists"
41
+ ),
42
+ ) -> None:
43
+ """Connect the AWS account the CLI is logged in to: the IAM-only stack, once."""
44
+ shell.run(
45
+ [
46
+ *shell.require("aws", "https://aws.amazon.com/cli/"),
47
+ "cloudformation",
48
+ "deploy",
49
+ "--template-file",
50
+ str(CONNECT_TEMPLATE),
51
+ "--stack-name",
52
+ stack_name,
53
+ "--region",
54
+ region,
55
+ "--capabilities",
56
+ "CAPABILITY_NAMED_IAM",
57
+ "--no-fail-on-empty-changeset",
58
+ "--parameter-overrides",
59
+ f"IssuerUrl={issuer.rstrip('/')}",
60
+ f"Organization={organization}",
61
+ f"OidcProviderArn={oidc_provider_arn}",
62
+ ]
63
+ )
64
+ data = shell.aws(
65
+ "cloudformation", "describe-stacks", "--stack-name", stack_name, region=region
66
+ )
67
+ outputs = {
68
+ o["OutputKey"]: o["OutputValue"]
69
+ for o in (data.get("Stacks") or [{}])[0].get("Outputs") or []
70
+ }
71
+ console.print(f"[bold]DeployRoleArn[/bold] {outputs.get('DeployRoleArn', '-')}")
72
+ console.print(
73
+ "On the platform: Plugins → AWS Lambda → Configure → Deploy role ARN."
74
+ )
75
+
76
+
77
+ @app.command("stacks")
78
+ def stacks(
79
+ prefix: str = typer.Argument(""), region: str | None = typer.Option(None)
80
+ ) -> None:
81
+ """CloudFormation stacks."""
82
+ data = shell.aws(
83
+ "cloudformation",
84
+ "list-stacks",
85
+ "--stack-status-filter",
86
+ "CREATE_COMPLETE",
87
+ "UPDATE_COMPLETE",
88
+ "ROLLBACK_COMPLETE",
89
+ "UPDATE_ROLLBACK_COMPLETE",
90
+ region=region,
91
+ )
92
+ _table(
93
+ ["stack", "status", "updated"],
94
+ [
95
+ [s["StackName"], s["StackStatus"], s.get("LastUpdatedTime", "")]
96
+ for s in data.get("StackSummaries", [])
97
+ if s["StackName"].startswith(prefix)
98
+ ],
99
+ )
100
+
101
+
102
+ @app.command("functions")
103
+ def functions(
104
+ prefix: str = typer.Argument(""), region: str | None = typer.Option(None)
105
+ ) -> None:
106
+ """Lambda functions."""
107
+ data = shell.aws("lambda", "list-functions", region=region)
108
+ _table(
109
+ ["function", "runtime", "memory"],
110
+ [
111
+ [f["FunctionName"], f.get("Runtime", ""), str(f.get("MemorySize", ""))]
112
+ for f in data.get("Functions", [])
113
+ if f["FunctionName"].startswith(prefix)
114
+ ],
115
+ )
@@ -0,0 +1,216 @@
1
+ AWSTemplateFormatVersion: "2010-09-09"
2
+ Description: Action Platform - connects this AWS account. The platform's OIDC tokens assume one deploy role; the app's session tag scopes every stack, function, log group and execution role to that app. IAM only, no code, no AWS key.
3
+
4
+ Parameters:
5
+ IssuerUrl:
6
+ Type: String
7
+ AllowedPattern: "^https://[^/].*[^/]$"
8
+ Description: The platform's public url, the OIDC issuer (https://platform.example.com), no trailing slash
9
+ Organization:
10
+ Type: String
11
+ AllowedPattern: "^[a-z0-9][a-z0-9-]{0,62}$"
12
+ Description: The organization slug on the platform
13
+ OidcProviderArn:
14
+ Type: String
15
+ Default: ""
16
+ Description: An IAM OIDC provider for IssuerUrl that already exists in this account. Empty creates one.
17
+
18
+ Conditions:
19
+ CreateProvider: !Equals [!Ref OidcProviderArn, ""]
20
+
21
+ Resources:
22
+ Provider:
23
+ Type: AWS::IAM::OIDCProvider
24
+ Condition: CreateProvider
25
+ Properties:
26
+ Url: !Ref IssuerUrl
27
+ ClientIdList:
28
+ - sts.amazonaws.com
29
+
30
+ Boundary:
31
+ Type: AWS::IAM::ManagedPolicy
32
+ Properties:
33
+ ManagedPolicyName: ActionPlatformAppBoundary
34
+ Path: /action-platform/
35
+ Description: Caps every execution role an app's stack creates, by the role's action-platform:prefix tag; edit to widen or narrow what apps may do.
36
+ PolicyDocument:
37
+ Version: "2012-10-17"
38
+ Statement:
39
+ - Sid: Logs
40
+ Effect: Allow
41
+ Action:
42
+ - logs:CreateLogGroup
43
+ - logs:CreateLogStream
44
+ - logs:PutLogEvents
45
+ Resource: !Sub "arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/${!aws:PrincipalTag/action-platform:prefix}*"
46
+ - Sid: Tracing
47
+ Effect: Allow
48
+ Action:
49
+ - xray:PutTraceSegments
50
+ - xray:PutTelemetryRecords
51
+ Resource: "*"
52
+ - Sid: OwnResources
53
+ Effect: Allow
54
+ Action:
55
+ - s3:*
56
+ - dynamodb:*
57
+ - sqs:*
58
+ - sns:*
59
+ - lambda:InvokeFunction
60
+ Resource:
61
+ - "arn:aws:s3:::${aws:PrincipalTag/action-platform:prefix}-*"
62
+ - "arn:aws:s3:::${aws:PrincipalTag/action-platform:prefix}-*/*"
63
+ - !Sub "arn:aws:dynamodb:*:${AWS::AccountId}:table/${!aws:PrincipalTag/action-platform:prefix}-*"
64
+ - !Sub "arn:aws:sqs:*:${AWS::AccountId}:${!aws:PrincipalTag/action-platform:prefix}-*"
65
+ - !Sub "arn:aws:sns:*:${AWS::AccountId}:${!aws:PrincipalTag/action-platform:prefix}-*"
66
+ - !Sub "arn:aws:lambda:*:${AWS::AccountId}:function:${!aws:PrincipalTag/action-platform:prefix}*"
67
+ - Sid: OwnSecrets
68
+ Effect: Allow
69
+ Action:
70
+ - secretsmanager:GetSecretValue
71
+ - ssm:GetParameter
72
+ - ssm:GetParameters
73
+ - ssm:GetParametersByPath
74
+ Resource:
75
+ - !Sub "arn:aws:secretsmanager:*:${AWS::AccountId}:secret:${!aws:PrincipalTag/action-platform:prefix}/*"
76
+ - !Sub "arn:aws:ssm:*:${AWS::AccountId}:parameter/${!aws:PrincipalTag/action-platform:prefix}/*"
77
+
78
+ DeployRole:
79
+ Type: AWS::IAM::Role
80
+ Properties:
81
+ RoleName: ActionPlatformDeploy
82
+ Path: /action-platform/
83
+ Description: Assumed with the platform's OIDC token; scoped to one app by the session tag action-platform:prefix.
84
+ MaxSessionDuration: 3600
85
+ AssumeRolePolicyDocument: !Sub
86
+ - |
87
+ {
88
+ "Version": "2012-10-17",
89
+ "Statement": [
90
+ {
91
+ "Effect": "Allow",
92
+ "Principal": {"Federated": "${ProviderArn}"},
93
+ "Action": "sts:AssumeRoleWithWebIdentity",
94
+ "Condition": {
95
+ "StringEquals": {"${Host}:aud": "sts.amazonaws.com"},
96
+ "StringLike": {"${Host}:sub": "org:${Organization}:*"}
97
+ }
98
+ },
99
+ {
100
+ "Effect": "Allow",
101
+ "Principal": {"Federated": "${ProviderArn}"},
102
+ "Action": "sts:TagSession",
103
+ "Condition": {
104
+ "StringEquals": {"${Host}:aud": "sts.amazonaws.com"},
105
+ "StringLike": {
106
+ "${Host}:sub": "org:${Organization}:*",
107
+ "aws:RequestTag/action-platform:prefix": "ap-${Organization}-*"
108
+ },
109
+ "ForAllValues:StringEquals": {"aws:TagKeys": ["action-platform:prefix"]}
110
+ }
111
+ }
112
+ ]
113
+ }
114
+ - Host: !Select [1, !Split ["https://", !Ref IssuerUrl]]
115
+ ProviderArn: !If [CreateProvider, !Ref Provider, !Ref OidcProviderArn]
116
+ Tags:
117
+ - Key: action-platform:managed
118
+ Value: "true"
119
+ Policies:
120
+ - PolicyName: deploy
121
+ PolicyDocument:
122
+ Version: "2012-10-17"
123
+ Statement:
124
+ - Sid: OwnStacks
125
+ Effect: Allow
126
+ Action: cloudformation:*
127
+ Resource: !Sub "arn:aws:cloudformation:*:${AWS::AccountId}:stack/${!aws:PrincipalTag/action-platform:prefix}*"
128
+ - Sid: StackReads
129
+ Effect: Allow
130
+ Action:
131
+ - cloudformation:ListStacks
132
+ - cloudformation:ValidateTemplate
133
+ - cloudformation:GetTemplateSummary
134
+ - cloudformation:CreateChangeSet
135
+ Resource: "*"
136
+ - Sid: OwnFunctions
137
+ Effect: Allow
138
+ Action: lambda:*
139
+ Resource:
140
+ - !Sub "arn:aws:lambda:*:${AWS::AccountId}:function:${!aws:PrincipalTag/action-platform:prefix}*"
141
+ - !Sub "arn:aws:lambda:*:${AWS::AccountId}:layer:${!aws:PrincipalTag/action-platform:prefix}*"
142
+ - Sid: PublicLayers
143
+ Effect: Allow
144
+ Action: lambda:GetLayerVersion
145
+ Resource: arn:aws:lambda:*:753240598075:layer:LambdaAdapterLayer*:*
146
+ - Sid: ApiGateway
147
+ Effect: Allow
148
+ Action: apigateway:*
149
+ Resource: arn:aws:apigateway:*::/*
150
+ - Sid: OwnLogs
151
+ Effect: Allow
152
+ Action: logs:*
153
+ Resource: !Sub "arn:aws:logs:*:${AWS::AccountId}:log-group:/aws/lambda/${!aws:PrincipalTag/action-platform:prefix}*"
154
+ - Sid: CreateExecutionRoleWithinTheBoundary
155
+ Effect: Allow
156
+ Action:
157
+ - iam:CreateRole
158
+ - iam:PutRolePermissionsBoundary
159
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${!aws:PrincipalTag/action-platform:prefix}-*"
160
+ Condition:
161
+ StringEquals:
162
+ iam:PermissionsBoundary: !Ref Boundary
163
+ StringEqualsIfExists:
164
+ aws:RequestTag/action-platform:prefix: "${aws:PrincipalTag/action-platform:prefix}"
165
+ - Sid: TagExecutionRoleWithItsOwnPrefix
166
+ Effect: Allow
167
+ Action: iam:TagRole
168
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${!aws:PrincipalTag/action-platform:prefix}-*"
169
+ Condition:
170
+ StringEqualsIfExists:
171
+ aws:RequestTag/action-platform:prefix: "${aws:PrincipalTag/action-platform:prefix}"
172
+ - Sid: ManageExecutionRole
173
+ Effect: Allow
174
+ Action:
175
+ - iam:GetRole
176
+ - iam:DeleteRole
177
+ - iam:UntagRole
178
+ - iam:ListRoleTags
179
+ - iam:AttachRolePolicy
180
+ - iam:DetachRolePolicy
181
+ - iam:PutRolePolicy
182
+ - iam:GetRolePolicy
183
+ - iam:DeleteRolePolicy
184
+ - iam:ListRolePolicies
185
+ - iam:ListAttachedRolePolicies
186
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${!aws:PrincipalTag/action-platform:prefix}-*"
187
+ - Sid: PassExecutionRoleToLambda
188
+ Effect: Allow
189
+ Action: iam:PassRole
190
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/${!aws:PrincipalTag/action-platform:prefix}-*"
191
+ Condition:
192
+ StringEquals:
193
+ iam:PassedToService: lambda.amazonaws.com
194
+ - Sid: ReadinessSimulatesItself
195
+ Effect: Allow
196
+ Action:
197
+ - iam:GetRole
198
+ - iam:SimulatePrincipalPolicy
199
+ Resource: !Sub "arn:aws:iam::${AWS::AccountId}:role/action-platform/ActionPlatformDeploy"
200
+ - Sid: SamBucketStack
201
+ Effect: Allow
202
+ Action: cloudformation:*
203
+ Resource: !Sub "arn:aws:cloudformation:*:${AWS::AccountId}:stack/aws-sam-cli-managed-default*"
204
+ - Sid: SamBucket
205
+ Effect: Allow
206
+ Action: s3:*
207
+ Resource:
208
+ - arn:aws:s3:::aws-sam-cli-managed-default-*
209
+ - arn:aws:s3:::aws-sam-cli-managed-default-*/*
210
+
211
+ Outputs:
212
+ DeployRoleArn:
213
+ Description: Paste on the platform - Plugins, AWS Lambda, Configure, Deploy role ARN
214
+ Value: !GetAtt DeployRole.Arn
215
+ BoundaryArn:
216
+ Value: !Ref Boundary