@aligent/aws-wrappers 0.5.8 → 0.5.9
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 +89 -3
- package/cjs/index.cjs +284 -11
- package/cjs/package.json +3 -1
- package/cjs/src/eventbridge/eventbridge.d.ts +58 -0
- package/cjs/src/eventbridge/eventbridge.d.ts.map +1 -0
- package/cjs/src/index.d.ts +3 -0
- package/cjs/src/index.d.ts.map +1 -1
- package/cjs/src/lambda/lambda.d.ts +54 -0
- package/cjs/src/lambda/lambda.d.ts.map +1 -0
- package/cjs/src/scheduler/scheduler.d.ts +3 -2
- package/cjs/src/scheduler/scheduler.d.ts.map +1 -1
- package/cjs/src/ssm/ssm.d.ts +18 -3
- package/cjs/src/ssm/ssm.d.ts.map +1 -1
- package/cjs/src/util/batch-operation-error.d.ts +13 -7
- package/cjs/src/util/batch-operation-error.d.ts.map +1 -1
- package/cjs/src/util/lambda-function-error.d.ts +36 -0
- package/cjs/src/util/lambda-function-error.d.ts.map +1 -0
- package/docs/index/classes/APIGatewayService.md +6 -6
- package/docs/index/classes/APIGatewayV2Service.md +5 -5
- package/docs/index/classes/BatchOperationError.md +7 -6
- package/docs/index/classes/DynamoDBService.md +12 -12
- package/docs/index/classes/EventBridgeService.md +99 -0
- package/docs/index/classes/LambdaFunctionError.md +283 -0
- package/docs/index/classes/LambdaService.md +95 -0
- package/docs/index/classes/S3Service.md +15 -15
- package/docs/index/classes/SNSService.md +4 -4
- package/docs/index/classes/SQSService.md +7 -7
- package/docs/index/classes/SSMService.md +33 -10
- package/docs/index/classes/SchedulerService.md +14 -13
- package/docs/index/classes/SecretsManagerService.md +8 -8
- package/docs/index/classes/StepFunctionsService.md +6 -6
- package/docs/index/interfaces/BatchFailedEntry.md +6 -5
- package/docs/index/interfaces/EmptyBucketPageResult.md +2 -2
- package/docs/index/modules.md +3 -0
- package/docs/testing/testing/functions/createMockService.md +1 -1
- package/esm/index.mjs +282 -12
- package/esm/package.json +3 -1
- package/esm/src/eventbridge/eventbridge.d.ts +58 -0
- package/esm/src/eventbridge/eventbridge.d.ts.map +1 -0
- package/esm/src/index.d.ts +3 -0
- package/esm/src/index.d.ts.map +1 -1
- package/esm/src/lambda/lambda.d.ts +54 -0
- package/esm/src/lambda/lambda.d.ts.map +1 -0
- package/esm/src/scheduler/scheduler.d.ts +3 -2
- package/esm/src/scheduler/scheduler.d.ts.map +1 -1
- package/esm/src/ssm/ssm.d.ts +18 -3
- package/esm/src/ssm/ssm.d.ts.map +1 -1
- package/esm/src/util/batch-operation-error.d.ts +13 -7
- package/esm/src/util/batch-operation-error.d.ts.map +1 -1
- package/esm/src/util/lambda-function-error.d.ts +36 -0
- package/esm/src/util/lambda-function-error.d.ts.map +1 -0
- package/package.json +3 -1
package/esm/index.mjs
CHANGED
|
@@ -4,6 +4,8 @@ import xray from 'aws-xray-sdk-core';
|
|
|
4
4
|
import { APIGatewayClient, paginateGetRestApis, paginateGetApiKeys, GetApiKeyCommand, paginateGetResources } from '@aws-sdk/client-api-gateway';
|
|
5
5
|
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
|
|
6
6
|
import { DynamoDBDocumentClient, GetCommand, PutCommand, UpdateCommand, DeleteCommand, QueryCommand, ScanCommand, BatchGetCommand, BatchWriteCommand, paginateQuery, paginateScan } from '@aws-sdk/lib-dynamodb';
|
|
7
|
+
import { EventBridgeClient, PutEventsCommand } from '@aws-sdk/client-eventbridge';
|
|
8
|
+
import { LambdaClient, InvokeCommand } from '@aws-sdk/client-lambda';
|
|
7
9
|
import { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand, CopyObjectCommand, paginateListObjectsV2, DeleteObjectCommand, DeleteObjectsCommand } from '@aws-sdk/client-s3';
|
|
8
10
|
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
|
|
9
11
|
import { SchedulerClient, CreateScheduleCommand, GetScheduleCommand, UpdateScheduleCommand, DeleteScheduleCommand, paginateListSchedules, CreateScheduleGroupCommand, GetScheduleGroupCommand, DeleteScheduleGroupCommand, paginateListScheduleGroups } from '@aws-sdk/client-scheduler';
|
|
@@ -517,7 +519,8 @@ class DynamoDBService {
|
|
|
517
519
|
*
|
|
518
520
|
* `results` holds the raw SDK output of every chunk, so the outputs of the
|
|
519
521
|
* entries that succeeded (message ids, sequence numbers) stay readable. The
|
|
520
|
-
*
|
|
522
|
+
* exceptions are `S3.emptyBucket`, whose `results` are per-page deleted keys,
|
|
523
|
+
* and `SSM.getParameters`, whose `results` are empty.
|
|
521
524
|
* `failed` is the normalised list of rejected entries across all chunks.
|
|
522
525
|
*
|
|
523
526
|
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
@@ -536,8 +539,7 @@ class BatchOperationError extends Error {
|
|
|
536
539
|
/**
|
|
537
540
|
* SQS and SNS report rejected entries under `Failed` on an otherwise
|
|
538
541
|
* successful response, so a resolved chunk does not mean every entry was
|
|
539
|
-
* accepted.
|
|
540
|
-
* and throws a {@link BatchOperationError}.
|
|
542
|
+
* accepted. Extracts those entries and delegates to {@link throwIfAny}.
|
|
541
543
|
*
|
|
542
544
|
* Only id, code and message are copied out — never the entry itself — so
|
|
543
545
|
* neither the error nor the warning can leak a payload.
|
|
@@ -564,9 +566,14 @@ function throwIfAnyDeleteErrors(logger, operation, results) {
|
|
|
564
566
|
return throwIfAny(logger, operation, results, failed);
|
|
565
567
|
}
|
|
566
568
|
/**
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
569
|
+
* Warn-and-throw step for services whose responses don't use the SQS/SNS
|
|
570
|
+
* `Failed` shape and so extract their own rejected entries (`EventBridge.putEvents`),
|
|
571
|
+
* or whose `results` aren't a plain list of SDK outputs (`S3.emptyBucket`).
|
|
572
|
+
* Returns `results` untouched when `failed` is empty.
|
|
573
|
+
*
|
|
574
|
+
* Callers must build `failed` by copying id, code and message explicitly —
|
|
575
|
+
* never by spreading the SDK entry — because it goes straight into the error
|
|
576
|
+
* and the warning.
|
|
570
577
|
*/
|
|
571
578
|
function throwIfAny(logger, operation, results, failed) {
|
|
572
579
|
if (failed.length === 0)
|
|
@@ -598,6 +605,235 @@ function chunk(items, size) {
|
|
|
598
605
|
return chunks;
|
|
599
606
|
}
|
|
600
607
|
|
|
608
|
+
const PUT_EVENTS_LIMIT = 10;
|
|
609
|
+
/**
|
|
610
|
+
* `Detail`, `Resources` and the entries themselves are payload carriers, so
|
|
611
|
+
* the INFO line carries only the endpoint id and how many entries were sent.
|
|
612
|
+
*/
|
|
613
|
+
function summariseEntries$1({ EndpointId, Entries }) {
|
|
614
|
+
return { EndpointId, entryCount: Entries?.length ?? 0 };
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Chunks are full except the last, so the caller's original index of a
|
|
618
|
+
* rejected entry is the chunk's offset (chunk number times the chunk size)
|
|
619
|
+
* plus its position within the chunk.
|
|
620
|
+
*/
|
|
621
|
+
function extractPutEventsFailures(results) {
|
|
622
|
+
return results.flatMap((result, chunkIndex) => extractChunkFailures(result, chunkIndex * PUT_EVENTS_LIMIT));
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* `PutEvents` reports a rejected entry by an error code on the result entry at
|
|
626
|
+
* the same position as the request entry.
|
|
627
|
+
*
|
|
628
|
+
* Copies only code and message out, never the request entry, so neither the
|
|
629
|
+
* error nor the warning can carry event detail.
|
|
630
|
+
*/
|
|
631
|
+
function extractChunkFailures(result, offset) {
|
|
632
|
+
return (result.Entries ?? [])
|
|
633
|
+
.map(({ ErrorCode, ErrorMessage }, position) => ({
|
|
634
|
+
id: String(offset + position),
|
|
635
|
+
code: ErrorCode,
|
|
636
|
+
message: ErrorMessage,
|
|
637
|
+
}))
|
|
638
|
+
.filter(({ code }) => code !== undefined);
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Wrapper around the AWS EventBridge client providing structured Powertools
|
|
642
|
+
* logging and X-Ray tracing by default.
|
|
643
|
+
*
|
|
644
|
+
* Where a method's input carries payloads, secret material or PII, the INFO
|
|
645
|
+
* log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
|
|
646
|
+
* `TRACE`) log full SDK inputs.
|
|
647
|
+
*
|
|
648
|
+
* Covers `putEvents` only. Named `EventBridgeService` for the event bus API;
|
|
649
|
+
* schedules live in `SchedulerService`.
|
|
650
|
+
*/
|
|
651
|
+
class EventBridgeService {
|
|
652
|
+
client;
|
|
653
|
+
logger;
|
|
654
|
+
/**
|
|
655
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
656
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
657
|
+
* @param opts.client - Optional pre-configured `EventBridgeClient`. When
|
|
658
|
+
* supplied, the wrapper does not apply X-Ray instrumentation.
|
|
659
|
+
*/
|
|
660
|
+
constructor(opts) {
|
|
661
|
+
this.client = opts?.client ?? xray.captureAWSv3Client(new EventBridgeClient());
|
|
662
|
+
this.logger = opts?.logger ?? new Logger();
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Publish events to an event bus. The EventBridge API caps `PutEvents` at
|
|
666
|
+
* 10 entries per request, so this method auto-chunks the caller's `Entries`
|
|
667
|
+
* and sends one request per chunk, returning the array of outputs. The
|
|
668
|
+
* remaining request fields (such as `EndpointId`) are carried onto every
|
|
669
|
+
* chunk.
|
|
670
|
+
*
|
|
671
|
+
* Chunking is by count only. The 256 KB request size limit is not enforced
|
|
672
|
+
* here: a chunk that exceeds it fails at the SDK as a request-level error.
|
|
673
|
+
*
|
|
674
|
+
* Every chunk is sent before the outcome is judged. If EventBridge rejected
|
|
675
|
+
* any entry (it reports an error code on the result entry), a
|
|
676
|
+
* {@link BatchOperationError} is then thrown carrying the per-chunk results
|
|
677
|
+
* and the failed entries. For this method each failed entry's `id` is
|
|
678
|
+
* always set, to the entry's index in the caller's original `Entries` list
|
|
679
|
+
* across all chunks, as a string. Only `id`, `code` and `message` are
|
|
680
|
+
* copied out, so event detail never reaches the error.
|
|
681
|
+
*
|
|
682
|
+
* No retries are performed. Request-level SDK exceptions (throttling,
|
|
683
|
+
* access denied, oversize request) are not wrapped: they propagate
|
|
684
|
+
* unchanged and immediately, so earlier chunks may already have been
|
|
685
|
+
* published.
|
|
686
|
+
*
|
|
687
|
+
* At INFO level the log line includes only the endpoint id and the entry
|
|
688
|
+
* count, because `Detail`, `Resources` and the entries themselves are
|
|
689
|
+
* payload carriers.
|
|
690
|
+
*
|
|
691
|
+
* @param input - PutEventsCommandInput including Entries.
|
|
692
|
+
*/
|
|
693
|
+
async putEvents(input) {
|
|
694
|
+
const entries = input.Entries ?? [];
|
|
695
|
+
this.logger.info('Putting EventBridge events', {
|
|
696
|
+
input: redactInput(this.logger, input, summariseEntries$1),
|
|
697
|
+
});
|
|
698
|
+
const results = [];
|
|
699
|
+
for (const batch of chunk(entries, PUT_EVENTS_LIMIT)) {
|
|
700
|
+
results.push(await this.client.send(new PutEventsCommand({ ...input, Entries: batch })));
|
|
701
|
+
}
|
|
702
|
+
return throwIfAny(this.logger, 'EventBridge putEvents', results, extractPutEventsFailures(results));
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Thrown by `LambdaService.invoke` when a synchronous invocation reached the
|
|
708
|
+
* function but the function itself failed. Lambda reports that as an HTTP 200
|
|
709
|
+
* carrying a function error marker, so the SDK does not throw.
|
|
710
|
+
*
|
|
711
|
+
* `functionError` is the SDK's marker (`Handled` or `Unhandled`).
|
|
712
|
+
* `errorType` and `errorMessage` are parsed from the response payload when it
|
|
713
|
+
* has the usual `{ errorType, errorMessage }` JSON shape, otherwise undefined.
|
|
714
|
+
*
|
|
715
|
+
* Deliberately excludes the raw SDK output and the stack trace: either can
|
|
716
|
+
* contain the caller's payload or PII.
|
|
717
|
+
*
|
|
718
|
+
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
719
|
+
* this package may be loaded in one process.
|
|
720
|
+
*/
|
|
721
|
+
class LambdaFunctionError extends Error {
|
|
722
|
+
functionName;
|
|
723
|
+
functionError;
|
|
724
|
+
name = 'LambdaFunctionError';
|
|
725
|
+
errorType;
|
|
726
|
+
errorMessage;
|
|
727
|
+
constructor(functionName, functionError, payload) {
|
|
728
|
+
super(`Lambda function ${functionName ?? '(unnamed)'} failed (${functionError})`);
|
|
729
|
+
this.functionName = functionName;
|
|
730
|
+
this.functionError = functionError;
|
|
731
|
+
this.errorType = payload.errorType;
|
|
732
|
+
this.errorMessage = payload.errorMessage;
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Reads `errorType` and `errorMessage` out of a function error payload.
|
|
737
|
+
* Anything that is not a JSON object with string fields yields undefined for
|
|
738
|
+
* that field rather than failing, because the payload is whatever the invoked
|
|
739
|
+
* function (or runtime) chose to return.
|
|
740
|
+
*/
|
|
741
|
+
function parseFunctionErrorPayload(payload) {
|
|
742
|
+
const empty = { errorType: undefined, errorMessage: undefined };
|
|
743
|
+
if (payload === undefined)
|
|
744
|
+
return empty;
|
|
745
|
+
let parsed;
|
|
746
|
+
try {
|
|
747
|
+
parsed = JSON.parse(new TextDecoder().decode(payload));
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
return empty;
|
|
751
|
+
}
|
|
752
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
753
|
+
return empty;
|
|
754
|
+
const { errorType, errorMessage } = parsed;
|
|
755
|
+
return {
|
|
756
|
+
errorType: typeof errorType === 'string' ? errorType : undefined,
|
|
757
|
+
errorMessage: typeof errorMessage === 'string' ? errorMessage : undefined,
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* `Invoke` inputs carry the invocation `Payload` and the base64 `ClientContext`
|
|
763
|
+
* handed to the function, both of which routinely contain caller data and PII.
|
|
764
|
+
* Everything else identifies the target or how to call it.
|
|
765
|
+
*/
|
|
766
|
+
const INVOKE_SAFE_FIELDS = [
|
|
767
|
+
'FunctionName',
|
|
768
|
+
'InvocationType',
|
|
769
|
+
'Qualifier',
|
|
770
|
+
'LogType',
|
|
771
|
+
'TenantId',
|
|
772
|
+
];
|
|
773
|
+
/**
|
|
774
|
+
* Wrapper around the AWS Lambda client providing structured Powertools logging
|
|
775
|
+
* and X-Ray tracing by default.
|
|
776
|
+
*
|
|
777
|
+
* Where a method's input carries payloads, secret material or PII, the INFO
|
|
778
|
+
* log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
|
|
779
|
+
* `TRACE`) log full SDK inputs.
|
|
780
|
+
*
|
|
781
|
+
* Covers `invoke` only.
|
|
782
|
+
*/
|
|
783
|
+
class LambdaService {
|
|
784
|
+
client;
|
|
785
|
+
logger;
|
|
786
|
+
/**
|
|
787
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
788
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
789
|
+
* @param opts.client - Optional pre-configured `LambdaClient`. When
|
|
790
|
+
* supplied, the wrapper does not apply X-Ray instrumentation.
|
|
791
|
+
*/
|
|
792
|
+
constructor(opts) {
|
|
793
|
+
this.client = opts?.client ?? xray.captureAWSv3Client(new LambdaClient());
|
|
794
|
+
this.logger = opts?.logger ?? new Logger();
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Invoke a Lambda function. The input is the SDK input unchanged and the
|
|
798
|
+
* output is the SDK output unchanged: `Payload` stays a `Uint8Array` you
|
|
799
|
+
* decode yourself. Choose synchronous, asynchronous or dry-run invocation
|
|
800
|
+
* with `InvocationType`; omitting it means synchronous (`RequestResponse`).
|
|
801
|
+
*
|
|
802
|
+
* Lambda answers HTTP 200 even when the invoked function threw, flagging it
|
|
803
|
+
* with `FunctionError` on the response. If that marker is present this
|
|
804
|
+
* method warns and throws a {@link LambdaFunctionError} carrying the
|
|
805
|
+
* function name, the marker, and the error type and message parsed from the
|
|
806
|
+
* payload when it has the usual JSON shape. The raw output and the stack
|
|
807
|
+
* trace are deliberately left off the error.
|
|
808
|
+
*
|
|
809
|
+
* The marker only appears on synchronous responses, so the check is
|
|
810
|
+
* unconditional: asynchronous (`Event`) and `DryRun` responses return
|
|
811
|
+
* without throwing. Failures of asynchronous invocations are therefore not
|
|
812
|
+
* observable here; they belong to dead-letter queues and destinations on
|
|
813
|
+
* the invoked function. No status code check is added; service-level
|
|
814
|
+
* errors such as throttling are thrown by the SDK and propagate unwrapped.
|
|
815
|
+
*
|
|
816
|
+
* At INFO level the log line includes only the function name, invocation
|
|
817
|
+
* type, qualifier, log type and tenant id. `Payload` and `ClientContext` are
|
|
818
|
+
* omitted, and responses are never logged.
|
|
819
|
+
*
|
|
820
|
+
* @param input - InvokeCommandInput including FunctionName.
|
|
821
|
+
*/
|
|
822
|
+
async invoke(input) {
|
|
823
|
+
this.logger.info('Invoking Lambda function', {
|
|
824
|
+
input: redactInput(this.logger, input, INVOKE_SAFE_FIELDS),
|
|
825
|
+
});
|
|
826
|
+
const output = await this.client.send(new InvokeCommand(input));
|
|
827
|
+
if (output.FunctionError === undefined)
|
|
828
|
+
return output;
|
|
829
|
+
this.logger.warn('Lambda invoke function error', {
|
|
830
|
+
functionName: input.FunctionName,
|
|
831
|
+
functionError: output.FunctionError,
|
|
832
|
+
});
|
|
833
|
+
throw new LambdaFunctionError(input.FunctionName, output.FunctionError, parseFunctionErrorPayload(output.Payload));
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
601
837
|
const DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
|
|
602
838
|
const DELETE_OBJECTS_BATCH_LIMIT = 1000;
|
|
603
839
|
/**
|
|
@@ -899,8 +1135,9 @@ function stripTargetInput(input) {
|
|
|
899
1135
|
* `TRACE`) log full SDK inputs.
|
|
900
1136
|
*
|
|
901
1137
|
* Covers CRUD on schedules and their groups. Named `SchedulerService` (not
|
|
902
|
-
* `EventBridgeSchedulerService`) so it doesn't collide with
|
|
903
|
-
* over the separate EventBridge bus/rules API
|
|
1138
|
+
* `EventBridgeSchedulerService`) so it doesn't collide with `EventBridgeService`,
|
|
1139
|
+
* the wrapper over the separate EventBridge bus/rules API
|
|
1140
|
+
* (`@aws-sdk/client-eventbridge`).
|
|
904
1141
|
*
|
|
905
1142
|
* `FlexibleTimeWindow` is required by `CreateSchedule` and is passed through
|
|
906
1143
|
* untouched — the wrapper bakes in no default, so the caller must state their
|
|
@@ -1521,6 +1758,19 @@ class SQSService {
|
|
|
1521
1758
|
}
|
|
1522
1759
|
|
|
1523
1760
|
const GET_PARAMETERS_LIMIT = 10;
|
|
1761
|
+
/**
|
|
1762
|
+
* One failed entry per alias whose path SSM reported as invalid, so two
|
|
1763
|
+
* aliases sharing a missing path are both named.
|
|
1764
|
+
*/
|
|
1765
|
+
function missingParameters(aliases, invalidPaths) {
|
|
1766
|
+
return Object.entries(aliases)
|
|
1767
|
+
.filter(([, path]) => invalidPaths.has(path))
|
|
1768
|
+
.map(([alias, path]) => ({
|
|
1769
|
+
id: path,
|
|
1770
|
+
code: 'ParameterNotFound',
|
|
1771
|
+
message: `Parameter not found for alias "${alias}"`,
|
|
1772
|
+
}));
|
|
1773
|
+
}
|
|
1524
1774
|
/**
|
|
1525
1775
|
* Fields safe to log at INFO level for `putParameter`. Omits `Value` (the
|
|
1526
1776
|
* parameter content itself).
|
|
@@ -1571,6 +1821,9 @@ class SSMService {
|
|
|
1571
1821
|
* @param name - The parameter name (or ARN).
|
|
1572
1822
|
* @returns The parameter value, or `undefined` if the parameter has no
|
|
1573
1823
|
* value set.
|
|
1824
|
+
* @throws When the parameter does not exist (the SDK's
|
|
1825
|
+
* `ParameterNotFound`). {@link SSMService.getParameters} instead returns
|
|
1826
|
+
* `undefined` for a missing parameter unless `required` is set.
|
|
1574
1827
|
*/
|
|
1575
1828
|
async getParameter(name) {
|
|
1576
1829
|
this.logger.info('Fetching SSM parameter', { input: { name } });
|
|
@@ -1595,16 +1848,27 @@ class SSMService {
|
|
|
1595
1848
|
* the underlying parameter names and sends one request per chunk,
|
|
1596
1849
|
* merging the results before building the alias-keyed return value.
|
|
1597
1850
|
*
|
|
1851
|
+
* Unlike {@link SSMService.getParameter}, which throws when the parameter
|
|
1852
|
+
* does not exist, a missing parameter here maps to `undefined` — so a
|
|
1853
|
+
* typo'd path surfaces later as an undefined value. Pass
|
|
1854
|
+
* `{ required: true }` to fail fast instead: every chunk is still sent,
|
|
1855
|
+
* then a {@link BatchOperationError} is thrown whose `failed` entries
|
|
1856
|
+
* carry each missing path as `id`, the code `ParameterNotFound`, and the
|
|
1857
|
+
* alias in `message`. Request-level SDK exceptions are not wrapped.
|
|
1858
|
+
*
|
|
1598
1859
|
* @param aliases - Record mapping each desired local alias to its SSM
|
|
1599
1860
|
* parameter name (or ARN).
|
|
1861
|
+
* @param opts.required - Throw when any requested parameter does not
|
|
1862
|
+
* exist. Defaults to `false`.
|
|
1600
1863
|
* @returns A record keyed by the same aliases, mapping each to the
|
|
1601
|
-
* parameter's value, or `undefined` when the parameter is missing
|
|
1602
|
-
* no value.
|
|
1864
|
+
* parameter's value, or `undefined` when the parameter is missing (unless
|
|
1865
|
+
* `required` is set) or has no value.
|
|
1603
1866
|
*/
|
|
1604
|
-
async getParameters(aliases) {
|
|
1867
|
+
async getParameters(aliases, opts) {
|
|
1605
1868
|
this.logger.info('Fetching SSM parameters', { input: { aliases } });
|
|
1606
1869
|
const names = Object.values(aliases);
|
|
1607
1870
|
const byPath = new Map();
|
|
1871
|
+
const invalidPaths = new Set();
|
|
1608
1872
|
for (const batch of chunk(names, GET_PARAMETERS_LIMIT)) {
|
|
1609
1873
|
const response = await this.client.send(new GetParametersCommand({
|
|
1610
1874
|
Names: batch,
|
|
@@ -1614,6 +1878,12 @@ class SSMService {
|
|
|
1614
1878
|
if (parameter.Name !== undefined)
|
|
1615
1879
|
byPath.set(parameter.Name, parameter.Value);
|
|
1616
1880
|
}
|
|
1881
|
+
for (const name of response.InvalidParameters ?? [])
|
|
1882
|
+
invalidPaths.add(name);
|
|
1883
|
+
}
|
|
1884
|
+
if (opts?.required) {
|
|
1885
|
+
// No per-chunk results: the SDK output of a failed lookup adds nothing
|
|
1886
|
+
throwIfAny(this.logger, 'SSM getParameters', [], missingParameters(aliases, invalidPaths));
|
|
1617
1887
|
}
|
|
1618
1888
|
const result = {};
|
|
1619
1889
|
for (const alias of Object.keys(aliases)) {
|
|
@@ -1665,4 +1935,4 @@ class SSMService {
|
|
|
1665
1935
|
}
|
|
1666
1936
|
}
|
|
1667
1937
|
|
|
1668
|
-
export { APIGatewayService, APIGatewayV2Service, BatchOperationError, DynamoDBService, S3Service, SNSService, SQSService, SSMService, SchedulerService, SecretsManagerService, StepFunctionsService };
|
|
1938
|
+
export { APIGatewayService, APIGatewayV2Service, BatchOperationError, DynamoDBService, EventBridgeService, LambdaFunctionError, LambdaService, S3Service, SNSService, SQSService, SSMService, SchedulerService, SecretsManagerService, StepFunctionsService };
|
package/esm/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aligent/aws-wrappers",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
4
4
|
"description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=18"
|
|
@@ -47,6 +47,8 @@
|
|
|
47
47
|
"@aws-sdk/client-api-gateway": "^3.1160.0",
|
|
48
48
|
"@aws-sdk/client-apigatewayv2": "^3.1160.0",
|
|
49
49
|
"@aws-sdk/client-dynamodb": "^3.1160.0",
|
|
50
|
+
"@aws-sdk/client-eventbridge": "^3.1160.0",
|
|
51
|
+
"@aws-sdk/client-lambda": "^3.1160.0",
|
|
50
52
|
"@aws-sdk/client-s3": "^3.1160.0",
|
|
51
53
|
"@aws-sdk/client-scheduler": "^3.1160.0",
|
|
52
54
|
"@aws-sdk/client-secrets-manager": "^3.1160.0",
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { EventBridgeClient, PutEventsCommandInput, PutEventsCommandOutput } from '@aws-sdk/client-eventbridge';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS EventBridge client providing structured Powertools
|
|
5
|
+
* logging and X-Ray tracing by default.
|
|
6
|
+
*
|
|
7
|
+
* Where a method's input carries payloads, secret material or PII, the INFO
|
|
8
|
+
* log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
|
|
9
|
+
* `TRACE`) log full SDK inputs.
|
|
10
|
+
*
|
|
11
|
+
* Covers `putEvents` only. Named `EventBridgeService` for the event bus API;
|
|
12
|
+
* schedules live in `SchedulerService`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class EventBridgeService {
|
|
15
|
+
private readonly client;
|
|
16
|
+
private readonly logger;
|
|
17
|
+
/**
|
|
18
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
19
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
20
|
+
* @param opts.client - Optional pre-configured `EventBridgeClient`. When
|
|
21
|
+
* supplied, the wrapper does not apply X-Ray instrumentation.
|
|
22
|
+
*/
|
|
23
|
+
constructor(opts?: {
|
|
24
|
+
logger?: LoggerInterface;
|
|
25
|
+
client?: EventBridgeClient;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Publish events to an event bus. The EventBridge API caps `PutEvents` at
|
|
29
|
+
* 10 entries per request, so this method auto-chunks the caller's `Entries`
|
|
30
|
+
* and sends one request per chunk, returning the array of outputs. The
|
|
31
|
+
* remaining request fields (such as `EndpointId`) are carried onto every
|
|
32
|
+
* chunk.
|
|
33
|
+
*
|
|
34
|
+
* Chunking is by count only. The 256 KB request size limit is not enforced
|
|
35
|
+
* here: a chunk that exceeds it fails at the SDK as a request-level error.
|
|
36
|
+
*
|
|
37
|
+
* Every chunk is sent before the outcome is judged. If EventBridge rejected
|
|
38
|
+
* any entry (it reports an error code on the result entry), a
|
|
39
|
+
* {@link BatchOperationError} is then thrown carrying the per-chunk results
|
|
40
|
+
* and the failed entries. For this method each failed entry's `id` is
|
|
41
|
+
* always set, to the entry's index in the caller's original `Entries` list
|
|
42
|
+
* across all chunks, as a string. Only `id`, `code` and `message` are
|
|
43
|
+
* copied out, so event detail never reaches the error.
|
|
44
|
+
*
|
|
45
|
+
* No retries are performed. Request-level SDK exceptions (throttling,
|
|
46
|
+
* access denied, oversize request) are not wrapped: they propagate
|
|
47
|
+
* unchanged and immediately, so earlier chunks may already have been
|
|
48
|
+
* published.
|
|
49
|
+
*
|
|
50
|
+
* At INFO level the log line includes only the endpoint id and the entry
|
|
51
|
+
* count, because `Detail`, `Resources` and the entries themselves are
|
|
52
|
+
* payload carriers.
|
|
53
|
+
*
|
|
54
|
+
* @param input - PutEventsCommandInput including Entries.
|
|
55
|
+
*/
|
|
56
|
+
putEvents(input: PutEventsCommandInput): Promise<PutEventsCommandOutput[]>;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=eventbridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventbridge.d.ts","sourceRoot":"","sources":["../../../../src/eventbridge/eventbridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EACH,iBAAiB,EAEjB,qBAAqB,EACrB,sBAAsB,EAEzB,MAAM,6BAA6B,CAAC;AA4CrC;;;;;;;;;;GAUG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC;;;;;OAKG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,MAAM,CAAC,EAAE,iBAAiB,CAAA;KAAE;IAK3E;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,SAAS,CAAC,KAAK,EAAE,qBAAqB,GAAG,OAAO,CAAC,sBAAsB,EAAE,CAAC;CAkBnF"}
|
package/esm/src/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { APIGatewayV2Service } from './api-gateway-v2/api-gateway-v2.js';
|
|
2
2
|
export { APIGatewayService } from './api-gateway/api-gateway.js';
|
|
3
3
|
export { DynamoDBService } from './dynamodb/dynamodb.js';
|
|
4
|
+
export { EventBridgeService } from './eventbridge/eventbridge.js';
|
|
5
|
+
export { LambdaService } from './lambda/lambda.js';
|
|
4
6
|
export { S3Service } from './s3/s3.js';
|
|
5
7
|
export type { EmptyBucketPageResult } from './s3/s3.js';
|
|
6
8
|
export { SchedulerService } from './scheduler/scheduler.js';
|
|
@@ -11,4 +13,5 @@ export { SQSService } from './sqs/sqs.js';
|
|
|
11
13
|
export { SSMService } from './ssm/ssm.js';
|
|
12
14
|
export { BatchOperationError } from './util/batch-operation-error.js';
|
|
13
15
|
export type { BatchFailedEntry } from './util/batch-operation-error.js';
|
|
16
|
+
export { LambdaFunctionError } from './util/lambda-function-error.js';
|
|
14
17
|
//# sourceMappingURL=index.d.ts.map
|
package/esm/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { InvokeCommandInput, InvokeCommandOutput, LambdaClient } from '@aws-sdk/client-lambda';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS Lambda client providing structured Powertools logging
|
|
5
|
+
* and X-Ray tracing by default.
|
|
6
|
+
*
|
|
7
|
+
* Where a method's input carries payloads, secret material or PII, the INFO
|
|
8
|
+
* log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
|
|
9
|
+
* `TRACE`) log full SDK inputs.
|
|
10
|
+
*
|
|
11
|
+
* Covers `invoke` only.
|
|
12
|
+
*/
|
|
13
|
+
export declare class LambdaService {
|
|
14
|
+
private readonly client;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
/**
|
|
17
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
18
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
19
|
+
* @param opts.client - Optional pre-configured `LambdaClient`. When
|
|
20
|
+
* supplied, the wrapper does not apply X-Ray instrumentation.
|
|
21
|
+
*/
|
|
22
|
+
constructor(opts?: {
|
|
23
|
+
logger?: LoggerInterface;
|
|
24
|
+
client?: LambdaClient;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Invoke a Lambda function. The input is the SDK input unchanged and the
|
|
28
|
+
* output is the SDK output unchanged: `Payload` stays a `Uint8Array` you
|
|
29
|
+
* decode yourself. Choose synchronous, asynchronous or dry-run invocation
|
|
30
|
+
* with `InvocationType`; omitting it means synchronous (`RequestResponse`).
|
|
31
|
+
*
|
|
32
|
+
* Lambda answers HTTP 200 even when the invoked function threw, flagging it
|
|
33
|
+
* with `FunctionError` on the response. If that marker is present this
|
|
34
|
+
* method warns and throws a {@link LambdaFunctionError} carrying the
|
|
35
|
+
* function name, the marker, and the error type and message parsed from the
|
|
36
|
+
* payload when it has the usual JSON shape. The raw output and the stack
|
|
37
|
+
* trace are deliberately left off the error.
|
|
38
|
+
*
|
|
39
|
+
* The marker only appears on synchronous responses, so the check is
|
|
40
|
+
* unconditional: asynchronous (`Event`) and `DryRun` responses return
|
|
41
|
+
* without throwing. Failures of asynchronous invocations are therefore not
|
|
42
|
+
* observable here; they belong to dead-letter queues and destinations on
|
|
43
|
+
* the invoked function. No status code check is added; service-level
|
|
44
|
+
* errors such as throttling are thrown by the SDK and propagate unwrapped.
|
|
45
|
+
*
|
|
46
|
+
* At INFO level the log line includes only the function name, invocation
|
|
47
|
+
* type, qualifier, log type and tenant id. `Payload` and `ClientContext` are
|
|
48
|
+
* omitted, and responses are never logged.
|
|
49
|
+
*
|
|
50
|
+
* @param input - InvokeCommandInput including FunctionName.
|
|
51
|
+
*/
|
|
52
|
+
invoke(input: InvokeCommandInput): Promise<InvokeCommandOutput>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=lambda.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambda.d.ts","sourceRoot":"","sources":["../../../../src/lambda/lambda.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAEH,kBAAkB,EAClB,mBAAmB,EACnB,YAAY,EACf,MAAM,wBAAwB,CAAC;AAkBhC;;;;;;;;;GASG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC;;;;;OAKG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,MAAM,CAAC,EAAE,YAAY,CAAA;KAAE;IAKtE;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,MAAM,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAiBxE"}
|
|
@@ -9,8 +9,9 @@ import { CreateScheduleCommandInput, CreateScheduleCommandOutput, CreateSchedule
|
|
|
9
9
|
* `TRACE`) log full SDK inputs.
|
|
10
10
|
*
|
|
11
11
|
* Covers CRUD on schedules and their groups. Named `SchedulerService` (not
|
|
12
|
-
* `EventBridgeSchedulerService`) so it doesn't collide with
|
|
13
|
-
* over the separate EventBridge bus/rules API
|
|
12
|
+
* `EventBridgeSchedulerService`) so it doesn't collide with `EventBridgeService`,
|
|
13
|
+
* the wrapper over the separate EventBridge bus/rules API
|
|
14
|
+
* (`@aws-sdk/client-eventbridge`).
|
|
14
15
|
*
|
|
15
16
|
* `FlexibleTimeWindow` is required by `CreateSchedule` and is passed through
|
|
16
17
|
* untouched — the wrapper bakes in no default, so the caller must state their
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../../src/scheduler/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAEH,0BAA0B,EAC1B,2BAA2B,EAE3B,+BAA+B,EAC/B,gCAAgC,EAEhC,0BAA0B,EAC1B,2BAA2B,EAE3B,+BAA+B,EAC/B,gCAAgC,EAEhC,uBAAuB,EACvB,wBAAwB,EAExB,4BAA4B,EAC5B,6BAA6B,EAC7B,8BAA8B,EAC9B,yBAAyB,EAGzB,oBAAoB,EACpB,eAAe,EACf,eAAe,EAGf,0BAA0B,EAC1B,2BAA2B,EAC9B,MAAM,2BAA2B,CAAC;AAwBnC
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../../src/scheduler/scheduler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAEH,0BAA0B,EAC1B,2BAA2B,EAE3B,+BAA+B,EAC/B,gCAAgC,EAEhC,0BAA0B,EAC1B,2BAA2B,EAE3B,+BAA+B,EAC/B,gCAAgC,EAEhC,uBAAuB,EACvB,wBAAwB,EAExB,4BAA4B,EAC5B,6BAA6B,EAC7B,8BAA8B,EAC9B,yBAAyB,EAGzB,oBAAoB,EACpB,eAAe,EACf,eAAe,EAGf,0BAA0B,EAC1B,2BAA2B,EAC9B,MAAM,2BAA2B,CAAC;AAwBnC;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC;;;;;OAKG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,MAAM,CAAC,EAAE,eAAe,CAAA;KAAE;IAKzE;;;OAGG;IACG,cAAc,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAO7F;;OAEG;IACG,WAAW,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAKpF;;;;;;;;;;;;OAYG;IACG,cAAc,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAO7F;;OAEG;IACG,cAAc,CAAC,KAAK,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAK7F;;;;OAIG;IACG,aAAa,CAAC,KAAK,CAAC,EAAE,yBAAyB,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAMlF;;;OAGG;IACG,mBAAmB,CACrB,KAAK,EAAE,+BAA+B,GACvC,OAAO,CAAC,gCAAgC,CAAC;IAK5C;;OAEG;IACG,gBAAgB,CAClB,KAAK,EAAE,4BAA4B,GACpC,OAAO,CAAC,6BAA6B,CAAC;IAKzC;;;;OAIG;IACG,mBAAmB,CACrB,KAAK,EAAE,+BAA+B,GACvC,OAAO,CAAC,gCAAgC,CAAC;IAK5C;;;OAGG;IACG,kBAAkB,CACpB,KAAK,CAAC,EAAE,8BAA8B,GACvC,OAAO,CAAC,oBAAoB,EAAE,CAAC;CAKrC"}
|
package/esm/src/ssm/ssm.d.ts
CHANGED
|
@@ -34,6 +34,9 @@ export declare class SSMService {
|
|
|
34
34
|
* @param name - The parameter name (or ARN).
|
|
35
35
|
* @returns The parameter value, or `undefined` if the parameter has no
|
|
36
36
|
* value set.
|
|
37
|
+
* @throws When the parameter does not exist (the SDK's
|
|
38
|
+
* `ParameterNotFound`). {@link SSMService.getParameters} instead returns
|
|
39
|
+
* `undefined` for a missing parameter unless `required` is set.
|
|
37
40
|
*/
|
|
38
41
|
getParameter(name: string): Promise<string | undefined>;
|
|
39
42
|
/**
|
|
@@ -54,13 +57,25 @@ export declare class SSMService {
|
|
|
54
57
|
* the underlying parameter names and sends one request per chunk,
|
|
55
58
|
* merging the results before building the alias-keyed return value.
|
|
56
59
|
*
|
|
60
|
+
* Unlike {@link SSMService.getParameter}, which throws when the parameter
|
|
61
|
+
* does not exist, a missing parameter here maps to `undefined` — so a
|
|
62
|
+
* typo'd path surfaces later as an undefined value. Pass
|
|
63
|
+
* `{ required: true }` to fail fast instead: every chunk is still sent,
|
|
64
|
+
* then a {@link BatchOperationError} is thrown whose `failed` entries
|
|
65
|
+
* carry each missing path as `id`, the code `ParameterNotFound`, and the
|
|
66
|
+
* alias in `message`. Request-level SDK exceptions are not wrapped.
|
|
67
|
+
*
|
|
57
68
|
* @param aliases - Record mapping each desired local alias to its SSM
|
|
58
69
|
* parameter name (or ARN).
|
|
70
|
+
* @param opts.required - Throw when any requested parameter does not
|
|
71
|
+
* exist. Defaults to `false`.
|
|
59
72
|
* @returns A record keyed by the same aliases, mapping each to the
|
|
60
|
-
* parameter's value, or `undefined` when the parameter is missing
|
|
61
|
-
* no value.
|
|
73
|
+
* parameter's value, or `undefined` when the parameter is missing (unless
|
|
74
|
+
* `required` is set) or has no value.
|
|
62
75
|
*/
|
|
63
|
-
getParameters<K extends string>(aliases: Record<K, string
|
|
76
|
+
getParameters<K extends string>(aliases: Record<K, string>, opts?: {
|
|
77
|
+
required?: boolean;
|
|
78
|
+
}): Promise<Record<K, string | undefined>>;
|
|
64
79
|
/**
|
|
65
80
|
* Create or update an SSM parameter. The log line omits `Value` to avoid
|
|
66
81
|
* leaking secret material.
|
package/esm/src/ssm/ssm.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssm.d.ts","sourceRoot":"","sources":["../../../../src/ssm/ssm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAKH,SAAS,EAET,wBAAwB,EACxB,yBAAyB,EACzB,SAAS,EACZ,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ssm.d.ts","sourceRoot":"","sources":["../../../../src/ssm/ssm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAKH,SAAS,EAET,wBAAwB,EACxB,yBAAyB,EACzB,SAAS,EACZ,MAAM,qBAAqB,CAAC;AA2C7B;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,UAAU;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC;;;;;OAKG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,MAAM,CAAC,EAAE,SAAS,CAAA;KAAE;IAKnE;;;;;;;;OAQG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAQ7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACG,aAAa,CAAC,CAAC,SAAS,MAAM,EAChC,OAAO,EAAE,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,EAC1B,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,GAC9B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAiCzC;;;;;;OAMG;IACG,YAAY,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAOvF;;;;;OAKG;IACG,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKlD;;;;;;;;;;OAUG;IACG,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CAWhG"}
|
|
@@ -2,7 +2,8 @@ import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* One entry a batch operation rejected. Deliberately limited to identifier,
|
|
4
4
|
* code and message so the error never carries message bodies, attributes or
|
|
5
|
-
* any other payload the caller sent. For S3 the identifier is the object key
|
|
5
|
+
* any other payload the caller sent. For S3 the identifier is the object key;
|
|
6
|
+
* for SSM it is the parameter path.
|
|
6
7
|
*/
|
|
7
8
|
export interface BatchFailedEntry {
|
|
8
9
|
id: string | undefined;
|
|
@@ -15,7 +16,8 @@ export interface BatchFailedEntry {
|
|
|
15
16
|
*
|
|
16
17
|
* `results` holds the raw SDK output of every chunk, so the outputs of the
|
|
17
18
|
* entries that succeeded (message ids, sequence numbers) stay readable. The
|
|
18
|
-
*
|
|
19
|
+
* exceptions are `S3.emptyBucket`, whose `results` are per-page deleted keys,
|
|
20
|
+
* and `SSM.getParameters`, whose `results` are empty.
|
|
19
21
|
* `failed` is the normalised list of rejected entries across all chunks.
|
|
20
22
|
*
|
|
21
23
|
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
@@ -38,8 +40,7 @@ interface RejectedEntry {
|
|
|
38
40
|
/**
|
|
39
41
|
* SQS and SNS report rejected entries under `Failed` on an otherwise
|
|
40
42
|
* successful response, so a resolved chunk does not mean every entry was
|
|
41
|
-
* accepted.
|
|
42
|
-
* and throws a {@link BatchOperationError}.
|
|
43
|
+
* accepted. Extracts those entries and delegates to {@link throwIfAny}.
|
|
43
44
|
*
|
|
44
45
|
* Only id, code and message are copied out — never the entry itself — so
|
|
45
46
|
* neither the error nor the warning can leak a payload.
|
|
@@ -64,9 +65,14 @@ export declare function throwIfAnyDeleteErrors<TResult extends {
|
|
|
64
65
|
Errors?: DeleteError[] | undefined;
|
|
65
66
|
}>(logger: LoggerInterface, operation: string, results: TResult[]): TResult[];
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
68
|
+
* Warn-and-throw step for services whose responses don't use the SQS/SNS
|
|
69
|
+
* `Failed` shape and so extract their own rejected entries (`EventBridge.putEvents`),
|
|
70
|
+
* or whose `results` aren't a plain list of SDK outputs (`S3.emptyBucket`).
|
|
71
|
+
* Returns `results` untouched when `failed` is empty.
|
|
72
|
+
*
|
|
73
|
+
* Callers must build `failed` by copying id, code and message explicitly —
|
|
74
|
+
* never by spreading the SDK entry — because it goes straight into the error
|
|
75
|
+
* and the warning.
|
|
70
76
|
*/
|
|
71
77
|
export declare function throwIfAny<TResult>(logger: LoggerInterface, operation: string, results: TResult[], failed: BatchFailedEntry[]): TResult[];
|
|
72
78
|
export {};
|