@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/README.md
CHANGED
|
@@ -27,9 +27,9 @@ Every wrapper emits one `logger.info` line per SDK call with a per-method safe-f
|
|
|
27
27
|
|
|
28
28
|
### Batch semantics
|
|
29
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`, `SNSService.publishBatch`, `S3Service.deleteObjects` and `
|
|
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`, `SNSService.publishBatch`, `EventBridgeService.putEvents`, `S3Service.deleteObjects`, `S3Service.emptyBucket` and, when `required` is set, `SSMService.getParameters`.
|
|
31
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
|
|
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 exactly what it did before.
|
|
33
33
|
|
|
34
34
|
```ts
|
|
35
35
|
import { BatchOperationError } from '@aligent/aws-wrappers';
|
|
@@ -39,6 +39,7 @@ try {
|
|
|
39
39
|
} catch (error) {
|
|
40
40
|
if (error instanceof BatchOperationError) {
|
|
41
41
|
// error.results — the raw SDK output of every chunk, including what succeeded
|
|
42
|
+
// (empty for SSM, per-page deleted keys for S3 emptyBucket)
|
|
42
43
|
// error.failed — [{ id, code, message }] for every rejected entry
|
|
43
44
|
const failedIds = new Set(error.failed.map(entry => entry.id));
|
|
44
45
|
await retry(entries.filter(entry => failedIds.has(entry.Id)));
|
|
@@ -48,7 +49,8 @@ try {
|
|
|
48
49
|
}
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
- `failed` carries only the entry identifier, error code and message — never message bodies, attributes or any other payload. For S3 the identifier is the object key.
|
|
52
|
+
- `failed` carries only the entry identifier, error code and message — never message bodies, attributes or any other payload. For S3 the identifier is the object key; for SSM it is the parameter path.
|
|
53
|
+
- `EventBridgeService.putEvents` entries have no identifier of their own, so for that method `id` is the entry's index in the `Entries` list you passed in, as a string.
|
|
52
54
|
- 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
55
|
- A warning is logged with the failure count and error codes, and no payload, at every log level.
|
|
54
56
|
- 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.
|
|
@@ -306,6 +308,81 @@ const groups = await scheduler.listScheduleGroups();
|
|
|
306
308
|
await scheduler.deleteScheduleGroup({ Name: 'integrations' });
|
|
307
309
|
```
|
|
308
310
|
|
|
311
|
+
## EventBridge
|
|
312
|
+
|
|
313
|
+
Publishes events to an event bus. `putEvents` takes the SDK input unchanged — `Detail` stays a JSON string you serialise yourself.
|
|
314
|
+
|
|
315
|
+
```ts
|
|
316
|
+
import { BatchOperationError, EventBridgeService } from '@aligent/aws-wrappers';
|
|
317
|
+
|
|
318
|
+
const eventBridge = new EventBridgeService();
|
|
319
|
+
|
|
320
|
+
// Auto-chunks Entries to the EventBridge-enforced 10-entry limit and throws a
|
|
321
|
+
// BatchOperationError if EventBridge rejects any entry — see "Batch semantics".
|
|
322
|
+
// Chunking is by count only: a chunk over the 256 KB request limit fails at the
|
|
323
|
+
// SDK as a request-level error.
|
|
324
|
+
try {
|
|
325
|
+
await eventBridge.putEvents({
|
|
326
|
+
Entries: orders.map(order => ({
|
|
327
|
+
Source: 'orders.service',
|
|
328
|
+
DetailType: 'OrderCreated',
|
|
329
|
+
Detail: JSON.stringify(order),
|
|
330
|
+
})),
|
|
331
|
+
});
|
|
332
|
+
} catch (error) {
|
|
333
|
+
if (error instanceof BatchOperationError) {
|
|
334
|
+
// failed[].id is the index in the Entries list you passed in, as a string.
|
|
335
|
+
const failedIndexes = new Set(error.failed.map(entry => Number(entry.id)));
|
|
336
|
+
await retry(orders.filter((_, index) => failedIndexes.has(index)));
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
throw error;
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
The wrapper does not retry. At INFO the log line shows only the endpoint id and the entry count, because `Detail` and `Resources` carry payloads.
|
|
344
|
+
|
|
345
|
+
## Lambda
|
|
346
|
+
|
|
347
|
+
Invokes another Lambda function. `invoke` takes the SDK input unchanged and returns the SDK output unchanged — `Payload` stays a `Uint8Array` you serialise and decode yourself. Choose sync, async or dry-run with `InvocationType`; omitting it means a synchronous call.
|
|
348
|
+
|
|
349
|
+
```ts
|
|
350
|
+
import { LambdaFunctionError, LambdaService } from '@aligent/aws-wrappers';
|
|
351
|
+
|
|
352
|
+
const lambda = new LambdaService();
|
|
353
|
+
|
|
354
|
+
// Lambda answers HTTP 200 even when the invoked function threw, flagging it with
|
|
355
|
+
// FunctionError on the response. invoke() turns that marker into a thrown
|
|
356
|
+
// LambdaFunctionError so a failed invocation can't be mistaken for a success.
|
|
357
|
+
try {
|
|
358
|
+
const { Payload } = await lambda.invoke({
|
|
359
|
+
FunctionName: 'pricing-service',
|
|
360
|
+
Payload: new TextEncoder().encode(JSON.stringify({ sku: 'ABC-123' })),
|
|
361
|
+
});
|
|
362
|
+
const price = JSON.parse(Payload?.transformToString() ?? 'null');
|
|
363
|
+
} catch (error) {
|
|
364
|
+
if (error instanceof LambdaFunctionError) {
|
|
365
|
+
// functionError is 'Handled' or 'Unhandled'; errorType and errorMessage are
|
|
366
|
+
// parsed from the function's error payload, or undefined if it isn't the usual shape.
|
|
367
|
+
console.error(error.functionName, error.functionError, error.errorType, error.errorMessage);
|
|
368
|
+
}
|
|
369
|
+
throw error;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Fire-and-forget: the response only confirms the request was accepted.
|
|
373
|
+
await lambda.invoke({
|
|
374
|
+
FunctionName: 'audit-writer',
|
|
375
|
+
InvocationType: 'Event',
|
|
376
|
+
Payload: new TextEncoder().encode(JSON.stringify(auditRecord)),
|
|
377
|
+
});
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
- `LambdaFunctionError` carries the function name, the SDK's function error value, and the error type and message parsed from the payload. It deliberately excludes the raw SDK output and the stack trace, because either can contain your payload or PII. A warning with only the function name and function error value is logged.
|
|
381
|
+
- The error has a stable `name` of `'LambdaFunctionError'`. If both the CJS and ESM builds of this package can be loaded in one process, check `error.name` instead of `instanceof`.
|
|
382
|
+
- The function error marker only appears on synchronous responses, so async (`Event`) and `DryRun` calls return without throwing. **Failures of asynchronous invocations are not observable by the wrapper** — configure a dead-letter queue or destination on the invoked function.
|
|
383
|
+
- Request-level SDK exceptions (throttling, access denied, network errors) are not wrapped and propagate unchanged.
|
|
384
|
+
- At INFO the log line shows only the function name, invocation type, qualifier, log type and tenant id. `Payload` and `ClientContext` are omitted, and responses are never logged.
|
|
385
|
+
|
|
309
386
|
## SSM Parameter Store
|
|
310
387
|
|
|
311
388
|
```ts
|
|
@@ -329,6 +406,15 @@ const params = await ssm.getParametersByPath('/myapp/');
|
|
|
329
406
|
const shallow = await ssm.getParametersByPath('/myapp/', { recursive: false });
|
|
330
407
|
```
|
|
331
408
|
|
|
409
|
+
`getParameter` throws when the parameter does not exist, but `getParameters` returns `undefined` for a missing one, so a typo'd path only surfaces later as an undefined value. Pass `required: true` to make `getParameters` fail fast instead. Every chunk is still sent, then a single `BatchOperationError` is thrown (see "Batch semantics") naming every missing parameter: `failed[].id` is the path, `failed[].code` is `ParameterNotFound` and `failed[].message` names the alias. `results` is empty, since there is nothing useful in the SDK output of a failed lookup.
|
|
410
|
+
|
|
411
|
+
```ts
|
|
412
|
+
const { host, port } = await ssm.getParameters(
|
|
413
|
+
{ host: '/myapp/host', port: '/myapp/port' },
|
|
414
|
+
{ required: true }
|
|
415
|
+
);
|
|
416
|
+
```
|
|
417
|
+
|
|
332
418
|
All read operations enable `WithDecryption` automatically — there's no opt-out. Callers needing plaintext should use `SSMClient` directly.
|
|
333
419
|
|
|
334
420
|
```ts
|
package/cjs/index.cjs
CHANGED
|
@@ -6,6 +6,8 @@ var xray = require('aws-xray-sdk-core');
|
|
|
6
6
|
var clientApiGateway = require('@aws-sdk/client-api-gateway');
|
|
7
7
|
var clientDynamodb = require('@aws-sdk/client-dynamodb');
|
|
8
8
|
var libDynamodb = require('@aws-sdk/lib-dynamodb');
|
|
9
|
+
var clientEventbridge = require('@aws-sdk/client-eventbridge');
|
|
10
|
+
var clientLambda = require('@aws-sdk/client-lambda');
|
|
9
11
|
var clientS3 = require('@aws-sdk/client-s3');
|
|
10
12
|
var s3RequestPresigner = require('@aws-sdk/s3-request-presigner');
|
|
11
13
|
var clientScheduler = require('@aws-sdk/client-scheduler');
|
|
@@ -519,7 +521,8 @@ class DynamoDBService {
|
|
|
519
521
|
*
|
|
520
522
|
* `results` holds the raw SDK output of every chunk, so the outputs of the
|
|
521
523
|
* entries that succeeded (message ids, sequence numbers) stay readable. The
|
|
522
|
-
*
|
|
524
|
+
* exceptions are `S3.emptyBucket`, whose `results` are per-page deleted keys,
|
|
525
|
+
* and `SSM.getParameters`, whose `results` are empty.
|
|
523
526
|
* `failed` is the normalised list of rejected entries across all chunks.
|
|
524
527
|
*
|
|
525
528
|
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
@@ -538,8 +541,7 @@ class BatchOperationError extends Error {
|
|
|
538
541
|
/**
|
|
539
542
|
* SQS and SNS report rejected entries under `Failed` on an otherwise
|
|
540
543
|
* successful response, so a resolved chunk does not mean every entry was
|
|
541
|
-
* accepted.
|
|
542
|
-
* and throws a {@link BatchOperationError}.
|
|
544
|
+
* accepted. Extracts those entries and delegates to {@link throwIfAny}.
|
|
543
545
|
*
|
|
544
546
|
* Only id, code and message are copied out — never the entry itself — so
|
|
545
547
|
* neither the error nor the warning can leak a payload.
|
|
@@ -566,9 +568,14 @@ function throwIfAnyDeleteErrors(logger, operation, results) {
|
|
|
566
568
|
return throwIfAny(logger, operation, results, failed);
|
|
567
569
|
}
|
|
568
570
|
/**
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
571
|
+
* Warn-and-throw step for services whose responses don't use the SQS/SNS
|
|
572
|
+
* `Failed` shape and so extract their own rejected entries (`EventBridge.putEvents`),
|
|
573
|
+
* or whose `results` aren't a plain list of SDK outputs (`S3.emptyBucket`).
|
|
574
|
+
* Returns `results` untouched when `failed` is empty.
|
|
575
|
+
*
|
|
576
|
+
* Callers must build `failed` by copying id, code and message explicitly —
|
|
577
|
+
* never by spreading the SDK entry — because it goes straight into the error
|
|
578
|
+
* and the warning.
|
|
572
579
|
*/
|
|
573
580
|
function throwIfAny(logger, operation, results, failed) {
|
|
574
581
|
if (failed.length === 0)
|
|
@@ -600,6 +607,235 @@ function chunk(items, size) {
|
|
|
600
607
|
return chunks;
|
|
601
608
|
}
|
|
602
609
|
|
|
610
|
+
const PUT_EVENTS_LIMIT = 10;
|
|
611
|
+
/**
|
|
612
|
+
* `Detail`, `Resources` and the entries themselves are payload carriers, so
|
|
613
|
+
* the INFO line carries only the endpoint id and how many entries were sent.
|
|
614
|
+
*/
|
|
615
|
+
function summariseEntries$1({ EndpointId, Entries }) {
|
|
616
|
+
return { EndpointId, entryCount: Entries?.length ?? 0 };
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* Chunks are full except the last, so the caller's original index of a
|
|
620
|
+
* rejected entry is the chunk's offset (chunk number times the chunk size)
|
|
621
|
+
* plus its position within the chunk.
|
|
622
|
+
*/
|
|
623
|
+
function extractPutEventsFailures(results) {
|
|
624
|
+
return results.flatMap((result, chunkIndex) => extractChunkFailures(result, chunkIndex * PUT_EVENTS_LIMIT));
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* `PutEvents` reports a rejected entry by an error code on the result entry at
|
|
628
|
+
* the same position as the request entry.
|
|
629
|
+
*
|
|
630
|
+
* Copies only code and message out, never the request entry, so neither the
|
|
631
|
+
* error nor the warning can carry event detail.
|
|
632
|
+
*/
|
|
633
|
+
function extractChunkFailures(result, offset) {
|
|
634
|
+
return (result.Entries ?? [])
|
|
635
|
+
.map(({ ErrorCode, ErrorMessage }, position) => ({
|
|
636
|
+
id: String(offset + position),
|
|
637
|
+
code: ErrorCode,
|
|
638
|
+
message: ErrorMessage,
|
|
639
|
+
}))
|
|
640
|
+
.filter(({ code }) => code !== undefined);
|
|
641
|
+
}
|
|
642
|
+
/**
|
|
643
|
+
* Wrapper around the AWS EventBridge client providing structured Powertools
|
|
644
|
+
* logging and X-Ray tracing by default.
|
|
645
|
+
*
|
|
646
|
+
* Where a method's input carries payloads, secret material or PII, the INFO
|
|
647
|
+
* log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
|
|
648
|
+
* `TRACE`) log full SDK inputs.
|
|
649
|
+
*
|
|
650
|
+
* Covers `putEvents` only. Named `EventBridgeService` for the event bus API;
|
|
651
|
+
* schedules live in `SchedulerService`.
|
|
652
|
+
*/
|
|
653
|
+
class EventBridgeService {
|
|
654
|
+
client;
|
|
655
|
+
logger;
|
|
656
|
+
/**
|
|
657
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
658
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
659
|
+
* @param opts.client - Optional pre-configured `EventBridgeClient`. When
|
|
660
|
+
* supplied, the wrapper does not apply X-Ray instrumentation.
|
|
661
|
+
*/
|
|
662
|
+
constructor(opts) {
|
|
663
|
+
this.client = opts?.client ?? xray.captureAWSv3Client(new clientEventbridge.EventBridgeClient());
|
|
664
|
+
this.logger = opts?.logger ?? new logger.Logger();
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Publish events to an event bus. The EventBridge API caps `PutEvents` at
|
|
668
|
+
* 10 entries per request, so this method auto-chunks the caller's `Entries`
|
|
669
|
+
* and sends one request per chunk, returning the array of outputs. The
|
|
670
|
+
* remaining request fields (such as `EndpointId`) are carried onto every
|
|
671
|
+
* chunk.
|
|
672
|
+
*
|
|
673
|
+
* Chunking is by count only. The 256 KB request size limit is not enforced
|
|
674
|
+
* here: a chunk that exceeds it fails at the SDK as a request-level error.
|
|
675
|
+
*
|
|
676
|
+
* Every chunk is sent before the outcome is judged. If EventBridge rejected
|
|
677
|
+
* any entry (it reports an error code on the result entry), a
|
|
678
|
+
* {@link BatchOperationError} is then thrown carrying the per-chunk results
|
|
679
|
+
* and the failed entries. For this method each failed entry's `id` is
|
|
680
|
+
* always set, to the entry's index in the caller's original `Entries` list
|
|
681
|
+
* across all chunks, as a string. Only `id`, `code` and `message` are
|
|
682
|
+
* copied out, so event detail never reaches the error.
|
|
683
|
+
*
|
|
684
|
+
* No retries are performed. Request-level SDK exceptions (throttling,
|
|
685
|
+
* access denied, oversize request) are not wrapped: they propagate
|
|
686
|
+
* unchanged and immediately, so earlier chunks may already have been
|
|
687
|
+
* published.
|
|
688
|
+
*
|
|
689
|
+
* At INFO level the log line includes only the endpoint id and the entry
|
|
690
|
+
* count, because `Detail`, `Resources` and the entries themselves are
|
|
691
|
+
* payload carriers.
|
|
692
|
+
*
|
|
693
|
+
* @param input - PutEventsCommandInput including Entries.
|
|
694
|
+
*/
|
|
695
|
+
async putEvents(input) {
|
|
696
|
+
const entries = input.Entries ?? [];
|
|
697
|
+
this.logger.info('Putting EventBridge events', {
|
|
698
|
+
input: redactInput(this.logger, input, summariseEntries$1),
|
|
699
|
+
});
|
|
700
|
+
const results = [];
|
|
701
|
+
for (const batch of chunk(entries, PUT_EVENTS_LIMIT)) {
|
|
702
|
+
results.push(await this.client.send(new clientEventbridge.PutEventsCommand({ ...input, Entries: batch })));
|
|
703
|
+
}
|
|
704
|
+
return throwIfAny(this.logger, 'EventBridge putEvents', results, extractPutEventsFailures(results));
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Thrown by `LambdaService.invoke` when a synchronous invocation reached the
|
|
710
|
+
* function but the function itself failed. Lambda reports that as an HTTP 200
|
|
711
|
+
* carrying a function error marker, so the SDK does not throw.
|
|
712
|
+
*
|
|
713
|
+
* `functionError` is the SDK's marker (`Handled` or `Unhandled`).
|
|
714
|
+
* `errorType` and `errorMessage` are parsed from the response payload when it
|
|
715
|
+
* has the usual `{ errorType, errorMessage }` JSON shape, otherwise undefined.
|
|
716
|
+
*
|
|
717
|
+
* Deliberately excludes the raw SDK output and the stack trace: either can
|
|
718
|
+
* contain the caller's payload or PII.
|
|
719
|
+
*
|
|
720
|
+
* Match on `name` rather than `instanceof` if both the CJS and ESM builds of
|
|
721
|
+
* this package may be loaded in one process.
|
|
722
|
+
*/
|
|
723
|
+
class LambdaFunctionError extends Error {
|
|
724
|
+
functionName;
|
|
725
|
+
functionError;
|
|
726
|
+
name = 'LambdaFunctionError';
|
|
727
|
+
errorType;
|
|
728
|
+
errorMessage;
|
|
729
|
+
constructor(functionName, functionError, payload) {
|
|
730
|
+
super(`Lambda function ${functionName ?? '(unnamed)'} failed (${functionError})`);
|
|
731
|
+
this.functionName = functionName;
|
|
732
|
+
this.functionError = functionError;
|
|
733
|
+
this.errorType = payload.errorType;
|
|
734
|
+
this.errorMessage = payload.errorMessage;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Reads `errorType` and `errorMessage` out of a function error payload.
|
|
739
|
+
* Anything that is not a JSON object with string fields yields undefined for
|
|
740
|
+
* that field rather than failing, because the payload is whatever the invoked
|
|
741
|
+
* function (or runtime) chose to return.
|
|
742
|
+
*/
|
|
743
|
+
function parseFunctionErrorPayload(payload) {
|
|
744
|
+
const empty = { errorType: undefined, errorMessage: undefined };
|
|
745
|
+
if (payload === undefined)
|
|
746
|
+
return empty;
|
|
747
|
+
let parsed;
|
|
748
|
+
try {
|
|
749
|
+
parsed = JSON.parse(new TextDecoder().decode(payload));
|
|
750
|
+
}
|
|
751
|
+
catch {
|
|
752
|
+
return empty;
|
|
753
|
+
}
|
|
754
|
+
if (typeof parsed !== 'object' || parsed === null)
|
|
755
|
+
return empty;
|
|
756
|
+
const { errorType, errorMessage } = parsed;
|
|
757
|
+
return {
|
|
758
|
+
errorType: typeof errorType === 'string' ? errorType : undefined,
|
|
759
|
+
errorMessage: typeof errorMessage === 'string' ? errorMessage : undefined,
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
/**
|
|
764
|
+
* `Invoke` inputs carry the invocation `Payload` and the base64 `ClientContext`
|
|
765
|
+
* handed to the function, both of which routinely contain caller data and PII.
|
|
766
|
+
* Everything else identifies the target or how to call it.
|
|
767
|
+
*/
|
|
768
|
+
const INVOKE_SAFE_FIELDS = [
|
|
769
|
+
'FunctionName',
|
|
770
|
+
'InvocationType',
|
|
771
|
+
'Qualifier',
|
|
772
|
+
'LogType',
|
|
773
|
+
'TenantId',
|
|
774
|
+
];
|
|
775
|
+
/**
|
|
776
|
+
* Wrapper around the AWS Lambda client providing structured Powertools logging
|
|
777
|
+
* and X-Ray tracing by default.
|
|
778
|
+
*
|
|
779
|
+
* Where a method's input carries payloads, secret material or PII, the INFO
|
|
780
|
+
* log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
|
|
781
|
+
* `TRACE`) log full SDK inputs.
|
|
782
|
+
*
|
|
783
|
+
* Covers `invoke` only.
|
|
784
|
+
*/
|
|
785
|
+
class LambdaService {
|
|
786
|
+
client;
|
|
787
|
+
logger;
|
|
788
|
+
/**
|
|
789
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
790
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
791
|
+
* @param opts.client - Optional pre-configured `LambdaClient`. When
|
|
792
|
+
* supplied, the wrapper does not apply X-Ray instrumentation.
|
|
793
|
+
*/
|
|
794
|
+
constructor(opts) {
|
|
795
|
+
this.client = opts?.client ?? xray.captureAWSv3Client(new clientLambda.LambdaClient());
|
|
796
|
+
this.logger = opts?.logger ?? new logger.Logger();
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Invoke a Lambda function. The input is the SDK input unchanged and the
|
|
800
|
+
* output is the SDK output unchanged: `Payload` stays a `Uint8Array` you
|
|
801
|
+
* decode yourself. Choose synchronous, asynchronous or dry-run invocation
|
|
802
|
+
* with `InvocationType`; omitting it means synchronous (`RequestResponse`).
|
|
803
|
+
*
|
|
804
|
+
* Lambda answers HTTP 200 even when the invoked function threw, flagging it
|
|
805
|
+
* with `FunctionError` on the response. If that marker is present this
|
|
806
|
+
* method warns and throws a {@link LambdaFunctionError} carrying the
|
|
807
|
+
* function name, the marker, and the error type and message parsed from the
|
|
808
|
+
* payload when it has the usual JSON shape. The raw output and the stack
|
|
809
|
+
* trace are deliberately left off the error.
|
|
810
|
+
*
|
|
811
|
+
* The marker only appears on synchronous responses, so the check is
|
|
812
|
+
* unconditional: asynchronous (`Event`) and `DryRun` responses return
|
|
813
|
+
* without throwing. Failures of asynchronous invocations are therefore not
|
|
814
|
+
* observable here; they belong to dead-letter queues and destinations on
|
|
815
|
+
* the invoked function. No status code check is added; service-level
|
|
816
|
+
* errors such as throttling are thrown by the SDK and propagate unwrapped.
|
|
817
|
+
*
|
|
818
|
+
* At INFO level the log line includes only the function name, invocation
|
|
819
|
+
* type, qualifier, log type and tenant id. `Payload` and `ClientContext` are
|
|
820
|
+
* omitted, and responses are never logged.
|
|
821
|
+
*
|
|
822
|
+
* @param input - InvokeCommandInput including FunctionName.
|
|
823
|
+
*/
|
|
824
|
+
async invoke(input) {
|
|
825
|
+
this.logger.info('Invoking Lambda function', {
|
|
826
|
+
input: redactInput(this.logger, input, INVOKE_SAFE_FIELDS),
|
|
827
|
+
});
|
|
828
|
+
const output = await this.client.send(new clientLambda.InvokeCommand(input));
|
|
829
|
+
if (output.FunctionError === undefined)
|
|
830
|
+
return output;
|
|
831
|
+
this.logger.warn('Lambda invoke function error', {
|
|
832
|
+
functionName: input.FunctionName,
|
|
833
|
+
functionError: output.FunctionError,
|
|
834
|
+
});
|
|
835
|
+
throw new LambdaFunctionError(input.FunctionName, output.FunctionError, parseFunctionErrorPayload(output.Payload));
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
603
839
|
const DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
|
|
604
840
|
const DELETE_OBJECTS_BATCH_LIMIT = 1000;
|
|
605
841
|
/**
|
|
@@ -901,8 +1137,9 @@ function stripTargetInput(input) {
|
|
|
901
1137
|
* `TRACE`) log full SDK inputs.
|
|
902
1138
|
*
|
|
903
1139
|
* Covers CRUD on schedules and their groups. Named `SchedulerService` (not
|
|
904
|
-
* `EventBridgeSchedulerService`) so it doesn't collide with
|
|
905
|
-
* over the separate EventBridge bus/rules API
|
|
1140
|
+
* `EventBridgeSchedulerService`) so it doesn't collide with `EventBridgeService`,
|
|
1141
|
+
* the wrapper over the separate EventBridge bus/rules API
|
|
1142
|
+
* (`@aws-sdk/client-eventbridge`).
|
|
906
1143
|
*
|
|
907
1144
|
* `FlexibleTimeWindow` is required by `CreateSchedule` and is passed through
|
|
908
1145
|
* untouched — the wrapper bakes in no default, so the caller must state their
|
|
@@ -1523,6 +1760,19 @@ class SQSService {
|
|
|
1523
1760
|
}
|
|
1524
1761
|
|
|
1525
1762
|
const GET_PARAMETERS_LIMIT = 10;
|
|
1763
|
+
/**
|
|
1764
|
+
* One failed entry per alias whose path SSM reported as invalid, so two
|
|
1765
|
+
* aliases sharing a missing path are both named.
|
|
1766
|
+
*/
|
|
1767
|
+
function missingParameters(aliases, invalidPaths) {
|
|
1768
|
+
return Object.entries(aliases)
|
|
1769
|
+
.filter(([, path]) => invalidPaths.has(path))
|
|
1770
|
+
.map(([alias, path]) => ({
|
|
1771
|
+
id: path,
|
|
1772
|
+
code: 'ParameterNotFound',
|
|
1773
|
+
message: `Parameter not found for alias "${alias}"`,
|
|
1774
|
+
}));
|
|
1775
|
+
}
|
|
1526
1776
|
/**
|
|
1527
1777
|
* Fields safe to log at INFO level for `putParameter`. Omits `Value` (the
|
|
1528
1778
|
* parameter content itself).
|
|
@@ -1573,6 +1823,9 @@ class SSMService {
|
|
|
1573
1823
|
* @param name - The parameter name (or ARN).
|
|
1574
1824
|
* @returns The parameter value, or `undefined` if the parameter has no
|
|
1575
1825
|
* value set.
|
|
1826
|
+
* @throws When the parameter does not exist (the SDK's
|
|
1827
|
+
* `ParameterNotFound`). {@link SSMService.getParameters} instead returns
|
|
1828
|
+
* `undefined` for a missing parameter unless `required` is set.
|
|
1576
1829
|
*/
|
|
1577
1830
|
async getParameter(name) {
|
|
1578
1831
|
this.logger.info('Fetching SSM parameter', { input: { name } });
|
|
@@ -1597,16 +1850,27 @@ class SSMService {
|
|
|
1597
1850
|
* the underlying parameter names and sends one request per chunk,
|
|
1598
1851
|
* merging the results before building the alias-keyed return value.
|
|
1599
1852
|
*
|
|
1853
|
+
* Unlike {@link SSMService.getParameter}, which throws when the parameter
|
|
1854
|
+
* does not exist, a missing parameter here maps to `undefined` — so a
|
|
1855
|
+
* typo'd path surfaces later as an undefined value. Pass
|
|
1856
|
+
* `{ required: true }` to fail fast instead: every chunk is still sent,
|
|
1857
|
+
* then a {@link BatchOperationError} is thrown whose `failed` entries
|
|
1858
|
+
* carry each missing path as `id`, the code `ParameterNotFound`, and the
|
|
1859
|
+
* alias in `message`. Request-level SDK exceptions are not wrapped.
|
|
1860
|
+
*
|
|
1600
1861
|
* @param aliases - Record mapping each desired local alias to its SSM
|
|
1601
1862
|
* parameter name (or ARN).
|
|
1863
|
+
* @param opts.required - Throw when any requested parameter does not
|
|
1864
|
+
* exist. Defaults to `false`.
|
|
1602
1865
|
* @returns A record keyed by the same aliases, mapping each to the
|
|
1603
|
-
* parameter's value, or `undefined` when the parameter is missing
|
|
1604
|
-
* no value.
|
|
1866
|
+
* parameter's value, or `undefined` when the parameter is missing (unless
|
|
1867
|
+
* `required` is set) or has no value.
|
|
1605
1868
|
*/
|
|
1606
|
-
async getParameters(aliases) {
|
|
1869
|
+
async getParameters(aliases, opts) {
|
|
1607
1870
|
this.logger.info('Fetching SSM parameters', { input: { aliases } });
|
|
1608
1871
|
const names = Object.values(aliases);
|
|
1609
1872
|
const byPath = new Map();
|
|
1873
|
+
const invalidPaths = new Set();
|
|
1610
1874
|
for (const batch of chunk(names, GET_PARAMETERS_LIMIT)) {
|
|
1611
1875
|
const response = await this.client.send(new clientSsm.GetParametersCommand({
|
|
1612
1876
|
Names: batch,
|
|
@@ -1616,6 +1880,12 @@ class SSMService {
|
|
|
1616
1880
|
if (parameter.Name !== undefined)
|
|
1617
1881
|
byPath.set(parameter.Name, parameter.Value);
|
|
1618
1882
|
}
|
|
1883
|
+
for (const name of response.InvalidParameters ?? [])
|
|
1884
|
+
invalidPaths.add(name);
|
|
1885
|
+
}
|
|
1886
|
+
if (opts?.required) {
|
|
1887
|
+
// No per-chunk results: the SDK output of a failed lookup adds nothing
|
|
1888
|
+
throwIfAny(this.logger, 'SSM getParameters', [], missingParameters(aliases, invalidPaths));
|
|
1619
1889
|
}
|
|
1620
1890
|
const result = {};
|
|
1621
1891
|
for (const alias of Object.keys(aliases)) {
|
|
@@ -1671,6 +1941,9 @@ exports.APIGatewayService = APIGatewayService;
|
|
|
1671
1941
|
exports.APIGatewayV2Service = APIGatewayV2Service;
|
|
1672
1942
|
exports.BatchOperationError = BatchOperationError;
|
|
1673
1943
|
exports.DynamoDBService = DynamoDBService;
|
|
1944
|
+
exports.EventBridgeService = EventBridgeService;
|
|
1945
|
+
exports.LambdaFunctionError = LambdaFunctionError;
|
|
1946
|
+
exports.LambdaService = LambdaService;
|
|
1674
1947
|
exports.S3Service = S3Service;
|
|
1675
1948
|
exports.SNSService = SNSService;
|
|
1676
1949
|
exports.SQSService = SQSService;
|
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.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/cjs/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/cjs/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"}
|