@aligent/aws-wrappers 0.5.5 → 0.5.7
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 +32 -2
- package/cjs/index.cjs +171 -139
- package/cjs/package.json +1 -1
- package/cjs/src/dynamodb/dynamodb.d.ts.map +1 -1
- package/cjs/src/index.d.ts +2 -0
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/s3/s3.d.ts.map +1 -1
- package/cjs/src/scheduler/scheduler.d.ts.map +1 -1
- package/cjs/src/sfn/sfn.d.ts.map +1 -1
- package/cjs/src/sns/sns.d.ts +7 -0
- package/cjs/src/sns/sns.d.ts.map +1 -1
- package/cjs/src/sqs/sqs.d.ts +13 -0
- package/cjs/src/sqs/sqs.d.ts.map +1 -1
- package/cjs/src/ssm/ssm.d.ts.map +1 -1
- package/cjs/src/util/batch-operation-error.d.ts +50 -0
- package/cjs/src/util/batch-operation-error.d.ts.map +1 -0
- package/cjs/src/util/chunk.d.ts +6 -0
- package/cjs/src/util/chunk.d.ts.map +1 -0
- package/cjs/src/util/redact.d.ts +17 -18
- package/cjs/src/util/redact.d.ts.map +1 -1
- package/docs/index/classes/APIGatewayService.md +6 -6
- package/docs/index/classes/APIGatewayV2Service.md +5 -5
- package/docs/index/classes/BatchOperationError.md +261 -0
- package/docs/index/classes/DynamoDBService.md +12 -12
- package/docs/index/classes/S3Service.md +15 -15
- package/docs/index/classes/SNSService.md +10 -4
- package/docs/index/classes/SQSService.md +20 -7
- package/docs/index/classes/SSMService.md +7 -7
- package/docs/index/classes/SchedulerService.md +11 -11
- package/docs/index/classes/SecretsManagerService.md +8 -8
- package/docs/index/classes/StepFunctionsService.md +6 -6
- package/docs/index/interfaces/BatchFailedEntry.md +43 -0
- package/docs/index/modules.md +5 -0
- package/docs/testing/testing/functions/createMockService.md +1 -1
- package/esm/index.mjs +171 -140
- package/esm/package.json +1 -1
- package/esm/src/dynamodb/dynamodb.d.ts.map +1 -1
- package/esm/src/index.d.ts +2 -0
- package/esm/src/index.d.ts.map +1 -1
- package/esm/src/s3/s3.d.ts.map +1 -1
- package/esm/src/scheduler/scheduler.d.ts.map +1 -1
- package/esm/src/sfn/sfn.d.ts.map +1 -1
- package/esm/src/sns/sns.d.ts +7 -0
- package/esm/src/sns/sns.d.ts.map +1 -1
- package/esm/src/sqs/sqs.d.ts +13 -0
- package/esm/src/sqs/sqs.d.ts.map +1 -1
- package/esm/src/ssm/ssm.d.ts.map +1 -1
- package/esm/src/util/batch-operation-error.d.ts +50 -0
- package/esm/src/util/batch-operation-error.d.ts.map +1 -0
- package/esm/src/util/chunk.d.ts +6 -0
- package/esm/src/util/chunk.d.ts.map +1 -0
- package/esm/src/util/redact.d.ts +17 -18
- package/esm/src/util/redact.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,6 +25,34 @@ new XService({ logger?, client? })
|
|
|
25
25
|
|
|
26
26
|
Every wrapper emits one `logger.info` line per SDK call with a per-method safe-field allowlist (omitting payloads, secret material, and PII recipient identifiers). Set `POWERTOOLS_LOG_LEVEL` to either `DEBUG` or `TRACE` to unlock the full SDK input in those log lines — useful for local development and incident triage. Both levels unlock because Powertools orders `TRACE` as more verbose than `DEBUG`; every level from `INFO` upwards redacts. See `packages/aws-wrappers/CLAUDE.md` for the per-method allowlists currently in force.
|
|
27
27
|
|
|
28
|
+
### Batch semantics
|
|
29
|
+
|
|
30
|
+
Batch methods split your entries into chunks of the size the AWS API allows and send one request per chunk. AWS reports rejected entries inside an otherwise successful response, so a resolved request does not mean every entry was accepted. Currently covered: `SQSService.sendMessageBatch`, `SQSService.deleteMessageBatch` and `SNSService.publishBatch`.
|
|
31
|
+
|
|
32
|
+
Every chunk is sent first. If any entry was rejected, the method then throws a single `BatchOperationError`. A call where nothing was rejected returns the per-chunk SDK outputs exactly as before.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import { BatchOperationError } from '@aligent/aws-wrappers';
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
await sqs.sendMessageBatch({ QueueUrl, Entries: entries });
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (error instanceof BatchOperationError) {
|
|
41
|
+
// error.results — the raw SDK output of every chunk, including what succeeded
|
|
42
|
+
// error.failed — [{ id, code, message }] for every rejected entry
|
|
43
|
+
const failedIds = new Set(error.failed.map(entry => entry.id));
|
|
44
|
+
await retry(entries.filter(entry => failedIds.has(entry.Id)));
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- `failed` carries only the entry identifier, error code and message — never message bodies, attributes or any other payload.
|
|
52
|
+
- The error has a stable `name` of `'BatchOperationError'`. If both the CJS and ESM builds of this package can be loaded in one process, check `error.name` instead of `instanceof`.
|
|
53
|
+
- A warning is logged with the failure count and error codes, and no payload, at every log level.
|
|
54
|
+
- Request-level SDK exceptions (throttling, access denied, network errors) are **not** wrapped. They propagate unchanged and immediately, so earlier chunks may already have been sent and the caller cannot tell which. Treat those as "outcome unknown" and make the operation safe to repeat.
|
|
55
|
+
|
|
28
56
|
### X-Ray outside Lambda
|
|
29
57
|
|
|
30
58
|
X-Ray's middleware throws by default when no active segment exists, which is the case for CLI scripts and local development. Set the environment variable to silence the noise:
|
|
@@ -318,7 +346,8 @@ for (const message of messages) {
|
|
|
318
346
|
}
|
|
319
347
|
}
|
|
320
348
|
|
|
321
|
-
// Batch methods auto-chunk Entries to the SQS-enforced 10-entry limit
|
|
349
|
+
// Batch methods auto-chunk Entries to the SQS-enforced 10-entry limit and throw
|
|
350
|
+
// a BatchOperationError if SQS rejects any entry — see "Batch semantics".
|
|
322
351
|
await sqs.sendMessageBatch({ QueueUrl, Entries: bigEntryList });
|
|
323
352
|
await sqs.deleteMessageBatch({ QueueUrl, Entries: receiptEntries });
|
|
324
353
|
```
|
|
@@ -343,7 +372,8 @@ const sns = new SNSService();
|
|
|
343
372
|
|
|
344
373
|
await sns.publish({ TopicArn, Message: 'hello' });
|
|
345
374
|
|
|
346
|
-
// publishBatch auto-chunks PublishBatchRequestEntries to the SNS-enforced 10-entry limit
|
|
375
|
+
// publishBatch auto-chunks PublishBatchRequestEntries to the SNS-enforced 10-entry limit
|
|
376
|
+
// and throws a BatchOperationError if SNS rejects any entry — see "Batch semantics".
|
|
347
377
|
await sns.publishBatch({ TopicArn, PublishBatchRequestEntries: bigEntryList });
|
|
348
378
|
|
|
349
379
|
// Opt-in truncation — same shape as SQS. Truncates Message (256 KB byte-safe)
|
package/cjs/index.cjs
CHANGED
|
@@ -144,38 +144,22 @@ class APIGatewayService {
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* Whether the logger is verbose enough that full SDK inputs
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* **This is the only place in the package that reads the log level.** Never
|
|
151
|
-
* compare `logger.getLevelName()` yourself: Powertools orders `TRACE` as *more*
|
|
152
|
-
* verbose than `DEBUG` (thresholds 6 and 8), so the obvious
|
|
153
|
-
* `getLevelName() === 'DEBUG'` check silently redacts at the most verbose level
|
|
154
|
-
* available. Route every disclosure decision through this predicate instead.
|
|
147
|
+
* Whether the logger is verbose enough that full SDK inputs may be written to
|
|
148
|
+
* the log. The unlock rule is documented on {@link redactInput}.
|
|
155
149
|
*/
|
|
156
150
|
function shouldLogFullInput(logger$1) {
|
|
157
151
|
return logger.LogLevelThreshold[logger$1.getLevelName()] <= logger.LogLevelThreshold.DEBUG;
|
|
158
152
|
}
|
|
159
|
-
|
|
160
|
-
* Return a log-safe projection of `input` based on the logger's configured level.
|
|
161
|
-
*
|
|
162
|
-
* At the verbose levels — see {@link shouldLogFullInput} — the full input is
|
|
163
|
-
* returned unchanged: operators who asked for that verbosity have explicitly
|
|
164
|
-
* opted into seeing everything, including payloads, secret material and PII.
|
|
165
|
-
*
|
|
166
|
-
* At any other level, only the fields listed in `safeFields` are included.
|
|
167
|
-
* Missing fields are silently skipped — the result type narrows to
|
|
168
|
-
* `Pick<T, K>` accordingly.
|
|
169
|
-
*
|
|
170
|
-
* Used across the package so that the "what's safe to log at INFO" decision
|
|
171
|
-
* lives in one place. See `packages/aws-wrappers/CLAUDE.md` ("Logging") for
|
|
172
|
-
* the design rationale and conventions on building the safe-field lists.
|
|
173
|
-
*/
|
|
174
|
-
function filterFieldsForLogLevel(logger, input, safeFields) {
|
|
153
|
+
function redactInput(logger, input, project) {
|
|
175
154
|
if (shouldLogFullInput(logger))
|
|
176
155
|
return input;
|
|
156
|
+
if (typeof project === 'function')
|
|
157
|
+
return project(input);
|
|
158
|
+
return pickKeys(input, project);
|
|
159
|
+
}
|
|
160
|
+
function pickKeys(input, keys) {
|
|
177
161
|
const out = {};
|
|
178
|
-
for (const key of
|
|
162
|
+
for (const key of keys) {
|
|
179
163
|
if (key in input)
|
|
180
164
|
out[key] = input[key];
|
|
181
165
|
}
|
|
@@ -186,6 +170,14 @@ const BATCH_WRITE_MAX_ATTEMPTS = 5;
|
|
|
186
170
|
const BATCH_WRITE_BASE_DELAY_MS = 200;
|
|
187
171
|
const BATCH_GET_MAX_ATTEMPTS = 5;
|
|
188
172
|
const BATCH_GET_BASE_DELAY_MS = 200;
|
|
173
|
+
/**
|
|
174
|
+
* Safe log shape for the batch methods. `RequestItems` is keyed by table name
|
|
175
|
+
* with the payload (`Keys`, `Item`) nested inside each value, so it can't be
|
|
176
|
+
* an allowlisted field and is reduced to the table names instead.
|
|
177
|
+
*/
|
|
178
|
+
function summariseTables(input) {
|
|
179
|
+
return { tables: Object.keys(input.RequestItems ?? {}) };
|
|
180
|
+
}
|
|
189
181
|
/**
|
|
190
182
|
* Fields safe to log at INFO. Omits `Key` (may carry customer IDs / tenant IDs).
|
|
191
183
|
*/
|
|
@@ -314,7 +306,7 @@ class DynamoDBService {
|
|
|
314
306
|
*/
|
|
315
307
|
async getItem(input) {
|
|
316
308
|
this.logger.info('Getting DynamoDB item', {
|
|
317
|
-
input:
|
|
309
|
+
input: redactInput(this.logger, input, GET_ITEM_SAFE_FIELDS),
|
|
318
310
|
});
|
|
319
311
|
const response = await this.client.send(new libDynamodb.GetCommand(input));
|
|
320
312
|
return response.Item;
|
|
@@ -326,7 +318,7 @@ class DynamoDBService {
|
|
|
326
318
|
*/
|
|
327
319
|
async putItem(input) {
|
|
328
320
|
this.logger.info('Putting DynamoDB item', {
|
|
329
|
-
input:
|
|
321
|
+
input: redactInput(this.logger, input, PUT_ITEM_SAFE_FIELDS),
|
|
330
322
|
});
|
|
331
323
|
return this.client.send(new libDynamodb.PutCommand(input));
|
|
332
324
|
}
|
|
@@ -342,7 +334,7 @@ class DynamoDBService {
|
|
|
342
334
|
*/
|
|
343
335
|
async updateItem(input) {
|
|
344
336
|
this.logger.info('Updating DynamoDB item', {
|
|
345
|
-
input:
|
|
337
|
+
input: redactInput(this.logger, input, UPDATE_ITEM_SAFE_FIELDS),
|
|
346
338
|
});
|
|
347
339
|
const response = await this.client.send(new libDynamodb.UpdateCommand(input));
|
|
348
340
|
return response;
|
|
@@ -355,7 +347,7 @@ class DynamoDBService {
|
|
|
355
347
|
*/
|
|
356
348
|
async deleteItem(input) {
|
|
357
349
|
this.logger.info('Deleting DynamoDB item', {
|
|
358
|
-
input:
|
|
350
|
+
input: redactInput(this.logger, input, DELETE_ITEM_SAFE_FIELDS),
|
|
359
351
|
});
|
|
360
352
|
const response = await this.client.send(new libDynamodb.DeleteCommand(input));
|
|
361
353
|
return response;
|
|
@@ -368,7 +360,7 @@ class DynamoDBService {
|
|
|
368
360
|
*/
|
|
369
361
|
async query(input) {
|
|
370
362
|
this.logger.info('Querying DynamoDB', {
|
|
371
|
-
input:
|
|
363
|
+
input: redactInput(this.logger, input, QUERY_SAFE_FIELDS),
|
|
372
364
|
});
|
|
373
365
|
const response = await this.client.send(new libDynamodb.QueryCommand(input));
|
|
374
366
|
return response;
|
|
@@ -394,7 +386,7 @@ class DynamoDBService {
|
|
|
394
386
|
*/
|
|
395
387
|
async scan(input) {
|
|
396
388
|
this.logger.info('Scanning DynamoDB', {
|
|
397
|
-
input:
|
|
389
|
+
input: redactInput(this.logger, input, SCAN_SAFE_FIELDS),
|
|
398
390
|
});
|
|
399
391
|
const response = await this.client.send(new libDynamodb.ScanCommand(input));
|
|
400
392
|
return response;
|
|
@@ -411,13 +403,8 @@ class DynamoDBService {
|
|
|
411
403
|
* Callers should narrow the result type at the call site.
|
|
412
404
|
*/
|
|
413
405
|
async batchGet(input) {
|
|
414
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because
|
|
415
|
-
// `RequestItems` is a `Record<tableName, KeysAndAttributes>` — the
|
|
416
|
-
// payload (`Keys[]`) lives inside the value, not as a top-level key
|
|
417
|
-
// the helper could pick or drop.
|
|
418
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
419
406
|
this.logger.info('Batch getting DynamoDB items', {
|
|
420
|
-
input:
|
|
407
|
+
input: redactInput(this.logger, input, summariseTables),
|
|
421
408
|
});
|
|
422
409
|
let current = input;
|
|
423
410
|
const mergedResponses = {};
|
|
@@ -446,13 +433,8 @@ class DynamoDBService {
|
|
|
446
433
|
* items remain unprocessed after the final attempt.
|
|
447
434
|
*/
|
|
448
435
|
async batchWrite(input) {
|
|
449
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because
|
|
450
|
-
// `RequestItems` is a `Record<tableName, WriteRequest[]>` — the
|
|
451
|
-
// payload (`PutRequest.Item` / `DeleteRequest.Key`) lives inside the
|
|
452
|
-
// value, not as a top-level key the helper could pick or drop.
|
|
453
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
454
436
|
this.logger.info('Batch writing DynamoDB items', {
|
|
455
|
-
input:
|
|
437
|
+
input: redactInput(this.logger, input, summariseTables),
|
|
456
438
|
});
|
|
457
439
|
let current = input;
|
|
458
440
|
for (let attempt = 0; attempt < BATCH_WRITE_MAX_ATTEMPTS; attempt++) {
|
|
@@ -498,7 +480,7 @@ class DynamoDBService {
|
|
|
498
480
|
*/
|
|
499
481
|
async *paginateItems(input) {
|
|
500
482
|
this.logger.info('Paginating DynamoDB query', {
|
|
501
|
-
input:
|
|
483
|
+
input: redactInput(this.logger, input, QUERY_SAFE_FIELDS),
|
|
502
484
|
});
|
|
503
485
|
const paginator = libDynamodb.paginateQuery({ client: this.client }, input);
|
|
504
486
|
for await (const page of paginator) {
|
|
@@ -519,7 +501,7 @@ class DynamoDBService {
|
|
|
519
501
|
*/
|
|
520
502
|
async *paginateScan(input) {
|
|
521
503
|
this.logger.info('Paginating DynamoDB scan', {
|
|
522
|
-
input:
|
|
504
|
+
input: redactInput(this.logger, input, SCAN_SAFE_FIELDS),
|
|
523
505
|
});
|
|
524
506
|
const paginator = libDynamodb.paginateScan({ client: this.client }, input);
|
|
525
507
|
for await (const page of paginator) {
|
|
@@ -531,6 +513,18 @@ class DynamoDBService {
|
|
|
531
513
|
}
|
|
532
514
|
}
|
|
533
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Split a list into consecutive chunks of at most `size` items, mirroring the
|
|
518
|
+
* per-request caps the AWS APIs enforce on batch operations.
|
|
519
|
+
*/
|
|
520
|
+
function chunk(items, size) {
|
|
521
|
+
const chunks = [];
|
|
522
|
+
for (let i = 0; i < items.length; i += size) {
|
|
523
|
+
chunks.push(items.slice(i, i + size));
|
|
524
|
+
}
|
|
525
|
+
return chunks;
|
|
526
|
+
}
|
|
527
|
+
|
|
534
528
|
const DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
|
|
535
529
|
const DELETE_OBJECTS_BATCH_LIMIT = 1000;
|
|
536
530
|
/**
|
|
@@ -582,7 +576,7 @@ class S3Service {
|
|
|
582
576
|
*/
|
|
583
577
|
async putObject(input) {
|
|
584
578
|
this.logger.info('Putting S3 object', {
|
|
585
|
-
input:
|
|
579
|
+
input: redactInput(this.logger, input, PUT_OBJECT_SAFE_FIELDS),
|
|
586
580
|
});
|
|
587
581
|
return this.client.send(new clientS3.PutObjectCommand(input));
|
|
588
582
|
}
|
|
@@ -597,7 +591,7 @@ class S3Service {
|
|
|
597
591
|
*/
|
|
598
592
|
async putJsonObject(input) {
|
|
599
593
|
this.logger.info('Putting S3 JSON object', {
|
|
600
|
-
input:
|
|
594
|
+
input: redactInput(this.logger, input, PUT_JSON_OBJECT_SAFE_FIELDS),
|
|
601
595
|
});
|
|
602
596
|
return this.client.send(new clientS3.PutObjectCommand({
|
|
603
597
|
Bucket: input.Bucket,
|
|
@@ -656,14 +650,8 @@ class S3Service {
|
|
|
656
650
|
async listObjects(bucket, prefix) {
|
|
657
651
|
this.logger.info('Listing S3 objects', { input: { bucket, prefix } });
|
|
658
652
|
const paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket, Prefix: prefix });
|
|
659
|
-
const
|
|
660
|
-
|
|
661
|
-
for (const object of page.Contents ?? []) {
|
|
662
|
-
if (object.Key)
|
|
663
|
-
keys.push(object.Key);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
return keys;
|
|
653
|
+
const objects = await collectItems(paginator, page => page.Contents);
|
|
654
|
+
return objects.flatMap(object => (object.Key ? [object.Key] : []));
|
|
667
655
|
}
|
|
668
656
|
/**
|
|
669
657
|
* List and JSON-parse every object under a bucket and optional prefix.
|
|
@@ -731,16 +719,14 @@ class S3Service {
|
|
|
731
719
|
* per chunk.
|
|
732
720
|
*/
|
|
733
721
|
async deleteObjects(bucket, keys) {
|
|
734
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
735
|
-
// safe log shape includes the computed `keyCount`, which isn't a key
|
|
736
|
-
// on any SDK input type.
|
|
737
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
738
722
|
this.logger.info('Deleting S3 objects', {
|
|
739
|
-
input:
|
|
723
|
+
input: redactInput(this.logger, { bucket, keys }, input => ({
|
|
724
|
+
bucket: input.bucket,
|
|
725
|
+
keyCount: input.keys.length,
|
|
726
|
+
})),
|
|
740
727
|
});
|
|
741
728
|
const results = [];
|
|
742
|
-
for (
|
|
743
|
-
const batch = keys.slice(i, i + DELETE_OBJECTS_BATCH_LIMIT);
|
|
729
|
+
for (const batch of chunk(keys, DELETE_OBJECTS_BATCH_LIMIT)) {
|
|
744
730
|
results.push(await this.client.send(new clientS3.DeleteObjectsCommand({
|
|
745
731
|
Bucket: bucket,
|
|
746
732
|
Delete: { Objects: batch.map(Key => ({ Key })) },
|
|
@@ -786,21 +772,14 @@ class S3Service {
|
|
|
786
772
|
* PII (customer IDs, order contents, etc.), the same risk profile as SFN's
|
|
787
773
|
* execution `input`.
|
|
788
774
|
*
|
|
789
|
-
* This can't
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
793
|
-
* `
|
|
794
|
-
*
|
|
795
|
-
* `Target.Input`.
|
|
796
|
-
*
|
|
797
|
-
* At the verbose levels — see {@link shouldLogFullInput} — the input is
|
|
798
|
-
* returned unchanged: operators who asked for that verbosity have opted into
|
|
799
|
-
* seeing payloads and PII.
|
|
775
|
+
* This can't be a key allowlist for {@link redactInput}: an allowlist picks
|
|
776
|
+
* **top-level** keys only, and the sensitive field is nested one level down
|
|
777
|
+
* inside `Target`. Allowlisting `Target` would leak `Input`; omitting `Target`
|
|
778
|
+
* would lose operationally-useful fields (`Arn`, `RoleArn`, `RetryPolicy`,
|
|
779
|
+
* `DeadLetterConfig`, the target-type params). So this is a projection
|
|
780
|
+
* function: keep every top-level field and shallow-strip only `Target.Input`.
|
|
800
781
|
*/
|
|
801
|
-
function
|
|
802
|
-
if (shouldLogFullInput(logger))
|
|
803
|
-
return input;
|
|
782
|
+
function stripTargetInput(input) {
|
|
804
783
|
if (input.Target?.Input === undefined)
|
|
805
784
|
return input;
|
|
806
785
|
const { Input: _input, ...safeTarget } = input.Target;
|
|
@@ -840,7 +819,9 @@ class SchedulerService {
|
|
|
840
819
|
* target payload, a PII carrier).
|
|
841
820
|
*/
|
|
842
821
|
async createSchedule(input) {
|
|
843
|
-
this.logger.info('Creating schedule', {
|
|
822
|
+
this.logger.info('Creating schedule', {
|
|
823
|
+
input: redactInput(this.logger, input, stripTargetInput),
|
|
824
|
+
});
|
|
844
825
|
return this.client.send(new clientScheduler.CreateScheduleCommand(input));
|
|
845
826
|
}
|
|
846
827
|
/**
|
|
@@ -864,7 +845,9 @@ class SchedulerService {
|
|
|
864
845
|
* At INFO the log line omits `Target.Input`.
|
|
865
846
|
*/
|
|
866
847
|
async updateSchedule(input) {
|
|
867
|
-
this.logger.info('Updating schedule', {
|
|
848
|
+
this.logger.info('Updating schedule', {
|
|
849
|
+
input: redactInput(this.logger, input, stripTargetInput),
|
|
850
|
+
});
|
|
868
851
|
return this.client.send(new clientScheduler.UpdateScheduleCommand(input));
|
|
869
852
|
}
|
|
870
853
|
/**
|
|
@@ -882,12 +865,7 @@ class SchedulerService {
|
|
|
882
865
|
async listSchedules(input) {
|
|
883
866
|
this.logger.info('Listing schedules', { input });
|
|
884
867
|
const paginator = clientScheduler.paginateListSchedules({ client: this.client }, input ?? {});
|
|
885
|
-
|
|
886
|
-
for await (const page of paginator) {
|
|
887
|
-
if (page.Schedules)
|
|
888
|
-
schedules.push(...page.Schedules);
|
|
889
|
-
}
|
|
890
|
-
return schedules;
|
|
868
|
+
return collectItems(paginator, page => page.Schedules);
|
|
891
869
|
}
|
|
892
870
|
/**
|
|
893
871
|
* Create a new schedule group. Groups are containers for schedules and are
|
|
@@ -920,12 +898,7 @@ class SchedulerService {
|
|
|
920
898
|
async listScheduleGroups(input) {
|
|
921
899
|
this.logger.info('Listing schedule groups', { input });
|
|
922
900
|
const paginator = clientScheduler.paginateListScheduleGroups({ client: this.client }, input ?? {});
|
|
923
|
-
|
|
924
|
-
for await (const page of paginator) {
|
|
925
|
-
if (page.ScheduleGroups)
|
|
926
|
-
groups.push(...page.ScheduleGroups);
|
|
927
|
-
}
|
|
928
|
-
return groups;
|
|
901
|
+
return collectItems(paginator, page => page.ScheduleGroups);
|
|
929
902
|
}
|
|
930
903
|
}
|
|
931
904
|
|
|
@@ -1024,7 +997,7 @@ class SecretsManagerService {
|
|
|
1024
997
|
*/
|
|
1025
998
|
async createSecret(input) {
|
|
1026
999
|
this.logger.info('Creating secret', {
|
|
1027
|
-
input:
|
|
1000
|
+
input: redactInput(this.logger, input, CREATE_SECRET_SAFE_FIELDS),
|
|
1028
1001
|
});
|
|
1029
1002
|
return this.client.send(new clientSecretsManager.CreateSecretCommand(input));
|
|
1030
1003
|
}
|
|
@@ -1037,7 +1010,7 @@ class SecretsManagerService {
|
|
|
1037
1010
|
*/
|
|
1038
1011
|
async updateSecret(input) {
|
|
1039
1012
|
this.logger.info('Updating secret', {
|
|
1040
|
-
input:
|
|
1013
|
+
input: redactInput(this.logger, input, UPDATE_SECRET_SAFE_FIELDS),
|
|
1041
1014
|
});
|
|
1042
1015
|
return this.client.send(new clientSecretsManager.UpdateSecretCommand(input));
|
|
1043
1016
|
}
|
|
@@ -1049,7 +1022,7 @@ class SecretsManagerService {
|
|
|
1049
1022
|
*/
|
|
1050
1023
|
async putSecretValue(input) {
|
|
1051
1024
|
this.logger.info('Putting secret value', {
|
|
1052
|
-
input:
|
|
1025
|
+
input: redactInput(this.logger, input, PUT_SECRET_VALUE_SAFE_FIELDS),
|
|
1053
1026
|
});
|
|
1054
1027
|
return this.client.send(new clientSecretsManager.PutSecretValueCommand(input));
|
|
1055
1028
|
}
|
|
@@ -1061,7 +1034,7 @@ class SecretsManagerService {
|
|
|
1061
1034
|
*/
|
|
1062
1035
|
async deleteSecret(input) {
|
|
1063
1036
|
this.logger.info('Deleting secret', {
|
|
1064
|
-
input:
|
|
1037
|
+
input: redactInput(this.logger, input, DELETE_SECRET_SAFE_FIELDS),
|
|
1065
1038
|
});
|
|
1066
1039
|
return this.client.send(new clientSecretsManager.DeleteSecretCommand(input));
|
|
1067
1040
|
}
|
|
@@ -1113,19 +1086,14 @@ class StepFunctionsService {
|
|
|
1113
1086
|
async listExecutions(input) {
|
|
1114
1087
|
this.logger.info('Listing Step Functions executions', { input });
|
|
1115
1088
|
const paginator = clientSfn.paginateListExecutions({ client: this.client }, input);
|
|
1116
|
-
|
|
1117
|
-
for await (const page of paginator) {
|
|
1118
|
-
if (page.executions)
|
|
1119
|
-
executions.push(...page.executions);
|
|
1120
|
-
}
|
|
1121
|
-
return executions;
|
|
1089
|
+
return collectItems(paginator, page => page.executions);
|
|
1122
1090
|
}
|
|
1123
1091
|
/**
|
|
1124
1092
|
* Start a new Step Functions execution.
|
|
1125
1093
|
*/
|
|
1126
1094
|
async startExecution(input) {
|
|
1127
1095
|
this.logger.info('Starting Step Functions execution', {
|
|
1128
|
-
input:
|
|
1096
|
+
input: redactInput(this.logger, input, START_EXECUTION_SAFE_FIELDS),
|
|
1129
1097
|
});
|
|
1130
1098
|
return this.client.send(new clientSfn.StartExecutionCommand(input));
|
|
1131
1099
|
}
|
|
@@ -1145,6 +1113,59 @@ class StepFunctionsService {
|
|
|
1145
1113
|
}
|
|
1146
1114
|
}
|
|
1147
1115
|
|
|
1116
|
+
/**
|
|
1117
|
+
* Thrown by the batch methods once every chunk has been sent and at least one
|
|
1118
|
+
* entry was rejected.
|
|
1119
|
+
*
|
|
1120
|
+
* `results` holds the raw SDK output of every chunk, so the outputs of the
|
|
1121
|
+
* entries that succeeded (message ids, sequence numbers) stay readable.
|
|
1122
|
+
* `failed` is the normalised list of rejected entries across all chunks.
|
|
1123
|
+
*
|
|
1124
|
+
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
1125
|
+
* this package may be loaded in one process.
|
|
1126
|
+
*/
|
|
1127
|
+
class BatchOperationError extends Error {
|
|
1128
|
+
results;
|
|
1129
|
+
failed;
|
|
1130
|
+
name = 'BatchOperationError';
|
|
1131
|
+
constructor(results, failed) {
|
|
1132
|
+
super(`Batch operation failed for ${failed.length} entries (${distinctCodes(failed).join(', ')})`);
|
|
1133
|
+
this.results = results;
|
|
1134
|
+
this.failed = failed;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* SQS and SNS report rejected entries under `Failed` on an otherwise
|
|
1139
|
+
* successful response, so a resolved chunk does not mean every entry was
|
|
1140
|
+
* accepted. Returns `results` untouched when nothing failed; otherwise warns
|
|
1141
|
+
* and throws a {@link BatchOperationError}.
|
|
1142
|
+
*
|
|
1143
|
+
* Only id, code and message are copied out — never the entry itself — so
|
|
1144
|
+
* neither the error nor the warning can leak a payload.
|
|
1145
|
+
*/
|
|
1146
|
+
function throwIfAnyFailed(logger, operation, results) {
|
|
1147
|
+
const failed = results.flatMap(result => (result.Failed ?? []).map(({ Id, Code, Message }) => ({
|
|
1148
|
+
id: Id,
|
|
1149
|
+
code: Code,
|
|
1150
|
+
message: Message,
|
|
1151
|
+
})));
|
|
1152
|
+
if (failed.length === 0)
|
|
1153
|
+
return results;
|
|
1154
|
+
logger.warn(`${operation} had rejected entries`, {
|
|
1155
|
+
failedCount: failed.length,
|
|
1156
|
+
codes: distinctCodes(failed),
|
|
1157
|
+
});
|
|
1158
|
+
throw new BatchOperationError(results, failed);
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* Distinct error codes in first-seen order, for the error message and the
|
|
1162
|
+
* warning log line.
|
|
1163
|
+
*/
|
|
1164
|
+
function distinctCodes(failed) {
|
|
1165
|
+
const codes = failed.flatMap(entry => (entry.code === undefined ? [] : [entry.code]));
|
|
1166
|
+
return [...new Set(codes)];
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1148
1169
|
/**
|
|
1149
1170
|
* Truncate a UTF-8 string to fit within `maxBytes` when encoded as UTF-8.
|
|
1150
1171
|
*
|
|
@@ -1234,7 +1255,7 @@ class SNSService {
|
|
|
1234
1255
|
const shouldTruncate = opts?.truncate ?? this.truncate;
|
|
1235
1256
|
const effective = shouldTruncate ? this.applyTruncation(input) : input;
|
|
1236
1257
|
this.logger.info('Publishing SNS message', {
|
|
1237
|
-
input:
|
|
1258
|
+
input: redactInput(this.logger, effective, PUBLISH_SAFE_FIELDS),
|
|
1238
1259
|
});
|
|
1239
1260
|
return this.client.send(new clientSns.PublishCommand(effective));
|
|
1240
1261
|
}
|
|
@@ -1272,26 +1293,31 @@ class SNSService {
|
|
|
1272
1293
|
* PublishBatch at 10 entries per request, so this method auto-chunks
|
|
1273
1294
|
* the caller's `PublishBatchRequestEntries` and sends one request per
|
|
1274
1295
|
* chunk, returning the array of outputs.
|
|
1296
|
+
*
|
|
1297
|
+
* Every chunk is sent before the outcome is judged. If SNS rejected any
|
|
1298
|
+
* entry, a {@link BatchOperationError} is then thrown carrying the
|
|
1299
|
+
* per-chunk results and the failed entries. Request-level SDK exceptions
|
|
1300
|
+
* (throttling, access denied) propagate unchanged and immediately, so
|
|
1301
|
+
* earlier chunks may already have been published.
|
|
1302
|
+
*
|
|
1275
1303
|
* @param input - PublishBatchCommandInput including TopicArn and entries.
|
|
1276
1304
|
*/
|
|
1277
1305
|
async publishBatch(input) {
|
|
1278
1306
|
const entries = input.PublishBatchRequestEntries ?? [];
|
|
1279
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
1280
|
-
// safe log shape includes the computed `entryCount`, which isn't a key
|
|
1281
|
-
// on `PublishBatchCommandInput`.
|
|
1282
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
1283
1307
|
this.logger.info('Publishing SNS message batch', {
|
|
1284
|
-
input:
|
|
1308
|
+
input: redactInput(this.logger, input, ({ TopicArn }) => ({
|
|
1309
|
+
TopicArn,
|
|
1310
|
+
entryCount: entries.length,
|
|
1311
|
+
})),
|
|
1285
1312
|
});
|
|
1286
1313
|
const results = [];
|
|
1287
|
-
for (
|
|
1288
|
-
const chunk = entries.slice(i, i + PUBLISH_BATCH_LIMIT);
|
|
1314
|
+
for (const batch of chunk(entries, PUBLISH_BATCH_LIMIT)) {
|
|
1289
1315
|
results.push(await this.client.send(new clientSns.PublishBatchCommand({
|
|
1290
1316
|
...input,
|
|
1291
|
-
PublishBatchRequestEntries:
|
|
1317
|
+
PublishBatchRequestEntries: batch,
|
|
1292
1318
|
})));
|
|
1293
1319
|
}
|
|
1294
|
-
return results;
|
|
1320
|
+
return throwIfAnyFailed(this.logger, 'SNS publishBatch', results);
|
|
1295
1321
|
}
|
|
1296
1322
|
}
|
|
1297
1323
|
|
|
@@ -1307,6 +1333,13 @@ const SEND_MESSAGE_SAFE_FIELDS = [
|
|
|
1307
1333
|
'MessageGroupId',
|
|
1308
1334
|
'MessageDeduplicationId',
|
|
1309
1335
|
];
|
|
1336
|
+
/**
|
|
1337
|
+
* Safe log shape for the batch methods. The entries carry message bodies and
|
|
1338
|
+
* receipt handles, so they are reduced to a count.
|
|
1339
|
+
*/
|
|
1340
|
+
function summariseEntries(input) {
|
|
1341
|
+
return { QueueUrl: input.QueueUrl, entryCount: input.Entries?.length ?? 0 };
|
|
1342
|
+
}
|
|
1310
1343
|
/**
|
|
1311
1344
|
* Wrapper around the AWS SQS client providing structured Powertools logging
|
|
1312
1345
|
* and X-Ray tracing by default.
|
|
@@ -1344,7 +1377,7 @@ class SQSService {
|
|
|
1344
1377
|
const shouldTruncate = opts?.truncate ?? this.truncate;
|
|
1345
1378
|
const effective = shouldTruncate ? this.applyTruncation(input) : input;
|
|
1346
1379
|
this.logger.info('Sending SQS message', {
|
|
1347
|
-
input:
|
|
1380
|
+
input: redactInput(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
|
|
1348
1381
|
});
|
|
1349
1382
|
return this.client.send(new clientSqs.SendMessageCommand(effective));
|
|
1350
1383
|
}
|
|
@@ -1392,43 +1425,46 @@ class SQSService {
|
|
|
1392
1425
|
* Send a batch of messages to an SQS queue. The SQS API caps
|
|
1393
1426
|
* SendMessageBatch at 10 entries per request, so this method auto-chunks
|
|
1394
1427
|
* the caller's entries and sends one request per chunk.
|
|
1428
|
+
*
|
|
1429
|
+
* Every chunk is sent before the outcome is judged. If SQS rejected any
|
|
1430
|
+
* entry, a {@link BatchOperationError} is then thrown carrying the
|
|
1431
|
+
* per-chunk results and the failed entries. Request-level SDK exceptions
|
|
1432
|
+
* (throttling, access denied) propagate unchanged and immediately, so
|
|
1433
|
+
* earlier chunks may already have been sent.
|
|
1395
1434
|
*/
|
|
1396
1435
|
async sendMessageBatch(input) {
|
|
1397
1436
|
const entries = input.Entries ?? [];
|
|
1398
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
1399
|
-
// safe log shape includes the computed `entryCount`, which isn't a key
|
|
1400
|
-
// on `SendMessageBatchCommandInput`.
|
|
1401
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
1402
1437
|
this.logger.info('Sending SQS message batch', {
|
|
1403
|
-
input:
|
|
1438
|
+
input: redactInput(this.logger, input, summariseEntries),
|
|
1404
1439
|
});
|
|
1405
1440
|
const results = [];
|
|
1406
|
-
for (
|
|
1407
|
-
|
|
1408
|
-
results.push(await this.client.send(new clientSqs.SendMessageBatchCommand({ ...input, Entries: chunk })));
|
|
1441
|
+
for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
|
|
1442
|
+
results.push(await this.client.send(new clientSqs.SendMessageBatchCommand({ ...input, Entries: batch })));
|
|
1409
1443
|
}
|
|
1410
|
-
return results;
|
|
1444
|
+
return throwIfAnyFailed(this.logger, 'SQS sendMessageBatch', results);
|
|
1411
1445
|
}
|
|
1412
1446
|
/**
|
|
1413
1447
|
* Delete a batch of messages from an SQS queue. The SQS API caps
|
|
1414
1448
|
* DeleteMessageBatch at 10 entries per request, so this method auto-chunks
|
|
1415
1449
|
* the caller's entries and sends one request per chunk.
|
|
1450
|
+
*
|
|
1451
|
+
* Every chunk is sent before the outcome is judged. If SQS failed to
|
|
1452
|
+
* delete any message, a {@link BatchOperationError} is then thrown carrying
|
|
1453
|
+
* the per-chunk results and the failed entries; those messages will be
|
|
1454
|
+
* redelivered. Request-level SDK exceptions (throttling, access denied)
|
|
1455
|
+
* propagate unchanged and immediately, so earlier chunks may already have
|
|
1456
|
+
* been deleted.
|
|
1416
1457
|
*/
|
|
1417
1458
|
async deleteMessageBatch(input) {
|
|
1418
1459
|
const entries = input.Entries ?? [];
|
|
1419
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
1420
|
-
// safe log shape includes the computed `entryCount`, which isn't a key
|
|
1421
|
-
// on `DeleteMessageBatchCommandInput`.
|
|
1422
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
1423
1460
|
this.logger.info('Deleting SQS message batch', {
|
|
1424
|
-
input:
|
|
1461
|
+
input: redactInput(this.logger, input, summariseEntries),
|
|
1425
1462
|
});
|
|
1426
1463
|
const results = [];
|
|
1427
|
-
for (
|
|
1428
|
-
|
|
1429
|
-
results.push(await this.client.send(new clientSqs.DeleteMessageBatchCommand({ ...input, Entries: chunk })));
|
|
1464
|
+
for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
|
|
1465
|
+
results.push(await this.client.send(new clientSqs.DeleteMessageBatchCommand({ ...input, Entries: batch })));
|
|
1430
1466
|
}
|
|
1431
|
-
return results;
|
|
1467
|
+
return throwIfAnyFailed(this.logger, 'SQS deleteMessageBatch', results);
|
|
1432
1468
|
}
|
|
1433
1469
|
}
|
|
1434
1470
|
|
|
@@ -1517,10 +1553,9 @@ class SSMService {
|
|
|
1517
1553
|
this.logger.info('Fetching SSM parameters', { input: { aliases } });
|
|
1518
1554
|
const names = Object.values(aliases);
|
|
1519
1555
|
const byPath = new Map();
|
|
1520
|
-
for (
|
|
1521
|
-
const chunk = names.slice(i, i + GET_PARAMETERS_LIMIT);
|
|
1556
|
+
for (const batch of chunk(names, GET_PARAMETERS_LIMIT)) {
|
|
1522
1557
|
const response = await this.client.send(new clientSsm.GetParametersCommand({
|
|
1523
|
-
Names:
|
|
1558
|
+
Names: batch,
|
|
1524
1559
|
WithDecryption: true,
|
|
1525
1560
|
}));
|
|
1526
1561
|
for (const parameter of response.Parameters ?? []) {
|
|
@@ -1543,7 +1578,7 @@ class SSMService {
|
|
|
1543
1578
|
*/
|
|
1544
1579
|
async putParameter(input) {
|
|
1545
1580
|
this.logger.info('Putting SSM parameter', {
|
|
1546
|
-
input:
|
|
1581
|
+
input: redactInput(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
|
|
1547
1582
|
});
|
|
1548
1583
|
return this.client.send(new clientSsm.PutParameterCommand(input));
|
|
1549
1584
|
}
|
|
@@ -1574,16 +1609,13 @@ class SSMService {
|
|
|
1574
1609
|
input: { path, recursive },
|
|
1575
1610
|
});
|
|
1576
1611
|
const paginator = clientSsm.paginateGetParametersByPath({ client: this.client }, { Path: path, Recursive: recursive, WithDecryption: true });
|
|
1577
|
-
|
|
1578
|
-
for await (const page of paginator) {
|
|
1579
|
-
parameters.push(...(page.Parameters ?? []));
|
|
1580
|
-
}
|
|
1581
|
-
return parameters;
|
|
1612
|
+
return collectItems(paginator, page => page.Parameters);
|
|
1582
1613
|
}
|
|
1583
1614
|
}
|
|
1584
1615
|
|
|
1585
1616
|
exports.APIGatewayService = APIGatewayService;
|
|
1586
1617
|
exports.APIGatewayV2Service = APIGatewayV2Service;
|
|
1618
|
+
exports.BatchOperationError = BatchOperationError;
|
|
1587
1619
|
exports.DynamoDBService = DynamoDBService;
|
|
1588
1620
|
exports.S3Service = S3Service;
|
|
1589
1621
|
exports.SNSService = SNSService;
|