@aligent/aws-wrappers 0.5.4 → 0.5.6

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.
Files changed (58) hide show
  1. package/README.md +57 -2
  2. package/cjs/index.cjs +226 -48
  3. package/cjs/package.json +3 -1
  4. package/cjs/src/api-gateway/api-gateway.d.ts +45 -0
  5. package/cjs/src/api-gateway/api-gateway.d.ts.map +1 -0
  6. package/cjs/src/api-gateway-v2/api-gateway-v2.d.ts +39 -0
  7. package/cjs/src/api-gateway-v2/api-gateway-v2.d.ts.map +1 -0
  8. package/cjs/src/index.d.ts +4 -0
  9. package/cjs/src/index.d.ts.map +1 -1
  10. package/cjs/src/s3/s3.d.ts.map +1 -1
  11. package/cjs/src/scheduler/scheduler.d.ts.map +1 -1
  12. package/cjs/src/sfn/sfn.d.ts.map +1 -1
  13. package/cjs/src/sns/sns.d.ts.map +1 -1
  14. package/cjs/src/sqs/sqs.d.ts +20 -0
  15. package/cjs/src/sqs/sqs.d.ts.map +1 -1
  16. package/cjs/src/ssm/ssm.d.ts.map +1 -1
  17. package/cjs/src/util/batch-operation-error.d.ts +33 -0
  18. package/cjs/src/util/batch-operation-error.d.ts.map +1 -0
  19. package/cjs/src/util/chunk.d.ts +6 -0
  20. package/cjs/src/util/chunk.d.ts.map +1 -0
  21. package/cjs/src/util/pagination.d.ts +12 -0
  22. package/cjs/src/util/pagination.d.ts.map +1 -0
  23. package/docs/index/classes/APIGatewayService.md +143 -0
  24. package/docs/index/classes/APIGatewayV2Service.md +119 -0
  25. package/docs/index/classes/BatchOperationError.md +261 -0
  26. package/docs/index/classes/DynamoDBService.md +12 -12
  27. package/docs/index/classes/S3Service.md +15 -15
  28. package/docs/index/classes/SNSService.md +4 -4
  29. package/docs/index/classes/SQSService.md +20 -7
  30. package/docs/index/classes/SSMService.md +7 -7
  31. package/docs/index/classes/SchedulerService.md +11 -11
  32. package/docs/index/classes/SecretsManagerService.md +8 -8
  33. package/docs/index/classes/StepFunctionsService.md +6 -6
  34. package/docs/index/interfaces/BatchFailedEntry.md +43 -0
  35. package/docs/index/modules.md +7 -0
  36. package/docs/testing/testing/functions/createMockService.md +1 -1
  37. package/esm/index.mjs +225 -50
  38. package/esm/package.json +3 -1
  39. package/esm/src/api-gateway/api-gateway.d.ts +45 -0
  40. package/esm/src/api-gateway/api-gateway.d.ts.map +1 -0
  41. package/esm/src/api-gateway-v2/api-gateway-v2.d.ts +39 -0
  42. package/esm/src/api-gateway-v2/api-gateway-v2.d.ts.map +1 -0
  43. package/esm/src/index.d.ts +4 -0
  44. package/esm/src/index.d.ts.map +1 -1
  45. package/esm/src/s3/s3.d.ts.map +1 -1
  46. package/esm/src/scheduler/scheduler.d.ts.map +1 -1
  47. package/esm/src/sfn/sfn.d.ts.map +1 -1
  48. package/esm/src/sns/sns.d.ts.map +1 -1
  49. package/esm/src/sqs/sqs.d.ts +20 -0
  50. package/esm/src/sqs/sqs.d.ts.map +1 -1
  51. package/esm/src/ssm/ssm.d.ts.map +1 -1
  52. package/esm/src/util/batch-operation-error.d.ts +33 -0
  53. package/esm/src/util/batch-operation-error.d.ts.map +1 -0
  54. package/esm/src/util/chunk.d.ts +6 -0
  55. package/esm/src/util/chunk.d.ts.map +1 -0
  56. package/esm/src/util/pagination.d.ts +12 -0
  57. package/esm/src/util/pagination.d.ts.map +1 -0
  58. package/package.json +3 -1
@@ -6,7 +6,7 @@
6
6
 
7
7
  # Class: StepFunctionsService
8
8
 
9
- Defined in: [sfn/sfn.ts:40](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/sfn/sfn.ts#L40)
9
+ Defined in: [packages/aws-wrappers/src/sfn/sfn.ts:41](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/sfn/sfn.ts#L41)
10
10
 
11
11
  Wrapper around the AWS Step Functions client providing structured
12
12
  Powertools logging and X-Ray tracing by default.
@@ -23,7 +23,7 @@ log line omits them; the verbose levels (`POWERTOOLS_LOG_LEVEL=DEBUG` or
23
23
 
24
24
  > **new StepFunctionsService**(`opts?`): `StepFunctionsService`
25
25
 
26
- Defined in: [sfn/sfn.ts:50](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/sfn/sfn.ts#L50)
26
+ Defined in: [packages/aws-wrappers/src/sfn/sfn.ts:51](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/sfn/sfn.ts#L51)
27
27
 
28
28
  #### Parameters
29
29
 
@@ -55,7 +55,7 @@ which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
55
55
 
56
56
  > **describeExecution**(`input`): `Promise`\<`DescribeExecutionCommandOutput`\>
57
57
 
58
- Defined in: [sfn/sfn.ts:83](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/sfn/sfn.ts#L83)
58
+ Defined in: [packages/aws-wrappers/src/sfn/sfn.ts:80](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/sfn/sfn.ts#L80)
59
59
 
60
60
  Describe an existing Step Functions execution.
61
61
 
@@ -77,7 +77,7 @@ Describe an existing Step Functions execution.
77
77
 
78
78
  > **listExecutions**(`input`): `Promise`\<`ExecutionListItem`[]\>
79
79
 
80
- Defined in: [sfn/sfn.ts:60](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/sfn/sfn.ts#L60)
80
+ Defined in: [packages/aws-wrappers/src/sfn/sfn.ts:61](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/sfn/sfn.ts#L61)
81
81
 
82
82
  List all executions for a state machine, auto-paginating across all
83
83
  pages. Typically bounded by `statusFilter` and state-machine retention,
@@ -101,7 +101,7 @@ so the flat-array shape is safe in practice.
101
101
 
102
102
  > **startExecution**(`input`): `Promise`\<`StartExecutionCommandOutput`\>
103
103
 
104
- Defined in: [sfn/sfn.ts:73](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/sfn/sfn.ts#L73)
104
+ Defined in: [packages/aws-wrappers/src/sfn/sfn.ts:70](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/sfn/sfn.ts#L70)
105
105
 
106
106
  Start a new Step Functions execution.
107
107
 
@@ -123,7 +123,7 @@ Start a new Step Functions execution.
123
123
 
124
124
  > **stopExecution**(`input`): `Promise`\<`StopExecutionCommandOutput`\>
125
125
 
126
- Defined in: [sfn/sfn.ts:93](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/sfn/sfn.ts#L93)
126
+ Defined in: [packages/aws-wrappers/src/sfn/sfn.ts:90](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/sfn/sfn.ts#L90)
127
127
 
128
128
  Stop an in-progress Step Functions execution.
129
129
 
@@ -0,0 +1,43 @@
1
+ [**@aligent/aws-wrappers**](../../modules.md)
2
+
3
+ ***
4
+
5
+ [@aligent/aws-wrappers](../../modules.md) / [index](../modules.md) / BatchFailedEntry
6
+
7
+ # Interface: BatchFailedEntry
8
+
9
+ Defined in: [packages/aws-wrappers/src/util/batch-operation-error.ts:6](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/util/batch-operation-error.ts#L6)
10
+
11
+ One entry a batch operation rejected. Deliberately limited to identifier,
12
+ code and message so the error never carries message bodies, attributes or
13
+ any other payload the caller sent.
14
+
15
+ ## Properties
16
+
17
+ <a id="code"></a>
18
+
19
+ ### code
20
+
21
+ > **code**: `string` \| `undefined`
22
+
23
+ Defined in: [packages/aws-wrappers/src/util/batch-operation-error.ts:8](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/util/batch-operation-error.ts#L8)
24
+
25
+ ***
26
+
27
+ <a id="id"></a>
28
+
29
+ ### id
30
+
31
+ > **id**: `string` \| `undefined`
32
+
33
+ Defined in: [packages/aws-wrappers/src/util/batch-operation-error.ts:7](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/util/batch-operation-error.ts#L7)
34
+
35
+ ***
36
+
37
+ <a id="message"></a>
38
+
39
+ ### message
40
+
41
+ > **message**: `string` \| `undefined`
42
+
43
+ Defined in: [packages/aws-wrappers/src/util/batch-operation-error.ts:9](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/util/batch-operation-error.ts#L9)
@@ -8,6 +8,9 @@
8
8
 
9
9
  ## Classes
10
10
 
11
+ - [APIGatewayService](classes/APIGatewayService.md)
12
+ - [APIGatewayV2Service](classes/APIGatewayV2Service.md)
13
+ - [BatchOperationError](classes/BatchOperationError.md)
11
14
  - [DynamoDBService](classes/DynamoDBService.md)
12
15
  - [S3Service](classes/S3Service.md)
13
16
  - [SchedulerService](classes/SchedulerService.md)
@@ -16,3 +19,7 @@
16
19
  - [SQSService](classes/SQSService.md)
17
20
  - [SSMService](classes/SSMService.md)
18
21
  - [StepFunctionsService](classes/StepFunctionsService.md)
22
+
23
+ ## Interfaces
24
+
25
+ - [BatchFailedEntry](interfaces/BatchFailedEntry.md)
@@ -8,7 +8,7 @@
8
8
 
9
9
  > **createMockService**\<`T`, `O`\>(`service`, `overrides`): `T` & `O`
10
10
 
11
- Defined in: [testing/testing.ts:66](https://github.com/aligent/microservice-development-utilities/blob/208162b51bc413ae3185eb1c132d9faf5fac8079/packages/aws-wrappers/src/testing/testing.ts#L66)
11
+ Defined in: [packages/aws-wrappers/src/testing/testing.ts:66](https://github.com/aligent/microservice-development-utilities/blob/36323d6a14efbe8673c2a1e7e5c4b742c6b4220a/packages/aws-wrappers/src/testing/testing.ts#L66)
12
12
 
13
13
  Build a stand-in for a service class from an object of method overrides, for
14
14
  use in unit tests of code that depends on the service.
package/esm/index.mjs CHANGED
@@ -1,7 +1,9 @@
1
- import { LogLevelThreshold, Logger } from '@aws-lambda-powertools/logger';
1
+ import { Logger, LogLevelThreshold } from '@aws-lambda-powertools/logger';
2
+ import { ApiGatewayV2Client, GetRouteCommand, GetApisCommand, GetRoutesCommand } from '@aws-sdk/client-apigatewayv2';
3
+ import xray from 'aws-xray-sdk-core';
4
+ import { APIGatewayClient, paginateGetRestApis, paginateGetApiKeys, GetApiKeyCommand, paginateGetResources } from '@aws-sdk/client-api-gateway';
2
5
  import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
3
6
  import { DynamoDBDocumentClient, GetCommand, PutCommand, UpdateCommand, DeleteCommand, QueryCommand, ScanCommand, BatchGetCommand, BatchWriteCommand, paginateQuery, paginateScan } from '@aws-sdk/lib-dynamodb';
4
- import xray from 'aws-xray-sdk-core';
5
7
  import { S3Client, PutObjectCommand, GetObjectCommand, HeadObjectCommand, CopyObjectCommand, paginateListObjectsV2, DeleteObjectCommand, DeleteObjectsCommand } from '@aws-sdk/client-s3';
6
8
  import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
7
9
  import { SchedulerClient, CreateScheduleCommand, GetScheduleCommand, UpdateScheduleCommand, DeleteScheduleCommand, paginateListSchedules, CreateScheduleGroupCommand, GetScheduleGroupCommand, DeleteScheduleGroupCommand, paginateListScheduleGroups } from '@aws-sdk/client-scheduler';
@@ -11,6 +13,134 @@ import { SNSClient, PublishCommand, PublishBatchCommand } from '@aws-sdk/client-
11
13
  import { SQSClient, SendMessageCommand, ReceiveMessageCommand, DeleteMessageCommand, SendMessageBatchCommand, DeleteMessageBatchCommand } from '@aws-sdk/client-sqs';
12
14
  import { SSMClient, GetParameterCommand, GetParametersCommand, PutParameterCommand, DeleteParameterCommand, paginateGetParametersByPath } from '@aws-sdk/client-ssm';
13
15
 
16
+ /**
17
+ * Flatten the items of every page of an SDK paginator (`paginateXxx`).
18
+ * `getItems` picks the data-bearing field, which differs per operation.
19
+ */
20
+ async function collectItems(pages, getItems) {
21
+ const items = [];
22
+ for await (const page of pages) {
23
+ items.push(...(getItems(page) ?? []));
24
+ }
25
+ return items;
26
+ }
27
+ /**
28
+ * Flatten the items of every page of an operation the SDK ships no paginator
29
+ * for, following its continuation token until the response stops returning one.
30
+ * `fetchPage` receives `undefined` on the first call.
31
+ */
32
+ async function collectPages(fetchPage, getItems, getNextToken) {
33
+ const items = [];
34
+ let token;
35
+ do {
36
+ const page = await fetchPage(token);
37
+ items.push(...(getItems(page) ?? []));
38
+ token = getNextToken(page);
39
+ } while (token);
40
+ return items;
41
+ }
42
+
43
+ /**
44
+ * Read-only wrapper around the API Gateway v2 (HTTP and WebSocket APIs)
45
+ * control-plane client providing structured Powertools logging and X-Ray
46
+ * tracing by default.
47
+ *
48
+ * The v2 SDK ships no paginators for `GetApis` or `GetRoutes`, so list methods
49
+ * follow `NextToken` manually.
50
+ */
51
+ class APIGatewayV2Service {
52
+ client;
53
+ logger;
54
+ /**
55
+ * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
56
+ * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
57
+ * @param opts.client - Optional pre-configured `ApiGatewayV2Client`. When
58
+ * supplied, the wrapper does not apply X-Ray instrumentation.
59
+ */
60
+ constructor(opts) {
61
+ this.client = opts?.client ?? xray.captureAWSv3Client(new ApiGatewayV2Client());
62
+ this.logger = opts?.logger ?? new Logger();
63
+ }
64
+ /**
65
+ * List every HTTP and WebSocket API in the account and region.
66
+ * Auto-paginated.
67
+ */
68
+ async getApis(input = {}) {
69
+ this.logger.info('Fetching APIs', { input });
70
+ return collectPages(NextToken => this.client.send(new GetApisCommand({ ...input, NextToken })), page => page.Items, page => page.NextToken);
71
+ }
72
+ /**
73
+ * Fetch a single route of an HTTP or WebSocket API.
74
+ * @throws NotFoundException when the route does not exist.
75
+ */
76
+ async getRoute(input) {
77
+ this.logger.info('Fetching API route', { input });
78
+ return this.client.send(new GetRouteCommand(input));
79
+ }
80
+ /**
81
+ * List every route of an HTTP or WebSocket API. Auto-paginated.
82
+ */
83
+ async getRoutes(input) {
84
+ this.logger.info('Fetching API routes', { input });
85
+ return collectPages(NextToken => this.client.send(new GetRoutesCommand({ ...input, NextToken })), page => page.Items, page => page.NextToken);
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Read-only wrapper around the API Gateway (REST API, v1) control-plane client
91
+ * providing structured Powertools logging and X-Ray tracing by default.
92
+ *
93
+ * `getApiKeys` and `getApiKey` always request key values (`includeValues` /
94
+ * `includeValue` is `true`, with no opt-out) — callers needing metadata only
95
+ * should use `APIGatewayClient` directly. Key values appear only in method
96
+ * output; the wrapper never logs output, and no input carries secrets.
97
+ */
98
+ class APIGatewayService {
99
+ client;
100
+ logger;
101
+ /**
102
+ * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
103
+ * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
104
+ * @param opts.client - Optional pre-configured `APIGatewayClient`. When
105
+ * supplied, the wrapper does not apply X-Ray instrumentation.
106
+ */
107
+ constructor(opts) {
108
+ this.client = opts?.client ?? xray.captureAWSv3Client(new APIGatewayClient());
109
+ this.logger = opts?.logger ?? new Logger();
110
+ }
111
+ /**
112
+ * List every REST API in the account and region. Auto-paginated.
113
+ */
114
+ async getRestApis(input = {}) {
115
+ this.logger.info('Fetching REST APIs', { input });
116
+ return collectItems(paginateGetRestApis({ client: this.client }, input), page => page.items);
117
+ }
118
+ /**
119
+ * List API keys, including their secret values. Auto-paginated.
120
+ */
121
+ async getApiKeys(input = {}) {
122
+ this.logger.info('Fetching API keys', { input });
123
+ return collectItems(paginateGetApiKeys({ client: this.client }, { ...input, includeValues: true }), page => page.items);
124
+ }
125
+ /**
126
+ * Fetch a single API key, including its secret value.
127
+ * @throws NotFoundException when the key does not exist.
128
+ */
129
+ async getApiKey(input) {
130
+ this.logger.info('Fetching API key', { input });
131
+ return this.client.send(new GetApiKeyCommand({ ...input, includeValue: true }));
132
+ }
133
+ /**
134
+ * List every resource (path) of a REST API, which is how REST APIs expose
135
+ * their routes. Pass `embed: ['methods']` to include each resource's
136
+ * methods. Auto-paginated.
137
+ */
138
+ async getResources(input) {
139
+ this.logger.info('Fetching REST API resources', { input });
140
+ return collectItems(paginateGetResources({ client: this.client }, input), page => page.items);
141
+ }
142
+ }
143
+
14
144
  /**
15
145
  * Whether the logger is verbose enough that full SDK inputs — payloads, secret
16
146
  * material and PII — may be written to the log.
@@ -399,6 +529,18 @@ class DynamoDBService {
399
529
  }
400
530
  }
401
531
 
532
+ /**
533
+ * Split a list into consecutive chunks of at most `size` items, mirroring the
534
+ * per-request caps the AWS APIs enforce on batch operations.
535
+ */
536
+ function chunk(items, size) {
537
+ const chunks = [];
538
+ for (let i = 0; i < items.length; i += size) {
539
+ chunks.push(items.slice(i, i + size));
540
+ }
541
+ return chunks;
542
+ }
543
+
402
544
  const DEFAULT_PRESIGNED_URL_EXPIRES_IN_SECONDS = 3600;
403
545
  const DELETE_OBJECTS_BATCH_LIMIT = 1000;
404
546
  /**
@@ -524,14 +666,8 @@ class S3Service {
524
666
  async listObjects(bucket, prefix) {
525
667
  this.logger.info('Listing S3 objects', { input: { bucket, prefix } });
526
668
  const paginator = paginateListObjectsV2({ client: this.client }, { Bucket: bucket, Prefix: prefix });
527
- const keys = [];
528
- for await (const page of paginator) {
529
- for (const object of page.Contents ?? []) {
530
- if (object.Key)
531
- keys.push(object.Key);
532
- }
533
- }
534
- return keys;
669
+ const objects = await collectItems(paginator, page => page.Contents);
670
+ return objects.flatMap(object => (object.Key ? [object.Key] : []));
535
671
  }
536
672
  /**
537
673
  * List and JSON-parse every object under a bucket and optional prefix.
@@ -607,8 +743,7 @@ class S3Service {
607
743
  input: logFullInput ? { bucket, keys } : { bucket, keyCount: keys.length },
608
744
  });
609
745
  const results = [];
610
- for (let i = 0; i < keys.length; i += DELETE_OBJECTS_BATCH_LIMIT) {
611
- const batch = keys.slice(i, i + DELETE_OBJECTS_BATCH_LIMIT);
746
+ for (const batch of chunk(keys, DELETE_OBJECTS_BATCH_LIMIT)) {
612
747
  results.push(await this.client.send(new DeleteObjectsCommand({
613
748
  Bucket: bucket,
614
749
  Delete: { Objects: batch.map(Key => ({ Key })) },
@@ -750,12 +885,7 @@ class SchedulerService {
750
885
  async listSchedules(input) {
751
886
  this.logger.info('Listing schedules', { input });
752
887
  const paginator = paginateListSchedules({ client: this.client }, input ?? {});
753
- const schedules = [];
754
- for await (const page of paginator) {
755
- if (page.Schedules)
756
- schedules.push(...page.Schedules);
757
- }
758
- return schedules;
888
+ return collectItems(paginator, page => page.Schedules);
759
889
  }
760
890
  /**
761
891
  * Create a new schedule group. Groups are containers for schedules and are
@@ -788,12 +918,7 @@ class SchedulerService {
788
918
  async listScheduleGroups(input) {
789
919
  this.logger.info('Listing schedule groups', { input });
790
920
  const paginator = paginateListScheduleGroups({ client: this.client }, input ?? {});
791
- const groups = [];
792
- for await (const page of paginator) {
793
- if (page.ScheduleGroups)
794
- groups.push(...page.ScheduleGroups);
795
- }
796
- return groups;
921
+ return collectItems(paginator, page => page.ScheduleGroups);
797
922
  }
798
923
  }
799
924
 
@@ -981,12 +1106,7 @@ class StepFunctionsService {
981
1106
  async listExecutions(input) {
982
1107
  this.logger.info('Listing Step Functions executions', { input });
983
1108
  const paginator = paginateListExecutions({ client: this.client }, input);
984
- const executions = [];
985
- for await (const page of paginator) {
986
- if (page.executions)
987
- executions.push(...page.executions);
988
- }
989
- return executions;
1109
+ return collectItems(paginator, page => page.executions);
990
1110
  }
991
1111
  /**
992
1112
  * Start a new Step Functions execution.
@@ -1152,17 +1272,46 @@ class SNSService {
1152
1272
  input: logFullInput ? input : { TopicArn: input.TopicArn, entryCount: entries.length },
1153
1273
  });
1154
1274
  const results = [];
1155
- for (let i = 0; i < entries.length; i += PUBLISH_BATCH_LIMIT) {
1156
- const chunk = entries.slice(i, i + PUBLISH_BATCH_LIMIT);
1275
+ for (const batch of chunk(entries, PUBLISH_BATCH_LIMIT)) {
1157
1276
  results.push(await this.client.send(new PublishBatchCommand({
1158
1277
  ...input,
1159
- PublishBatchRequestEntries: chunk,
1278
+ PublishBatchRequestEntries: batch,
1160
1279
  })));
1161
1280
  }
1162
1281
  return results;
1163
1282
  }
1164
1283
  }
1165
1284
 
1285
+ /**
1286
+ * Thrown by the batch methods once every chunk has been sent and at least one
1287
+ * entry was rejected.
1288
+ *
1289
+ * `results` holds the raw SDK output of every chunk, so the outputs of the
1290
+ * entries that succeeded (message ids, sequence numbers) stay readable.
1291
+ * `failed` is the normalised list of rejected entries across all chunks.
1292
+ *
1293
+ * Match on `name` rather than `instanceof` if both the CJS and ESM builds of
1294
+ * this package may be loaded in one process.
1295
+ */
1296
+ class BatchOperationError extends Error {
1297
+ results;
1298
+ failed;
1299
+ name = 'BatchOperationError';
1300
+ constructor(results, failed) {
1301
+ super(`Batch operation failed for ${failed.length} entries (${distinctCodes(failed).join(', ')})`);
1302
+ this.results = results;
1303
+ this.failed = failed;
1304
+ }
1305
+ }
1306
+ /**
1307
+ * Distinct error codes in first-seen order, for the error message and the
1308
+ * warning log line.
1309
+ */
1310
+ function distinctCodes(failed) {
1311
+ const codes = failed.flatMap(entry => (entry.code === undefined ? [] : [entry.code]));
1312
+ return [...new Set(codes)];
1313
+ }
1314
+
1166
1315
  const SQS_BATCH_LIMIT = 10;
1167
1316
  const SQS_MESSAGE_BODY_MAX_BYTES = 256 * 1024;
1168
1317
  /**
@@ -1256,10 +1405,36 @@ class SQSService {
1256
1405
  this.logger.info('Deleting SQS message', { input });
1257
1406
  return this.client.send(new DeleteMessageCommand(input));
1258
1407
  }
1408
+ /**
1409
+ * SQS reports rejected entries under `Failed` on an otherwise successful
1410
+ * response, so a resolved chunk does not mean every entry was accepted.
1411
+ * Only id, code and message are copied out — never the entry itself — so
1412
+ * neither the error nor the warning can leak a payload.
1413
+ */
1414
+ throwIfAnyFailed(operation, results) {
1415
+ const failed = results.flatMap(result => (result.Failed ?? []).map(({ Id, Code, Message }) => ({
1416
+ id: Id,
1417
+ code: Code,
1418
+ message: Message,
1419
+ })));
1420
+ if (failed.length === 0)
1421
+ return results;
1422
+ this.logger.warn(`${operation} had rejected entries`, {
1423
+ failedCount: failed.length,
1424
+ codes: distinctCodes(failed),
1425
+ });
1426
+ throw new BatchOperationError(results, failed);
1427
+ }
1259
1428
  /**
1260
1429
  * Send a batch of messages to an SQS queue. The SQS API caps
1261
1430
  * SendMessageBatch at 10 entries per request, so this method auto-chunks
1262
1431
  * the caller's entries and sends one request per chunk.
1432
+ *
1433
+ * Every chunk is sent before the outcome is judged. If SQS rejected any
1434
+ * entry, a {@link BatchOperationError} is then thrown carrying the
1435
+ * per-chunk results and the failed entries. Request-level SDK exceptions
1436
+ * (throttling, access denied) propagate unchanged and immediately, so
1437
+ * earlier chunks may already have been sent.
1263
1438
  */
1264
1439
  async sendMessageBatch(input) {
1265
1440
  const entries = input.Entries ?? [];
@@ -1271,16 +1446,22 @@ class SQSService {
1271
1446
  input: logFullInput ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1272
1447
  });
1273
1448
  const results = [];
1274
- for (let i = 0; i < entries.length; i += SQS_BATCH_LIMIT) {
1275
- const chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
1276
- results.push(await this.client.send(new SendMessageBatchCommand({ ...input, Entries: chunk })));
1449
+ for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
1450
+ results.push(await this.client.send(new SendMessageBatchCommand({ ...input, Entries: batch })));
1277
1451
  }
1278
- return results;
1452
+ return this.throwIfAnyFailed('SQS sendMessageBatch', results);
1279
1453
  }
1280
1454
  /**
1281
1455
  * Delete a batch of messages from an SQS queue. The SQS API caps
1282
1456
  * DeleteMessageBatch at 10 entries per request, so this method auto-chunks
1283
1457
  * the caller's entries and sends one request per chunk.
1458
+ *
1459
+ * Every chunk is sent before the outcome is judged. If SQS failed to
1460
+ * delete any message, a {@link BatchOperationError} is then thrown carrying
1461
+ * the per-chunk results and the failed entries; those messages will be
1462
+ * redelivered. Request-level SDK exceptions (throttling, access denied)
1463
+ * propagate unchanged and immediately, so earlier chunks may already have
1464
+ * been deleted.
1284
1465
  */
1285
1466
  async deleteMessageBatch(input) {
1286
1467
  const entries = input.Entries ?? [];
@@ -1292,11 +1473,10 @@ class SQSService {
1292
1473
  input: logFullInput ? input : { QueueUrl: input.QueueUrl, entryCount: entries.length },
1293
1474
  });
1294
1475
  const results = [];
1295
- for (let i = 0; i < entries.length; i += SQS_BATCH_LIMIT) {
1296
- const chunk = entries.slice(i, i + SQS_BATCH_LIMIT);
1297
- results.push(await this.client.send(new DeleteMessageBatchCommand({ ...input, Entries: chunk })));
1476
+ for (const batch of chunk(entries, SQS_BATCH_LIMIT)) {
1477
+ results.push(await this.client.send(new DeleteMessageBatchCommand({ ...input, Entries: batch })));
1298
1478
  }
1299
- return results;
1479
+ return this.throwIfAnyFailed('SQS deleteMessageBatch', results);
1300
1480
  }
1301
1481
  }
1302
1482
 
@@ -1385,10 +1565,9 @@ class SSMService {
1385
1565
  this.logger.info('Fetching SSM parameters', { input: { aliases } });
1386
1566
  const names = Object.values(aliases);
1387
1567
  const byPath = new Map();
1388
- for (let i = 0; i < names.length; i += GET_PARAMETERS_LIMIT) {
1389
- const chunk = names.slice(i, i + GET_PARAMETERS_LIMIT);
1568
+ for (const batch of chunk(names, GET_PARAMETERS_LIMIT)) {
1390
1569
  const response = await this.client.send(new GetParametersCommand({
1391
- Names: chunk,
1570
+ Names: batch,
1392
1571
  WithDecryption: true,
1393
1572
  }));
1394
1573
  for (const parameter of response.Parameters ?? []) {
@@ -1442,12 +1621,8 @@ class SSMService {
1442
1621
  input: { path, recursive },
1443
1622
  });
1444
1623
  const paginator = paginateGetParametersByPath({ client: this.client }, { Path: path, Recursive: recursive, WithDecryption: true });
1445
- const parameters = [];
1446
- for await (const page of paginator) {
1447
- parameters.push(...(page.Parameters ?? []));
1448
- }
1449
- return parameters;
1624
+ return collectItems(paginator, page => page.Parameters);
1450
1625
  }
1451
1626
  }
1452
1627
 
1453
- export { DynamoDBService, S3Service, SNSService, SQSService, SSMService, SchedulerService, SecretsManagerService, StepFunctionsService };
1628
+ export { APIGatewayService, APIGatewayV2Service, BatchOperationError, DynamoDBService, 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.4",
3
+ "version": "0.5.6",
4
4
  "description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
5
5
  "engines": {
6
6
  "node": ">=18"
@@ -44,6 +44,8 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@aws-lambda-powertools/logger": "^2.33.1",
47
+ "@aws-sdk/client-api-gateway": "^3.1127.0",
48
+ "@aws-sdk/client-apigatewayv2": "^3.1127.0",
47
49
  "@aws-sdk/client-dynamodb": "^3.1127.0",
48
50
  "@aws-sdk/client-s3": "^3.1127.0",
49
51
  "@aws-sdk/client-scheduler": "^3.1127.0",
@@ -0,0 +1,45 @@
1
+ import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
2
+ import { APIGatewayClient, ApiKey, GetApiKeyCommandInput, GetApiKeyCommandOutput, GetApiKeysCommandInput, GetResourcesCommandInput, GetRestApisCommandInput, Resource, RestApi } from '@aws-sdk/client-api-gateway';
3
+ /**
4
+ * Read-only wrapper around the API Gateway (REST API, v1) control-plane client
5
+ * providing structured Powertools logging and X-Ray tracing by default.
6
+ *
7
+ * `getApiKeys` and `getApiKey` always request key values (`includeValues` /
8
+ * `includeValue` is `true`, with no opt-out) — callers needing metadata only
9
+ * should use `APIGatewayClient` directly. Key values appear only in method
10
+ * output; the wrapper never logs output, and no input carries secrets.
11
+ */
12
+ export declare class APIGatewayService {
13
+ private readonly client;
14
+ private readonly logger;
15
+ /**
16
+ * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
17
+ * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
18
+ * @param opts.client - Optional pre-configured `APIGatewayClient`. When
19
+ * supplied, the wrapper does not apply X-Ray instrumentation.
20
+ */
21
+ constructor(opts?: {
22
+ logger?: LoggerInterface;
23
+ client?: APIGatewayClient;
24
+ });
25
+ /**
26
+ * List every REST API in the account and region. Auto-paginated.
27
+ */
28
+ getRestApis(input?: GetRestApisCommandInput): Promise<RestApi[]>;
29
+ /**
30
+ * List API keys, including their secret values. Auto-paginated.
31
+ */
32
+ getApiKeys(input?: Omit<GetApiKeysCommandInput, 'includeValues'>): Promise<ApiKey[]>;
33
+ /**
34
+ * Fetch a single API key, including its secret value.
35
+ * @throws NotFoundException when the key does not exist.
36
+ */
37
+ getApiKey(input: Omit<GetApiKeyCommandInput, 'includeValue'>): Promise<GetApiKeyCommandOutput>;
38
+ /**
39
+ * List every resource (path) of a REST API, which is how REST APIs expose
40
+ * their routes. Pass `embed: ['methods']` to include each resource's
41
+ * methods. Auto-paginated.
42
+ */
43
+ getResources(input: GetResourcesCommandInput): Promise<Resource[]>;
44
+ }
45
+ //# sourceMappingURL=api-gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-gateway.d.ts","sourceRoot":"","sources":["../../../../src/api-gateway/api-gateway.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EACH,gBAAgB,EAChB,MAAM,EAEN,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,uBAAuB,EAIvB,QAAQ,EACR,OAAO,EACV,MAAM,6BAA6B,CAAC;AAIrC;;;;;;;;GAQG;AACH,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmB;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC;;;;;OAKG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,MAAM,CAAC,EAAE,gBAAgB,CAAA;KAAE;IAK1E;;OAEG;IACG,WAAW,CAAC,KAAK,GAAE,uBAA4B,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAQ1E;;OAEG;IACG,UAAU,CAAC,KAAK,GAAE,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAQ9F;;;OAGG;IACG,SAAS,CACX,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,cAAc,CAAC,GACnD,OAAO,CAAC,sBAAsB,CAAC;IAKlC;;;;OAIG;IACG,YAAY,CAAC,KAAK,EAAE,wBAAwB,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAO3E"}
@@ -0,0 +1,39 @@
1
+ import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
2
+ import { Api, ApiGatewayV2Client, GetApisCommandInput, GetRouteCommandInput, GetRouteCommandOutput, GetRoutesCommandInput, Route } from '@aws-sdk/client-apigatewayv2';
3
+ /**
4
+ * Read-only wrapper around the API Gateway v2 (HTTP and WebSocket APIs)
5
+ * control-plane client providing structured Powertools logging and X-Ray
6
+ * tracing by default.
7
+ *
8
+ * The v2 SDK ships no paginators for `GetApis` or `GetRoutes`, so list methods
9
+ * follow `NextToken` manually.
10
+ */
11
+ export declare class APIGatewayV2Service {
12
+ private readonly client;
13
+ private readonly logger;
14
+ /**
15
+ * @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
16
+ * which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
17
+ * @param opts.client - Optional pre-configured `ApiGatewayV2Client`. When
18
+ * supplied, the wrapper does not apply X-Ray instrumentation.
19
+ */
20
+ constructor(opts?: {
21
+ logger?: LoggerInterface;
22
+ client?: ApiGatewayV2Client;
23
+ });
24
+ /**
25
+ * List every HTTP and WebSocket API in the account and region.
26
+ * Auto-paginated.
27
+ */
28
+ getApis(input?: Omit<GetApisCommandInput, 'NextToken'>): Promise<Api[]>;
29
+ /**
30
+ * Fetch a single route of an HTTP or WebSocket API.
31
+ * @throws NotFoundException when the route does not exist.
32
+ */
33
+ getRoute(input: GetRouteCommandInput): Promise<GetRouteCommandOutput>;
34
+ /**
35
+ * List every route of an HTTP or WebSocket API. Auto-paginated.
36
+ */
37
+ getRoutes(input: Omit<GetRoutesCommandInput, 'NextToken'>): Promise<Route[]>;
38
+ }
39
+ //# sourceMappingURL=api-gateway-v2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-gateway-v2.d.ts","sourceRoot":"","sources":["../../../../src/api-gateway-v2/api-gateway-v2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EACH,GAAG,EACH,kBAAkB,EAElB,mBAAmB,EAEnB,oBAAoB,EACpB,qBAAqB,EAErB,qBAAqB,EACrB,KAAK,EACR,MAAM,8BAA8B,CAAC;AAItC;;;;;;;GAOG;AACH,qBAAa,mBAAmB;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqB;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IAEzC;;;;;OAKG;gBACS,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,eAAe,CAAC;QAAC,MAAM,CAAC,EAAE,kBAAkB,CAAA;KAAE;IAK5E;;;OAGG;IACG,OAAO,CAAC,KAAK,GAAE,IAAI,CAAC,mBAAmB,EAAE,WAAW,CAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IASjF;;;OAGG;IACG,QAAQ,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAK3E;;OAEG;IACG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;CAQrF"}
@@ -1,3 +1,5 @@
1
+ export { APIGatewayV2Service } from './api-gateway-v2/api-gateway-v2.js';
2
+ export { APIGatewayService } from './api-gateway/api-gateway.js';
1
3
  export { DynamoDBService } from './dynamodb/dynamodb.js';
2
4
  export { S3Service } from './s3/s3.js';
3
5
  export { SchedulerService } from './scheduler/scheduler.js';
@@ -6,4 +8,6 @@ export { StepFunctionsService } from './sfn/sfn.js';
6
8
  export { SNSService } from './sns/sns.js';
7
9
  export { SQSService } from './sqs/sqs.js';
8
10
  export { SSMService } from './ssm/ssm.js';
11
+ export { BatchOperationError } from './util/batch-operation-error.js';
12
+ export type { BatchFailedEntry } from './util/batch-operation-error.js';
9
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,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"}
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,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"}