@pipeline-builder/pipeline-events 3.4.93 → 3.4.95
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.
- package/README.md +57 -9
- package/lib/index.js +580 -91
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -10,11 +10,24 @@ AWS Lambda handler for [Pipeline Builder](https://mwashburn160.github.io/pipelin
|
|
|
10
10
|
|
|
11
11
|
1. Receives CodePipeline (pipeline / stage / action) events delivered as an SQS batch sourced from EventBridge.
|
|
12
12
|
2. Classifies each record into a normalized event type (`PIPELINE`, `STAGE`, `ACTION`) and derives status, start/completion times, run duration, and — on failures — the `errorMessage` (from the action's `execution-result.external-execution-summary`).
|
|
13
|
-
3. Resolves each pipeline's
|
|
14
|
-
4.
|
|
13
|
+
3. Resolves each pipeline's tags via `codepipeline:ListTagsForResource`, cached per pipeline. The ARN and AWS account never leave AWS, so there is no masking/secret to manage. Untagged (unregistered) pipelines are skipped.
|
|
14
|
+
4. Resolves the DORA **commit range** in-account for source/deploy events (Phase 4) and attaches `commitTimestamp`/`commitCount`.
|
|
15
|
+
5. Posts the normalized batch (keyed by `pipelineId`) to the reporting service via `POST /api/reports/events`.
|
|
16
|
+
6. After a successful batch, emits a **delivery-health** signal and **self-heals the dead-letter queue** (Phase 3).
|
|
15
17
|
|
|
16
18
|
CodeBuild `Build State` events are skipped: a build project can be shared across pipelines, so there is no clean 1:1 mapping to a pipeline id.
|
|
17
19
|
|
|
20
|
+
### Tag standard (pipeline-core generates → this forwarder parses)
|
|
21
|
+
|
|
22
|
+
| Tag | Value | Purpose |
|
|
23
|
+
|---|---|---|
|
|
24
|
+
| `pb.pipeline-id` | `<platform pipelineId>` | The platform pipeline id to report against. Pipelines **without** this tag are unregistered and skipped. |
|
|
25
|
+
| `pb.deploys` | `<stage>:<env>` pairs joined by `+`, e.g. `Deploy-stg:staging+Deploy-prod:production` | Declares which stages are deploys and to which environment. CodePipeline-tag-safe (`:` `+` allowed; no JSON). |
|
|
26
|
+
|
|
27
|
+
The forwarder parses `pb.deploys` into a `stage → environment` map. For a `STAGE`/`ACTION` event it sets `environment` **only** when the event's stage matches a key in the map — that (and only that) marks the event as a deploy (`isDeploy` is derived server-side as `environment IS NOT NULL`). `PIPELINE` events have no stage and are never deploys.
|
|
28
|
+
|
|
29
|
+
> No backward compatibility: the old `PIPELINE_EVENT_ID` and `Environment` tags are gone. Already-deployed pipelines produce no DORA data until they re-synth with the new tags.
|
|
30
|
+
|
|
18
31
|
## Data forwarded to the platform
|
|
19
32
|
|
|
20
33
|
The Lambda forwards **only pipeline-execution telemetry** — enough to compute
|
|
@@ -25,8 +38,10 @@ account**; the reporting service only ever receives the normalized payload below
|
|
|
25
38
|
|
|
26
39
|
- **AWS account number** — explicitly stripped from every event (`delete detail.account`).
|
|
27
40
|
- **The pipeline ARN** (`arn:aws:codepipeline:<region>:<account>:<name>`) — built only as a
|
|
28
|
-
transient handle to look up the pipeline's `
|
|
41
|
+
transient handle to look up the pipeline's `pb.pipeline-id` tag, then discarded; it is
|
|
29
42
|
never stored or sent.
|
|
43
|
+
- **Source-revision URLs** (`revisionUrl`) — read only in-account to classify the source type
|
|
44
|
+
(CodeCommit / GitHub / Bitbucket) for commit-range resolution; not forwarded on their own.
|
|
30
45
|
- **AWS credentials / IAM** and any account-identifying identifiers.
|
|
31
46
|
|
|
32
47
|
The platform stores no AWS account id anywhere (schemas, JWTs, and APIs are account-id-free
|
|
@@ -38,7 +53,7 @@ by design), so there is nothing to mask.
|
|
|
38
53
|
|
|
39
54
|
| Field | Type | Notes |
|
|
40
55
|
|---|---|---|
|
|
41
|
-
| `pipelineId` | string | The **platform** pipeline id (from the `
|
|
56
|
+
| `pipelineId` | string | The **platform** pipeline id (from the `pb.pipeline-id` tag) — not the ARN |
|
|
42
57
|
| `eventSource` | `codepipeline` | |
|
|
43
58
|
| `eventType` | `PIPELINE` \| `STAGE` \| `ACTION` | |
|
|
44
59
|
| `status` | enum | The CodePipeline state (`SUCCEEDED`/`FAILED`/…) |
|
|
@@ -49,9 +64,28 @@ by design), so there is nothing to mask.
|
|
|
49
64
|
| `startedAt` / `completedAt` | ISO 8601? | Event timestamps |
|
|
50
65
|
| `durationMs` | number? | |
|
|
51
66
|
| `commitSha` / `commitRef` | string? | Source revision — DORA deploy attribution |
|
|
52
|
-
| `
|
|
67
|
+
| `commitTimestamp` | ISO 8601? | Oldest-unshipped commit time for the range since the last deploy — resolved **in-account** (Phase 4). Omitted when unresolvable (reporting falls back to `unknown`) |
|
|
68
|
+
| `commitCount` | number? | Number of commits (≥1) in that range. Omitted when unresolvable |
|
|
69
|
+
| `environment` | string? | Set only when the event's stage is listed in the pipeline's `pb.deploys` tag (⇒ this event is a deploy) |
|
|
53
70
|
| `detail` | object | The raw CodePipeline event detail **with `account` removed** — carries the execution result (log URL, error code) for drill-down |
|
|
54
71
|
|
|
72
|
+
### Commit-range resolution (Phase 4, in-account)
|
|
73
|
+
|
|
74
|
+
For a source/deploy event carrying a `commitSha`, the forwarder resolves the commit timestamp(s) for the range **since the last deploy of that pipeline**, entirely inside your AWS account, per source type detected from the revision URL:
|
|
75
|
+
|
|
76
|
+
- **CodeCommit** → AWS SDK `codecommit:GetCommit` (walks first-parents back to the previous shipped commit).
|
|
77
|
+
- **GitHub / CodeConnections-GitHub** → GitHub REST `compare` / `commits` API. Authenticated with the org's `pipeline-builder/{orgId}/github-token` secret when present (the secret name is derived from `PLATFORM_SECRET_NAME` by swapping the trailing `/platform` for `/github-token`; the value is the raw token string). Falls back to best-effort unauthenticated calls otherwise.
|
|
78
|
+
- **Bitbucket** → Bitbucket REST commit API (single-commit).
|
|
79
|
+
|
|
80
|
+
It emits `commitTimestamp` (oldest unshipped commit) and `commitCount`. Results are cached per commit; SCM rate limits (403/429) trigger a short cooldown; and **any** failure simply omits the fields — commit resolution never fails the batch. The last-shipped commit is tracked in-memory per warm container, so the first deploy after a cold start resolves as a single commit.
|
|
81
|
+
|
|
82
|
+
### Delivery health + self-healing redrive (Phase 3)
|
|
83
|
+
|
|
84
|
+
After a **successful** batch POST, the forwarder (throttled per warm container, best-effort, never failing the batch):
|
|
85
|
+
|
|
86
|
+
1. POSTs a delivery-health signal to `POST /api/reports/ingest-health` `{ forwarded, dropped, lastEventAt }` so the Reports UI can show flowing / stale / dropping. `forwarded` accumulates across batches between health posts; `dropped` is the current DLQ depth snapshot; `lastEventAt` is the newest event timestamp seen.
|
|
87
|
+
2. If the dead-letter queue is non-empty **and** no message-move task is already running, starts an SQS `StartMessageMoveTask` (DLQ → main queue) so retryable failures self-heal without a new AWS service. Guarded: success-gated, one-at-a-time (`ListMessageMoveTasks`), and throttled. Idempotent ingest (`idempotencyKey`) prevents double-counting on redelivery. The DLQ ARN defaults to `<main-queue-arn>-dlq` (derived from the SQS trigger ARN) and can be overridden with `EVENT_DLQ_ARN`.
|
|
88
|
+
|
|
55
89
|
## Key exports
|
|
56
90
|
|
|
57
91
|
| Export | Purpose |
|
|
@@ -60,11 +94,25 @@ by design), so there is nothing to mask.
|
|
|
60
94
|
|
|
61
95
|
## Runtime
|
|
62
96
|
|
|
63
|
-
- Lambda Node.js runtime, using the runtime-provided `@aws-sdk
|
|
97
|
+
- Lambda Node.js runtime, using the runtime-provided `@aws-sdk` clients (`client-codepipeline`, `client-secrets-manager`, and — loaded lazily only when needed — `client-codecommit` and `client-sqs`).
|
|
64
98
|
- Triggered by an SQS queue fed by an EventBridge rule matching the `aws.codepipeline` source; processes events in batches and POSTs them in a single request per invocation.
|
|
65
|
-
- Requires `PLATFORM_BASE_URL` (set by `setup-events`).
|
|
66
|
-
-
|
|
67
|
-
|
|
99
|
+
- Requires `PLATFORM_BASE_URL` (set by `setup-events`). Optional: `EVENT_DLQ_ARN` (self-healing redrive; defaults to `<main-queue-arn>-dlq`).
|
|
100
|
+
- Authenticates with either `PLATFORM_TOKEN` (a JWT set directly) or `PLATFORM_SECRET_NAME` (a Secrets Manager secret holding the JWT in `password`, created via `pipeline-manager infra store-token`); the resolved token is cached across invocations.
|
|
101
|
+
|
|
102
|
+
### IAM required by this handler
|
|
103
|
+
|
|
104
|
+
The execution role (granted on the events stack — `pipeline-manager/src/templates/events-stack.json`) must allow:
|
|
105
|
+
|
|
106
|
+
| Action | Resource | Used by |
|
|
107
|
+
|---|---|---|
|
|
108
|
+
| `codepipeline:ListTagsForResource` | the pipelines | Tag resolution. An `AccessDenied` here is logged as an error and **fails the batch**, so a missing grant is visible rather than silent. |
|
|
109
|
+
| `secretsmanager:GetSecretValue` | `pipeline-builder/*/platform-*` | Platform JWT (auth). |
|
|
110
|
+
| `secretsmanager:GetSecretValue` | `pipeline-builder/*/github-token-*` | GitHub/Bitbucket commit resolution (Phase 4). Best-effort: absent/denied ⇒ unauthenticated fallback. |
|
|
111
|
+
| `codecommit:GetCommit` | the CodeCommit source repositories | CodeCommit commit resolution (Phase 4). Best-effort. |
|
|
112
|
+
| `sqs:ReceiveMessage`, `sqs:DeleteMessage`, `sqs:GetQueueAttributes` | the main queue | SQS trigger + DLQ depth check. |
|
|
113
|
+
| `sqs:GetQueueAttributes`, `sqs:ListMessageMoveTasks`, `sqs:StartMessageMoveTask` | the **dead-letter queue** | Self-healing redrive (Phase 3). |
|
|
114
|
+
|
|
115
|
+
> The Phase 3/4 actions (`codecommit:GetCommit`, the `github-token` secret read, and the three DLQ `sqs:*` actions) are new grants required by this code — the events-stack IAM owner must add them. All Phase 3/4 paths are best-effort: a missing grant degrades gracefully (fields omitted / redrive skipped) and never fails the batch.
|
|
68
116
|
|
|
69
117
|
## Development
|
|
70
118
|
|