@aligent/aws-wrappers 0.5.6 → 0.5.8
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 +21 -4
- package/cjs/index.cjs +192 -152
- package/cjs/package.json +14 -14
- package/cjs/src/dynamodb/dynamodb.d.ts.map +1 -1
- package/cjs/src/index.d.ts +1 -0
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/s3/s3.d.ts +26 -4
- package/cjs/src/s3/s3.d.ts.map +1 -1
- package/cjs/src/scheduler/scheduler.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 +0 -7
- package/cjs/src/sqs/sqs.d.ts.map +1 -1
- package/cjs/src/util/batch-operation-error.d.ts +45 -5
- package/cjs/src/util/batch-operation-error.d.ts.map +1 -1
- 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 +9 -6
- package/docs/index/classes/DynamoDBService.md +34 -12
- package/docs/index/classes/S3Service.md +42 -19
- package/docs/index/classes/SNSService.md +10 -4
- package/docs/index/classes/SQSService.md +7 -7
- package/docs/index/classes/SSMService.md +9 -7
- package/docs/index/classes/SchedulerService.md +11 -11
- package/docs/index/classes/SecretsManagerService.md +10 -8
- package/docs/index/classes/StepFunctionsService.md +6 -6
- package/docs/index/interfaces/BatchFailedEntry.md +5 -5
- package/docs/index/interfaces/EmptyBucketPageResult.md +23 -0
- package/docs/index/modules.md +1 -0
- package/docs/testing/testing/functions/createMockService.md +5 -1
- package/esm/index.mjs +192 -152
- package/esm/package.json +14 -14
- package/esm/src/dynamodb/dynamodb.d.ts.map +1 -1
- package/esm/src/index.d.ts +1 -0
- package/esm/src/index.d.ts.map +1 -1
- package/esm/src/s3/s3.d.ts +26 -4
- package/esm/src/s3/s3.d.ts.map +1 -1
- package/esm/src/scheduler/scheduler.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 +0 -7
- package/esm/src/sqs/sqs.d.ts.map +1 -1
- package/esm/src/util/batch-operation-error.d.ts +45 -5
- package/esm/src/util/batch-operation-error.d.ts.map +1 -1
- package/esm/src/util/redact.d.ts +17 -18
- package/esm/src/util/redact.d.ts.map +1 -1
- package/package.json +14 -14
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,81 @@ class DynamoDBService {
|
|
|
531
513
|
}
|
|
532
514
|
}
|
|
533
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Thrown by the batch methods once every chunk has been sent and at least one
|
|
518
|
+
* entry was rejected.
|
|
519
|
+
*
|
|
520
|
+
* `results` holds the raw SDK output of every chunk, so the outputs of the
|
|
521
|
+
* entries that succeeded (message ids, sequence numbers) stay readable. The
|
|
522
|
+
* one exception is `S3.emptyBucket`, whose `results` are per-page deleted keys.
|
|
523
|
+
* `failed` is the normalised list of rejected entries across all chunks.
|
|
524
|
+
*
|
|
525
|
+
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
526
|
+
* this package may be loaded in one process.
|
|
527
|
+
*/
|
|
528
|
+
class BatchOperationError extends Error {
|
|
529
|
+
results;
|
|
530
|
+
failed;
|
|
531
|
+
name = 'BatchOperationError';
|
|
532
|
+
constructor(results, failed) {
|
|
533
|
+
super(`Batch operation failed for ${failed.length} entries (${distinctCodes(failed).join(', ')})`);
|
|
534
|
+
this.results = results;
|
|
535
|
+
this.failed = failed;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* SQS and SNS report rejected entries under `Failed` on an otherwise
|
|
540
|
+
* successful response, so a resolved chunk does not mean every entry was
|
|
541
|
+
* accepted. Returns `results` untouched when nothing failed; otherwise warns
|
|
542
|
+
* and throws a {@link BatchOperationError}.
|
|
543
|
+
*
|
|
544
|
+
* Only id, code and message are copied out — never the entry itself — so
|
|
545
|
+
* neither the error nor the warning can leak a payload.
|
|
546
|
+
*/
|
|
547
|
+
function throwIfAnyFailed(logger, operation, results) {
|
|
548
|
+
const failed = results.flatMap(result => (result.Failed ?? []).map(({ Id, Code, Message }) => ({
|
|
549
|
+
id: Id,
|
|
550
|
+
code: Code,
|
|
551
|
+
message: Message,
|
|
552
|
+
})));
|
|
553
|
+
return throwIfAny(logger, operation, results, failed);
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* S3 reports undeleted keys under `Errors` on an otherwise successful
|
|
557
|
+
* `DeleteObjects` response. Same contract as {@link throwIfAnyFailed}; the
|
|
558
|
+
* key is carried as the failed entry's `id`, and `VersionId` is dropped.
|
|
559
|
+
*/
|
|
560
|
+
function throwIfAnyDeleteErrors(logger, operation, results) {
|
|
561
|
+
const failed = results.flatMap(result => (result.Errors ?? []).map(({ Key, Code, Message }) => ({
|
|
562
|
+
id: Key,
|
|
563
|
+
code: Code,
|
|
564
|
+
message: Message,
|
|
565
|
+
})));
|
|
566
|
+
return throwIfAny(logger, operation, results, failed);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Throws a {@link BatchOperationError} for operations whose `results` aren't a
|
|
570
|
+
* plain list of SDK outputs, such as `S3.emptyBucket`. Returns `results`
|
|
571
|
+
* untouched when `failed` is empty.
|
|
572
|
+
*/
|
|
573
|
+
function throwIfAny(logger, operation, results, failed) {
|
|
574
|
+
if (failed.length === 0)
|
|
575
|
+
return results;
|
|
576
|
+
logger.warn(`${operation} had rejected entries`, {
|
|
577
|
+
failedCount: failed.length,
|
|
578
|
+
codes: distinctCodes(failed),
|
|
579
|
+
});
|
|
580
|
+
throw new BatchOperationError(results, failed);
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Distinct error codes in first-seen order, for the error message and the
|
|
584
|
+
* warning log line.
|
|
585
|
+
*/
|
|
586
|
+
function distinctCodes(failed) {
|
|
587
|
+
const codes = failed.flatMap(entry => (entry.code === undefined ? [] : [entry.code]));
|
|
588
|
+
return [...new Set(codes)];
|
|
589
|
+
}
|
|
590
|
+
|
|
534
591
|
/**
|
|
535
592
|
* Split a list into consecutive chunks of at most `size` items, mirroring the
|
|
536
593
|
* per-request caps the AWS APIs enforce on batch operations.
|
|
@@ -594,7 +651,7 @@ class S3Service {
|
|
|
594
651
|
*/
|
|
595
652
|
async putObject(input) {
|
|
596
653
|
this.logger.info('Putting S3 object', {
|
|
597
|
-
input:
|
|
654
|
+
input: redactInput(this.logger, input, PUT_OBJECT_SAFE_FIELDS),
|
|
598
655
|
});
|
|
599
656
|
return this.client.send(new clientS3.PutObjectCommand(input));
|
|
600
657
|
}
|
|
@@ -609,7 +666,7 @@ class S3Service {
|
|
|
609
666
|
*/
|
|
610
667
|
async putJsonObject(input) {
|
|
611
668
|
this.logger.info('Putting S3 JSON object', {
|
|
612
|
-
input:
|
|
669
|
+
input: redactInput(this.logger, input, PUT_JSON_OBJECT_SAFE_FIELDS),
|
|
613
670
|
});
|
|
614
671
|
return this.client.send(new clientS3.PutObjectCommand({
|
|
615
672
|
Bucket: input.Bucket,
|
|
@@ -735,14 +792,19 @@ class S3Service {
|
|
|
735
792
|
* Delete multiple objects from S3, auto-chunking the request into batches
|
|
736
793
|
* of 1000 keys (the S3-enforced DeleteObjects limit). Returns one output
|
|
737
794
|
* per chunk.
|
|
795
|
+
*
|
|
796
|
+
* Every chunk is sent before the outcome is judged. If S3 reported a
|
|
797
|
+
* per-key delete error, a {@link BatchOperationError} is then thrown
|
|
798
|
+
* carrying the per-chunk results and the failed keys. Request-level SDK
|
|
799
|
+
* exceptions (throttling, access denied) propagate unchanged and
|
|
800
|
+
* immediately, so earlier chunks may already have been deleted.
|
|
738
801
|
*/
|
|
739
802
|
async deleteObjects(bucket, keys) {
|
|
740
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
741
|
-
// safe log shape includes the computed `keyCount`, which isn't a key
|
|
742
|
-
// on any SDK input type.
|
|
743
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
744
803
|
this.logger.info('Deleting S3 objects', {
|
|
745
|
-
input:
|
|
804
|
+
input: redactInput(this.logger, { bucket, keys }, input => ({
|
|
805
|
+
bucket: input.bucket,
|
|
806
|
+
keyCount: input.keys.length,
|
|
807
|
+
})),
|
|
746
808
|
});
|
|
747
809
|
const results = [];
|
|
748
810
|
for (const batch of chunk(keys, DELETE_OBJECTS_BATCH_LIMIT)) {
|
|
@@ -751,13 +813,20 @@ class S3Service {
|
|
|
751
813
|
Delete: { Objects: batch.map(Key => ({ Key })) },
|
|
752
814
|
})));
|
|
753
815
|
}
|
|
754
|
-
return results;
|
|
816
|
+
return throwIfAnyDeleteErrors(this.logger, 'S3 deleteObjects', results);
|
|
755
817
|
}
|
|
756
818
|
/**
|
|
757
819
|
* Delete every object in an **unversioned** bucket. Streams the listing
|
|
758
|
-
* page-by-page and delegates each page's deletion to `deleteObjects`, so
|
|
759
|
-
*
|
|
760
|
-
*
|
|
820
|
+
* page-by-page and delegates each page's deletion to `deleteObjects`, so no
|
|
821
|
+
* more than one page (~1000 keys) of SDK responses is held at a time. The
|
|
822
|
+
* only thing that grows with the bucket is the list of deleted keys this
|
|
823
|
+
* method returns.
|
|
824
|
+
*
|
|
825
|
+
* A page with per-key delete errors does not stop the run: every page is
|
|
826
|
+
* attempted, then one {@link BatchOperationError} is thrown carrying every
|
|
827
|
+
* failed key in `failed` and, per page, the keys that were deleted in
|
|
828
|
+
* `results`. Request-level SDK exceptions propagate unchanged and
|
|
829
|
+
* immediately, so earlier pages may already have been deleted.
|
|
761
830
|
*
|
|
762
831
|
* **Versioned buckets are out of scope.** This paginates `ListObjectsV2`,
|
|
763
832
|
* which reports only current object versions — never noncurrent versions or
|
|
@@ -768,20 +837,39 @@ class S3Service {
|
|
|
768
837
|
* versioned bucket requires `ListObjectVersions` and per-version deletes;
|
|
769
838
|
* use `S3Client` directly for that.
|
|
770
839
|
*
|
|
771
|
-
* @returns The keys
|
|
840
|
+
* @returns The keys that were deleted.
|
|
841
|
+
* @throws {BatchOperationError} If S3 could not delete one or more keys.
|
|
772
842
|
*/
|
|
773
843
|
async emptyBucket(bucket) {
|
|
774
844
|
this.logger.info('Emptying S3 bucket', { input: { bucket } });
|
|
775
845
|
const paginator = clientS3.paginateListObjectsV2({ client: this.client }, { Bucket: bucket });
|
|
776
|
-
const
|
|
846
|
+
const pages = [];
|
|
847
|
+
const failed = [];
|
|
777
848
|
for await (const page of paginator) {
|
|
778
849
|
const keys = (page.Contents ?? []).flatMap(o => (o.Key ? [o.Key] : []));
|
|
779
850
|
if (keys.length === 0)
|
|
780
851
|
continue;
|
|
852
|
+
const outcome = await this.deletePage(bucket, keys);
|
|
853
|
+
pages.push({ deletedKeys: outcome.deletedKeys });
|
|
854
|
+
failed.push(...outcome.failed);
|
|
855
|
+
}
|
|
856
|
+
throwIfAny(this.logger, 'S3 emptyBucket', pages, failed);
|
|
857
|
+
return pages.flatMap(page => page.deletedKeys);
|
|
858
|
+
}
|
|
859
|
+
async deletePage(bucket, keys) {
|
|
860
|
+
try {
|
|
781
861
|
await this.deleteObjects(bucket, keys);
|
|
782
|
-
deletedKeys
|
|
862
|
+
return { deletedKeys: keys, failed: [] };
|
|
863
|
+
}
|
|
864
|
+
catch (error) {
|
|
865
|
+
if (!(error instanceof BatchOperationError))
|
|
866
|
+
throw error;
|
|
867
|
+
const failedKeys = new Set(error.failed.map(entry => entry.id));
|
|
868
|
+
return {
|
|
869
|
+
deletedKeys: keys.filter(key => !failedKeys.has(key)),
|
|
870
|
+
failed: error.failed,
|
|
871
|
+
};
|
|
783
872
|
}
|
|
784
|
-
return deletedKeys;
|
|
785
873
|
}
|
|
786
874
|
}
|
|
787
875
|
|
|
@@ -791,21 +879,14 @@ class S3Service {
|
|
|
791
879
|
* PII (customer IDs, order contents, etc.), the same risk profile as SFN's
|
|
792
880
|
* execution `input`.
|
|
793
881
|
*
|
|
794
|
-
* This can't
|
|
795
|
-
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
* `
|
|
799
|
-
*
|
|
800
|
-
* `Target.Input`.
|
|
801
|
-
*
|
|
802
|
-
* At the verbose levels — see {@link shouldLogFullInput} — the input is
|
|
803
|
-
* returned unchanged: operators who asked for that verbosity have opted into
|
|
804
|
-
* seeing payloads and PII.
|
|
882
|
+
* This can't be a key allowlist for {@link redactInput}: an allowlist picks
|
|
883
|
+
* **top-level** keys only, and the sensitive field is nested one level down
|
|
884
|
+
* inside `Target`. Allowlisting `Target` would leak `Input`; omitting `Target`
|
|
885
|
+
* would lose operationally-useful fields (`Arn`, `RoleArn`, `RetryPolicy`,
|
|
886
|
+
* `DeadLetterConfig`, the target-type params). So this is a projection
|
|
887
|
+
* function: keep every top-level field and shallow-strip only `Target.Input`.
|
|
805
888
|
*/
|
|
806
|
-
function
|
|
807
|
-
if (shouldLogFullInput(logger))
|
|
808
|
-
return input;
|
|
889
|
+
function stripTargetInput(input) {
|
|
809
890
|
if (input.Target?.Input === undefined)
|
|
810
891
|
return input;
|
|
811
892
|
const { Input: _input, ...safeTarget } = input.Target;
|
|
@@ -845,7 +926,9 @@ class SchedulerService {
|
|
|
845
926
|
* target payload, a PII carrier).
|
|
846
927
|
*/
|
|
847
928
|
async createSchedule(input) {
|
|
848
|
-
this.logger.info('Creating schedule', {
|
|
929
|
+
this.logger.info('Creating schedule', {
|
|
930
|
+
input: redactInput(this.logger, input, stripTargetInput),
|
|
931
|
+
});
|
|
849
932
|
return this.client.send(new clientScheduler.CreateScheduleCommand(input));
|
|
850
933
|
}
|
|
851
934
|
/**
|
|
@@ -869,7 +952,9 @@ class SchedulerService {
|
|
|
869
952
|
* At INFO the log line omits `Target.Input`.
|
|
870
953
|
*/
|
|
871
954
|
async updateSchedule(input) {
|
|
872
|
-
this.logger.info('Updating schedule', {
|
|
955
|
+
this.logger.info('Updating schedule', {
|
|
956
|
+
input: redactInput(this.logger, input, stripTargetInput),
|
|
957
|
+
});
|
|
873
958
|
return this.client.send(new clientScheduler.UpdateScheduleCommand(input));
|
|
874
959
|
}
|
|
875
960
|
/**
|
|
@@ -1019,7 +1104,7 @@ class SecretsManagerService {
|
|
|
1019
1104
|
*/
|
|
1020
1105
|
async createSecret(input) {
|
|
1021
1106
|
this.logger.info('Creating secret', {
|
|
1022
|
-
input:
|
|
1107
|
+
input: redactInput(this.logger, input, CREATE_SECRET_SAFE_FIELDS),
|
|
1023
1108
|
});
|
|
1024
1109
|
return this.client.send(new clientSecretsManager.CreateSecretCommand(input));
|
|
1025
1110
|
}
|
|
@@ -1032,7 +1117,7 @@ class SecretsManagerService {
|
|
|
1032
1117
|
*/
|
|
1033
1118
|
async updateSecret(input) {
|
|
1034
1119
|
this.logger.info('Updating secret', {
|
|
1035
|
-
input:
|
|
1120
|
+
input: redactInput(this.logger, input, UPDATE_SECRET_SAFE_FIELDS),
|
|
1036
1121
|
});
|
|
1037
1122
|
return this.client.send(new clientSecretsManager.UpdateSecretCommand(input));
|
|
1038
1123
|
}
|
|
@@ -1044,7 +1129,7 @@ class SecretsManagerService {
|
|
|
1044
1129
|
*/
|
|
1045
1130
|
async putSecretValue(input) {
|
|
1046
1131
|
this.logger.info('Putting secret value', {
|
|
1047
|
-
input:
|
|
1132
|
+
input: redactInput(this.logger, input, PUT_SECRET_VALUE_SAFE_FIELDS),
|
|
1048
1133
|
});
|
|
1049
1134
|
return this.client.send(new clientSecretsManager.PutSecretValueCommand(input));
|
|
1050
1135
|
}
|
|
@@ -1056,7 +1141,7 @@ class SecretsManagerService {
|
|
|
1056
1141
|
*/
|
|
1057
1142
|
async deleteSecret(input) {
|
|
1058
1143
|
this.logger.info('Deleting secret', {
|
|
1059
|
-
input:
|
|
1144
|
+
input: redactInput(this.logger, input, DELETE_SECRET_SAFE_FIELDS),
|
|
1060
1145
|
});
|
|
1061
1146
|
return this.client.send(new clientSecretsManager.DeleteSecretCommand(input));
|
|
1062
1147
|
}
|
|
@@ -1115,7 +1200,7 @@ class StepFunctionsService {
|
|
|
1115
1200
|
*/
|
|
1116
1201
|
async startExecution(input) {
|
|
1117
1202
|
this.logger.info('Starting Step Functions execution', {
|
|
1118
|
-
input:
|
|
1203
|
+
input: redactInput(this.logger, input, START_EXECUTION_SAFE_FIELDS),
|
|
1119
1204
|
});
|
|
1120
1205
|
return this.client.send(new clientSfn.StartExecutionCommand(input));
|
|
1121
1206
|
}
|
|
@@ -1224,7 +1309,7 @@ class SNSService {
|
|
|
1224
1309
|
const shouldTruncate = opts?.truncate ?? this.truncate;
|
|
1225
1310
|
const effective = shouldTruncate ? this.applyTruncation(input) : input;
|
|
1226
1311
|
this.logger.info('Publishing SNS message', {
|
|
1227
|
-
input:
|
|
1312
|
+
input: redactInput(this.logger, effective, PUBLISH_SAFE_FIELDS),
|
|
1228
1313
|
});
|
|
1229
1314
|
return this.client.send(new clientSns.PublishCommand(effective));
|
|
1230
1315
|
}
|
|
@@ -1262,16 +1347,22 @@ class SNSService {
|
|
|
1262
1347
|
* PublishBatch at 10 entries per request, so this method auto-chunks
|
|
1263
1348
|
* the caller's `PublishBatchRequestEntries` and sends one request per
|
|
1264
1349
|
* chunk, returning the array of outputs.
|
|
1350
|
+
*
|
|
1351
|
+
* Every chunk is sent before the outcome is judged. If SNS rejected any
|
|
1352
|
+
* entry, a {@link BatchOperationError} is then thrown carrying the
|
|
1353
|
+
* per-chunk results and the failed entries. Request-level SDK exceptions
|
|
1354
|
+
* (throttling, access denied) propagate unchanged and immediately, so
|
|
1355
|
+
* earlier chunks may already have been published.
|
|
1356
|
+
*
|
|
1265
1357
|
* @param input - PublishBatchCommandInput including TopicArn and entries.
|
|
1266
1358
|
*/
|
|
1267
1359
|
async publishBatch(input) {
|
|
1268
1360
|
const entries = input.PublishBatchRequestEntries ?? [];
|
|
1269
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
1270
|
-
// safe log shape includes the computed `entryCount`, which isn't a key
|
|
1271
|
-
// on `PublishBatchCommandInput`.
|
|
1272
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
1273
1361
|
this.logger.info('Publishing SNS message batch', {
|
|
1274
|
-
input:
|
|
1362
|
+
input: redactInput(this.logger, input, ({ TopicArn }) => ({
|
|
1363
|
+
TopicArn,
|
|
1364
|
+
entryCount: entries.length,
|
|
1365
|
+
})),
|
|
1275
1366
|
});
|
|
1276
1367
|
const results = [];
|
|
1277
1368
|
for (const batch of chunk(entries, PUBLISH_BATCH_LIMIT)) {
|
|
@@ -1280,40 +1371,10 @@ class SNSService {
|
|
|
1280
1371
|
PublishBatchRequestEntries: batch,
|
|
1281
1372
|
})));
|
|
1282
1373
|
}
|
|
1283
|
-
return results;
|
|
1374
|
+
return throwIfAnyFailed(this.logger, 'SNS publishBatch', results);
|
|
1284
1375
|
}
|
|
1285
1376
|
}
|
|
1286
1377
|
|
|
1287
|
-
/**
|
|
1288
|
-
* Thrown by the batch methods once every chunk has been sent and at least one
|
|
1289
|
-
* entry was rejected.
|
|
1290
|
-
*
|
|
1291
|
-
* `results` holds the raw SDK output of every chunk, so the outputs of the
|
|
1292
|
-
* entries that succeeded (message ids, sequence numbers) stay readable.
|
|
1293
|
-
* `failed` is the normalised list of rejected entries across all chunks.
|
|
1294
|
-
*
|
|
1295
|
-
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
1296
|
-
* this package may be loaded in one process.
|
|
1297
|
-
*/
|
|
1298
|
-
class BatchOperationError extends Error {
|
|
1299
|
-
results;
|
|
1300
|
-
failed;
|
|
1301
|
-
name = 'BatchOperationError';
|
|
1302
|
-
constructor(results, failed) {
|
|
1303
|
-
super(`Batch operation failed for ${failed.length} entries (${distinctCodes(failed).join(', ')})`);
|
|
1304
|
-
this.results = results;
|
|
1305
|
-
this.failed = failed;
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* Distinct error codes in first-seen order, for the error message and the
|
|
1310
|
-
* warning log line.
|
|
1311
|
-
*/
|
|
1312
|
-
function distinctCodes(failed) {
|
|
1313
|
-
const codes = failed.flatMap(entry => (entry.code === undefined ? [] : [entry.code]));
|
|
1314
|
-
return [...new Set(codes)];
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
1378
|
const SQS_BATCH_LIMIT = 10;
|
|
1318
1379
|
const SQS_MESSAGE_BODY_MAX_BYTES = 256 * 1024;
|
|
1319
1380
|
/**
|
|
@@ -1326,6 +1387,13 @@ const SEND_MESSAGE_SAFE_FIELDS = [
|
|
|
1326
1387
|
'MessageGroupId',
|
|
1327
1388
|
'MessageDeduplicationId',
|
|
1328
1389
|
];
|
|
1390
|
+
/**
|
|
1391
|
+
* Safe log shape for the batch methods. The entries carry message bodies and
|
|
1392
|
+
* receipt handles, so they are reduced to a count.
|
|
1393
|
+
*/
|
|
1394
|
+
function summariseEntries(input) {
|
|
1395
|
+
return { QueueUrl: input.QueueUrl, entryCount: input.Entries?.length ?? 0 };
|
|
1396
|
+
}
|
|
1329
1397
|
/**
|
|
1330
1398
|
* Wrapper around the AWS SQS client providing structured Powertools logging
|
|
1331
1399
|
* and X-Ray tracing by default.
|
|
@@ -1363,7 +1431,7 @@ class SQSService {
|
|
|
1363
1431
|
const shouldTruncate = opts?.truncate ?? this.truncate;
|
|
1364
1432
|
const effective = shouldTruncate ? this.applyTruncation(input) : input;
|
|
1365
1433
|
this.logger.info('Sending SQS message', {
|
|
1366
|
-
input:
|
|
1434
|
+
input: redactInput(this.logger, effective, SEND_MESSAGE_SAFE_FIELDS),
|
|
1367
1435
|
});
|
|
1368
1436
|
return this.client.send(new clientSqs.SendMessageCommand(effective));
|
|
1369
1437
|
}
|
|
@@ -1407,26 +1475,6 @@ class SQSService {
|
|
|
1407
1475
|
this.logger.info('Deleting SQS message', { input });
|
|
1408
1476
|
return this.client.send(new clientSqs.DeleteMessageCommand(input));
|
|
1409
1477
|
}
|
|
1410
|
-
/**
|
|
1411
|
-
* SQS reports rejected entries under `Failed` on an otherwise successful
|
|
1412
|
-
* response, so a resolved chunk does not mean every entry was accepted.
|
|
1413
|
-
* Only id, code and message are copied out — never the entry itself — so
|
|
1414
|
-
* neither the error nor the warning can leak a payload.
|
|
1415
|
-
*/
|
|
1416
|
-
throwIfAnyFailed(operation, results) {
|
|
1417
|
-
const failed = results.flatMap(result => (result.Failed ?? []).map(({ Id, Code, Message }) => ({
|
|
1418
|
-
id: Id,
|
|
1419
|
-
code: Code,
|
|
1420
|
-
message: Message,
|
|
1421
|
-
})));
|
|
1422
|
-
if (failed.length === 0)
|
|
1423
|
-
return results;
|
|
1424
|
-
this.logger.warn(`${operation} had rejected entries`, {
|
|
1425
|
-
failedCount: failed.length,
|
|
1426
|
-
codes: distinctCodes(failed),
|
|
1427
|
-
});
|
|
1428
|
-
throw new BatchOperationError(results, failed);
|
|
1429
|
-
}
|
|
1430
1478
|
/**
|
|
1431
1479
|
* Send a batch of messages to an SQS queue. The SQS API caps
|
|
1432
1480
|
* SendMessageBatch at 10 entries per request, so this method auto-chunks
|
|
@@ -1440,18 +1488,14 @@ class SQSService {
|
|
|
1440
1488
|
*/
|
|
1441
1489
|
async sendMessageBatch(input) {
|
|
1442
1490
|
const entries = input.Entries ?? [];
|
|
1443
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
1444
|
-
// safe log shape includes the computed `entryCount`, which isn't a key
|
|
1445
|
-
// on `SendMessageBatchCommandInput`.
|
|
1446
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
1447
1491
|
this.logger.info('Sending SQS message batch', {
|
|
1448
|
-
input:
|
|
1492
|
+
input: redactInput(this.logger, input, summariseEntries),
|
|
1449
1493
|
});
|
|
1450
1494
|
const results = [];
|
|
1451
1495
|
for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
|
|
1452
1496
|
results.push(await this.client.send(new clientSqs.SendMessageBatchCommand({ ...input, Entries: batch })));
|
|
1453
1497
|
}
|
|
1454
|
-
return this.
|
|
1498
|
+
return throwIfAnyFailed(this.logger, 'SQS sendMessageBatch', results);
|
|
1455
1499
|
}
|
|
1456
1500
|
/**
|
|
1457
1501
|
* Delete a batch of messages from an SQS queue. The SQS API caps
|
|
@@ -1467,18 +1511,14 @@ class SQSService {
|
|
|
1467
1511
|
*/
|
|
1468
1512
|
async deleteMessageBatch(input) {
|
|
1469
1513
|
const entries = input.Entries ?? [];
|
|
1470
|
-
// Inline verbosity check rather than `filterFieldsForLogLevel` because the
|
|
1471
|
-
// safe log shape includes the computed `entryCount`, which isn't a key
|
|
1472
|
-
// on `DeleteMessageBatchCommandInput`.
|
|
1473
|
-
const logFullInput = shouldLogFullInput(this.logger);
|
|
1474
1514
|
this.logger.info('Deleting SQS message batch', {
|
|
1475
|
-
input:
|
|
1515
|
+
input: redactInput(this.logger, input, summariseEntries),
|
|
1476
1516
|
});
|
|
1477
1517
|
const results = [];
|
|
1478
1518
|
for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
|
|
1479
1519
|
results.push(await this.client.send(new clientSqs.DeleteMessageBatchCommand({ ...input, Entries: batch })));
|
|
1480
1520
|
}
|
|
1481
|
-
return this.
|
|
1521
|
+
return throwIfAnyFailed(this.logger, 'SQS deleteMessageBatch', results);
|
|
1482
1522
|
}
|
|
1483
1523
|
}
|
|
1484
1524
|
|
|
@@ -1592,7 +1632,7 @@ class SSMService {
|
|
|
1592
1632
|
*/
|
|
1593
1633
|
async putParameter(input) {
|
|
1594
1634
|
this.logger.info('Putting SSM parameter', {
|
|
1595
|
-
input:
|
|
1635
|
+
input: redactInput(this.logger, input, PUT_PARAMETER_SAFE_FIELDS),
|
|
1596
1636
|
});
|
|
1597
1637
|
return this.client.send(new clientSsm.PutParameterCommand(input));
|
|
1598
1638
|
}
|
package/cjs/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aligent/aws-wrappers",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.8",
|
|
4
4
|
"description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -43,19 +43,19 @@
|
|
|
43
43
|
"directory": "packages/aws-wrappers"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@aws-lambda-powertools/logger": "^2.
|
|
47
|
-
"@aws-sdk/client-api-gateway": "^3.
|
|
48
|
-
"@aws-sdk/client-apigatewayv2": "^3.
|
|
49
|
-
"@aws-sdk/client-dynamodb": "^3.
|
|
50
|
-
"@aws-sdk/client-s3": "^3.
|
|
51
|
-
"@aws-sdk/client-scheduler": "^3.
|
|
52
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
53
|
-
"@aws-sdk/client-sfn": "^3.
|
|
54
|
-
"@aws-sdk/client-sns": "^3.
|
|
55
|
-
"@aws-sdk/client-sqs": "^3.
|
|
56
|
-
"@aws-sdk/client-ssm": "^3.
|
|
57
|
-
"@aws-sdk/lib-dynamodb": "^3.
|
|
58
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
|
46
|
+
"@aws-lambda-powertools/logger": "^2.36.0",
|
|
47
|
+
"@aws-sdk/client-api-gateway": "^3.1160.0",
|
|
48
|
+
"@aws-sdk/client-apigatewayv2": "^3.1160.0",
|
|
49
|
+
"@aws-sdk/client-dynamodb": "^3.1160.0",
|
|
50
|
+
"@aws-sdk/client-s3": "^3.1160.0",
|
|
51
|
+
"@aws-sdk/client-scheduler": "^3.1160.0",
|
|
52
|
+
"@aws-sdk/client-secrets-manager": "^3.1160.0",
|
|
53
|
+
"@aws-sdk/client-sfn": "^3.1160.0",
|
|
54
|
+
"@aws-sdk/client-sns": "^3.1160.0",
|
|
55
|
+
"@aws-sdk/client-sqs": "^3.1160.0",
|
|
56
|
+
"@aws-sdk/client-ssm": "^3.1160.0",
|
|
57
|
+
"@aws-sdk/lib-dynamodb": "^3.1160.0",
|
|
58
|
+
"@aws-sdk/s3-request-presigner": "^3.1160.0",
|
|
59
59
|
"aws-xray-sdk-core": "^3.12.0"
|
|
60
60
|
},
|
|
61
61
|
"author": "Aligent",
|