@aligent/aws-wrappers 0.1.0 → 0.1.1
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/cjs/index.cjs +1911 -0
- package/cjs/index.d.ts +1 -0
- package/cjs/package.json +51 -0
- package/cjs/src/index.d.ts +7 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.mjs +1903 -0
- package/esm/package.json +51 -0
- package/esm/src/dynamodb/dynamodb.d.ts +127 -0
- package/esm/src/index.d.ts +7 -0
- package/esm/src/s3/s3.d.ts +131 -0
- package/esm/src/secrets-manager/secrets-manager.d.ts +78 -0
- package/esm/src/sfn/sfn.d.ts +38 -0
- package/esm/src/sns/sns.d.ts +48 -0
- package/esm/src/sqs/sqs.d.ts +60 -0
- package/esm/src/ssm/ssm.d.ts +84 -0
- package/{src/util/redact.js → esm/src/util/redact.d.ts} +2 -13
- package/esm/src/util/truncate.d.ts +15 -0
- package/package.json +25 -7
- package/CLAUDE.md +0 -173
- package/src/dynamodb/dynamodb.js +0 -308
- package/src/index.d.ts +0 -7
- package/src/index.js +0 -17
- package/src/s3/s3.js +0 -244
- package/src/secrets-manager/secrets-manager.js +0 -152
- package/src/sfn/sfn.js +0 -74
- package/src/sns/sns.js +0 -110
- package/src/sqs/sqs.js +0 -134
- package/src/ssm/ssm.js +0 -144
- package/src/util/truncate.js +0 -36
- package/tsconfig.lib.tsbuildinfo +0 -1
- /package/{src → cjs/src}/dynamodb/dynamodb.d.ts +0 -0
- /package/{src → cjs/src}/s3/s3.d.ts +0 -0
- /package/{src → cjs/src}/secrets-manager/secrets-manager.d.ts +0 -0
- /package/{src → cjs/src}/sfn/sfn.d.ts +0 -0
- /package/{src → cjs/src}/sns/sns.d.ts +0 -0
- /package/{src → cjs/src}/sqs/sqs.d.ts +0 -0
- /package/{src → cjs/src}/ssm/ssm.d.ts +0 -0
- /package/{src → cjs/src}/util/redact.d.ts +0 -0
- /package/{src → cjs/src}/util/truncate.d.ts +0 -0
package/esm/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aligent/aws-wrappers",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Opinionated AWS SDK wrappers with Powertools logging and X-Ray tracing",
|
|
5
|
+
"main": "./cjs/index.cjs",
|
|
6
|
+
"module": "./index.esm.js",
|
|
7
|
+
"types": "./cjs/src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./esm/src/index.d.ts",
|
|
12
|
+
"default": "./esm/index.mjs"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./cjs/src/index.d.ts",
|
|
16
|
+
"default": "./cjs/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"cjs",
|
|
23
|
+
"esm",
|
|
24
|
+
"README.md",
|
|
25
|
+
"docs"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/aligent/microservice-development-utilities.git",
|
|
30
|
+
"directory": "packages/aws-wrappers"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@aws-lambda-powertools/logger": "^2.33.0",
|
|
34
|
+
"@aws-sdk/client-dynamodb": "^3.1045.0",
|
|
35
|
+
"@aws-sdk/client-s3": "^3.1045.0",
|
|
36
|
+
"@aws-sdk/client-secrets-manager": "^3.1045.0",
|
|
37
|
+
"@aws-sdk/client-sfn": "^3.1045.0",
|
|
38
|
+
"@aws-sdk/client-sns": "^3.1045.0",
|
|
39
|
+
"@aws-sdk/client-sqs": "^3.1045.0",
|
|
40
|
+
"@aws-sdk/client-ssm": "^3.1045.0",
|
|
41
|
+
"@aws-sdk/lib-dynamodb": "^3.1045.0",
|
|
42
|
+
"@aws-sdk/s3-request-presigner": "^3.1045.0",
|
|
43
|
+
"aws-xray-sdk-core": "^3.12.0"
|
|
44
|
+
},
|
|
45
|
+
"author": "Aligent",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"aws-sdk-client-mock": "^4.1.0"
|
|
49
|
+
},
|
|
50
|
+
"type": "module"
|
|
51
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { BatchGetCommandInput, BatchGetCommandOutput, BatchWriteCommandInput, BatchWriteCommandOutput, DeleteCommandInput, DeleteCommandOutput, DynamoDBDocumentClient, GetCommandInput, PutCommandInput, PutCommandOutput, QueryCommandInput, QueryCommandOutput, ScanCommandInput, ScanCommandOutput, UpdateCommandInput, UpdateCommandOutput } from '@aws-sdk/lib-dynamodb';
|
|
3
|
+
/**
|
|
4
|
+
* DynamoDB command input with a typed `Key`. Used to thread a caller-defined
|
|
5
|
+
* key shape through the SDK input shape while preserving every other field.
|
|
6
|
+
*/
|
|
7
|
+
type WithTypedKey<TInput, K extends Record<string, unknown>> = Omit<TInput, 'Key'> & {
|
|
8
|
+
Key: K;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Wrapper around the AWS DynamoDB Document client providing structured
|
|
12
|
+
* Powertools logging and X-Ray tracing by default.
|
|
13
|
+
*
|
|
14
|
+
* Items are automatically marshalled / unmarshalled via the document client —
|
|
15
|
+
* callers work with plain TypeScript objects in both directions.
|
|
16
|
+
*/
|
|
17
|
+
export declare class DynamoDBService {
|
|
18
|
+
private readonly client;
|
|
19
|
+
private readonly logger;
|
|
20
|
+
/**
|
|
21
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
22
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
23
|
+
* @param opts.client - Optional pre-configured `DynamoDBDocumentClient`.
|
|
24
|
+
* When supplied, the wrapper does not apply X-Ray instrumentation. When
|
|
25
|
+
* omitted, a default `DynamoDBClient` is wrapped with `captureAWSv3Client`
|
|
26
|
+
* *before* being passed to `DynamoDBDocumentClient.from`, so X-Ray
|
|
27
|
+
* tracing captures every DynamoDB call.
|
|
28
|
+
*/
|
|
29
|
+
constructor(opts?: {
|
|
30
|
+
logger?: LoggerInterface;
|
|
31
|
+
client?: DynamoDBDocumentClient;
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Get an item from DynamoDB.
|
|
35
|
+
* @template K - Shape of the partition / sort key.
|
|
36
|
+
* @template R - Expected unmarshalled item shape.
|
|
37
|
+
* @returns The item, or `undefined` if not found.
|
|
38
|
+
*/
|
|
39
|
+
getItem<K extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>>(input: WithTypedKey<GetCommandInput, K>): Promise<R | undefined>;
|
|
40
|
+
/**
|
|
41
|
+
* Put an item into DynamoDB. The caller's `Item` is typed as `T`, which
|
|
42
|
+
* the document client marshalls automatically.
|
|
43
|
+
* @template T - Type of the item being stored.
|
|
44
|
+
*/
|
|
45
|
+
putItem<T>(input: Omit<PutCommandInput, 'Item'> & {
|
|
46
|
+
Item: T;
|
|
47
|
+
}): Promise<PutCommandOutput>;
|
|
48
|
+
/**
|
|
49
|
+
* Update an item in DynamoDB. The `Attributes` field on the response is
|
|
50
|
+
* typed as `R` — the caller should choose `R` to match their
|
|
51
|
+
* `ReturnValues` setting:
|
|
52
|
+
* - `NONE` (default): no `Attributes` returned.
|
|
53
|
+
* - `ALL_OLD` / `ALL_NEW`: full item.
|
|
54
|
+
* - `UPDATED_OLD` / `UPDATED_NEW`: only updated attributes (partial).
|
|
55
|
+
* @template K - Shape of the partition / sort key.
|
|
56
|
+
* @template R - Expected shape of the returned `Attributes`.
|
|
57
|
+
*/
|
|
58
|
+
updateItem<K extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>>(input: WithTypedKey<UpdateCommandInput, K>): Promise<Omit<UpdateCommandOutput, 'Attributes'> & {
|
|
59
|
+
Attributes?: R;
|
|
60
|
+
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Delete an item from DynamoDB. The `Attributes` field on the response is
|
|
63
|
+
* typed as `R` — relevant when `ReturnValues: 'ALL_OLD'` is set.
|
|
64
|
+
* @template K - Shape of the partition / sort key.
|
|
65
|
+
* @template R - Expected shape of the returned `Attributes`.
|
|
66
|
+
*/
|
|
67
|
+
deleteItem<K extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>>(input: WithTypedKey<DeleteCommandInput, K>): Promise<Omit<DeleteCommandOutput, 'Attributes'> & {
|
|
68
|
+
Attributes?: R;
|
|
69
|
+
}>;
|
|
70
|
+
/**
|
|
71
|
+
* Execute a DynamoDB Query. The full `QueryCommandOutput` is returned with
|
|
72
|
+
* `Items` typed as `T[]` so callers retain pagination metadata
|
|
73
|
+
* (`LastEvaluatedKey`, `Count`, etc.).
|
|
74
|
+
* @template T - Expected shape of each unmarshalled item.
|
|
75
|
+
*/
|
|
76
|
+
query<T extends Record<string, unknown> = Record<string, unknown>>(input: QueryCommandInput): Promise<Omit<QueryCommandOutput, 'Items'> & {
|
|
77
|
+
Items?: T[];
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Scan a DynamoDB table. The full `ScanCommandOutput` is returned with
|
|
81
|
+
* `Items` typed as `T[]` so callers retain pagination metadata.
|
|
82
|
+
*
|
|
83
|
+
* Scan reads every item in the table, so cost and latency grow linearly
|
|
84
|
+
* with table size; it is rarely the right tool in a runtime service.
|
|
85
|
+
* Prefer, in order:
|
|
86
|
+
*
|
|
87
|
+
* 1. `query` with the table's partition key.
|
|
88
|
+
* 2. `query` against a GSI or LSI whose key matches your access pattern.
|
|
89
|
+
* 3. A sparse GSI populated only for the items you need to enumerate.
|
|
90
|
+
* 4. A denormalised lookup item or table maintained on write.
|
|
91
|
+
*
|
|
92
|
+
* Legitimate scan use cases are mostly one-off admin work (export,
|
|
93
|
+
* migration, audit). For those, prefer the AWS CLI or Console rather than
|
|
94
|
+
* embedding a scan in a Lambda.
|
|
95
|
+
*
|
|
96
|
+
* @template T - Expected shape of each unmarshalled item.
|
|
97
|
+
*/
|
|
98
|
+
scan<T extends Record<string, unknown> = Record<string, unknown>>(input: ScanCommandInput): Promise<Omit<ScanCommandOutput, 'Items'> & {
|
|
99
|
+
Items?: T[];
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Batch-get items from one or more DynamoDB tables.
|
|
103
|
+
*
|
|
104
|
+
* Note: this method is intentionally **not** generic. `BatchGet`'s
|
|
105
|
+
* `Responses` field is a multi-table `Record<string, item[]>` whose item
|
|
106
|
+
* shapes can differ per table — no single `T` can soundly describe it.
|
|
107
|
+
* Callers should narrow the result type at the call site.
|
|
108
|
+
*/
|
|
109
|
+
batchGet(input: BatchGetCommandInput): Promise<BatchGetCommandOutput>;
|
|
110
|
+
/**
|
|
111
|
+
* Batch-write items to DynamoDB, retrying `UnprocessedItems` with jittered
|
|
112
|
+
* exponential backoff. Up to 5 attempts (200ms base delay). Throws when
|
|
113
|
+
* items remain unprocessed after the final attempt.
|
|
114
|
+
*/
|
|
115
|
+
batchWrite(input: BatchWriteCommandInput): Promise<BatchWriteCommandOutput>;
|
|
116
|
+
/**
|
|
117
|
+
* Paginate over Query results, yielding one unmarshalled item at a time.
|
|
118
|
+
* @template T - Expected shape of each yielded item.
|
|
119
|
+
*/
|
|
120
|
+
paginateItems<T extends Record<string, unknown> = Record<string, unknown>>(input: QueryCommandInput): AsyncGenerator<T>;
|
|
121
|
+
/**
|
|
122
|
+
* Paginate over Scan results, yielding one unmarshalled item at a time.
|
|
123
|
+
* @template T - Expected shape of each yielded item.
|
|
124
|
+
*/
|
|
125
|
+
paginateScan<T extends Record<string, unknown> = Record<string, unknown>>(input: ScanCommandInput): AsyncGenerator<T>;
|
|
126
|
+
}
|
|
127
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DynamoDBService } from './dynamodb/dynamodb.js';
|
|
2
|
+
export { S3Service } from './s3/s3.js';
|
|
3
|
+
export { SecretsManagerService } from './secrets-manager/secrets-manager.js';
|
|
4
|
+
export { StepFunctionsService } from './sfn/sfn.js';
|
|
5
|
+
export { SNSService } from './sns/sns.js';
|
|
6
|
+
export { SQSService } from './sqs/sqs.js';
|
|
7
|
+
export { SSMService } from './ssm/ssm.js';
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { CopyObjectCommandInput, CopyObjectCommandOutput, DeleteObjectCommandInput, DeleteObjectCommandOutput, DeleteObjectsCommandOutput, GetObjectCommandInput, GetObjectCommandOutput, HeadObjectCommandInput, HeadObjectCommandOutput, PutObjectCommandInput, PutObjectCommandOutput, S3Client } from '@aws-sdk/client-s3';
|
|
3
|
+
/** Tight wrapper input type for `putObject`. */
|
|
4
|
+
type PutObjectInput = Required<Pick<PutObjectCommandInput, 'Bucket' | 'Key' | 'Body'>>;
|
|
5
|
+
/** Tight wrapper input type for `putJsonObject`. */
|
|
6
|
+
type PutJsonObjectInput<T> = {
|
|
7
|
+
Bucket: string;
|
|
8
|
+
Key: string;
|
|
9
|
+
Body: T;
|
|
10
|
+
Metadata?: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper around the AWS S3 client providing structured Powertools logging
|
|
14
|
+
* and X-Ray tracing by default.
|
|
15
|
+
*
|
|
16
|
+
* Input shapes are intentionally tight (Bucket/Key/Body only). Callers
|
|
17
|
+
* needing SDK-level options not exposed here (server-side encryption,
|
|
18
|
+
* tagging, version IDs) should use `S3Client` directly.
|
|
19
|
+
*/
|
|
20
|
+
export declare class S3Service {
|
|
21
|
+
private readonly client;
|
|
22
|
+
private readonly logger;
|
|
23
|
+
/**
|
|
24
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
25
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
26
|
+
* @param opts.client - Optional pre-configured `S3Client`. When supplied,
|
|
27
|
+
* the wrapper does not apply X-Ray instrumentation.
|
|
28
|
+
*/
|
|
29
|
+
constructor(opts?: {
|
|
30
|
+
logger?: LoggerInterface;
|
|
31
|
+
client?: S3Client;
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Put an object into S3.
|
|
35
|
+
*
|
|
36
|
+
* Note: the structured log line only includes `Bucket` and `Key` —
|
|
37
|
+
* `Body` is omitted to avoid spilling large payloads or sensitive
|
|
38
|
+
* content into CloudWatch.
|
|
39
|
+
*
|
|
40
|
+
* @param input - Bucket, Key, and Body of the object to store.
|
|
41
|
+
*/
|
|
42
|
+
putObject(input: PutObjectInput): Promise<PutObjectCommandOutput>;
|
|
43
|
+
/**
|
|
44
|
+
* Serialise a value to JSON and store it as an S3 object.
|
|
45
|
+
*
|
|
46
|
+
* Note: the structured log line only includes `Bucket` and `Key` —
|
|
47
|
+
* the JSON-encoded body is omitted to avoid spilling potentially
|
|
48
|
+
* large or sensitive content into CloudWatch.
|
|
49
|
+
*
|
|
50
|
+
* @template T - Type of the value being stored.
|
|
51
|
+
*/
|
|
52
|
+
putJsonObject<T>(input: PutJsonObjectInput<T>): Promise<PutObjectCommandOutput>;
|
|
53
|
+
/**
|
|
54
|
+
* Get an object from S3.
|
|
55
|
+
*/
|
|
56
|
+
getObject(input: Required<Pick<GetObjectCommandInput, 'Bucket' | 'Key'>>): Promise<GetObjectCommandOutput>;
|
|
57
|
+
/**
|
|
58
|
+
* Get an object from S3 and return its body as a string.
|
|
59
|
+
* @returns The object body as a string, or `undefined` if the response
|
|
60
|
+
* has no body.
|
|
61
|
+
*/
|
|
62
|
+
getObjectBody(input: Required<Pick<GetObjectCommandInput, 'Bucket' | 'Key'>>): Promise<string | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* Get an object from S3 and parse it as JSON.
|
|
65
|
+
* @template T - Expected type of the parsed value.
|
|
66
|
+
* @returns The parsed value, or `undefined` if the response has no body.
|
|
67
|
+
* @throws If the body is non-empty and not valid JSON.
|
|
68
|
+
*/
|
|
69
|
+
getJsonObject<T>(input: Required<Pick<GetObjectCommandInput, 'Bucket' | 'Key'>>): Promise<T | undefined>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch the metadata for an S3 object without downloading its body.
|
|
72
|
+
*/
|
|
73
|
+
headObject(input: Required<Pick<HeadObjectCommandInput, 'Bucket' | 'Key'>>): Promise<HeadObjectCommandOutput>;
|
|
74
|
+
/**
|
|
75
|
+
* Copy an object within S3.
|
|
76
|
+
*/
|
|
77
|
+
copyObject(input: Required<Pick<CopyObjectCommandInput, 'Bucket' | 'Key' | 'CopySource'>>): Promise<CopyObjectCommandOutput>;
|
|
78
|
+
/**
|
|
79
|
+
* List object keys under a bucket and optional prefix, auto-paginating
|
|
80
|
+
* across all pages.
|
|
81
|
+
*/
|
|
82
|
+
listObjects(bucket: string, prefix?: string): Promise<string[]>;
|
|
83
|
+
/**
|
|
84
|
+
* List and JSON-parse every object under a bucket and optional prefix.
|
|
85
|
+
* Auto-paginated. Objects without a body are skipped.
|
|
86
|
+
* @template T - Expected type of each parsed object.
|
|
87
|
+
*/
|
|
88
|
+
getAllObjects<T>(bucket: string, prefix?: string): Promise<T[]>;
|
|
89
|
+
/**
|
|
90
|
+
* Generate a presigned URL that callers can use to GET or PUT an S3 object
|
|
91
|
+
* directly, without going through the wrapper. The signing happens against
|
|
92
|
+
* the wrapper's `S3Client`, so callers do not need their own client.
|
|
93
|
+
*
|
|
94
|
+
* GET URLs are signed with `ResponseContentDisposition: 'attachment'` so
|
|
95
|
+
* browsers download the object rather than rendering it in-place.
|
|
96
|
+
*
|
|
97
|
+
* The input shape is an inline object (rather than the `Required<Pick<...>>`
|
|
98
|
+
* pattern used by other S3 methods) because this method wraps two SDK
|
|
99
|
+
* commands rather than one, and `action` / `expiresIn` are wrapper-level
|
|
100
|
+
* concerns with no SDK-input equivalent.
|
|
101
|
+
*
|
|
102
|
+
* @param input.Bucket - The S3 bucket name.
|
|
103
|
+
* @param input.Key - The S3 object key.
|
|
104
|
+
* @param input.action - `'get'` to download, `'put'` to upload.
|
|
105
|
+
* @param input.expiresIn - URL lifetime in seconds. Defaults to 3600 (1 hour).
|
|
106
|
+
*/
|
|
107
|
+
getPresignedUrl(input: {
|
|
108
|
+
Bucket: string;
|
|
109
|
+
Key: string;
|
|
110
|
+
action: 'get' | 'put';
|
|
111
|
+
expiresIn?: number;
|
|
112
|
+
}): Promise<string>;
|
|
113
|
+
/**
|
|
114
|
+
* Delete a single object from S3.
|
|
115
|
+
*/
|
|
116
|
+
deleteObject(input: Required<Pick<DeleteObjectCommandInput, 'Bucket' | 'Key'>>): Promise<DeleteObjectCommandOutput>;
|
|
117
|
+
/**
|
|
118
|
+
* Delete multiple objects from S3, auto-chunking the request into batches
|
|
119
|
+
* of 1000 keys (the S3-enforced DeleteObjects limit). Returns one output
|
|
120
|
+
* per chunk.
|
|
121
|
+
*/
|
|
122
|
+
deleteObjects(bucket: string, keys: string[]): Promise<DeleteObjectsCommandOutput[]>;
|
|
123
|
+
/**
|
|
124
|
+
* Delete every object in a bucket. Streams the listing page-by-page and
|
|
125
|
+
* delegates each page's deletion to `deleteObjects`, so peak memory stays
|
|
126
|
+
* bounded by one page (~1000 keys) regardless of bucket size.
|
|
127
|
+
* @returns The keys of every deleted object.
|
|
128
|
+
*/
|
|
129
|
+
emptyBucket(bucket: string): Promise<string[]>;
|
|
130
|
+
}
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { CreateSecretCommandInput, CreateSecretCommandOutput, DeleteSecretCommandInput, DeleteSecretCommandOutput, PutSecretValueCommandInput, PutSecretValueCommandOutput, SecretsManagerClient, UpdateSecretCommandInput, UpdateSecretCommandOutput } from '@aws-sdk/client-secrets-manager';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS Secrets Manager client providing structured
|
|
5
|
+
* Powertools logging and X-Ray tracing by default.
|
|
6
|
+
*
|
|
7
|
+
* Write operations (`createSecret`, `updateSecret`, `putSecretValue`,
|
|
8
|
+
* `deleteSecret`) are exposed for convenience but should be used with care:
|
|
9
|
+
* secret lifecycle is usually managed by IaC (CDK / Terraform). Prefer IaC
|
|
10
|
+
* for anything that exists at deploy time; reserve runtime writes for
|
|
11
|
+
* dynamically-issued credentials, rotation flows, or other genuinely
|
|
12
|
+
* mutable values.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SecretsManagerService {
|
|
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 `SecretsManagerClient`. When
|
|
21
|
+
* supplied, the wrapper does not apply X-Ray instrumentation — the caller
|
|
22
|
+
* owns that decision.
|
|
23
|
+
*/
|
|
24
|
+
constructor(opts?: {
|
|
25
|
+
logger?: LoggerInterface;
|
|
26
|
+
client?: SecretsManagerClient;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Fetch a secret's string value from Secrets Manager.
|
|
30
|
+
* @param secretId - The ARN or friendly name of the secret.
|
|
31
|
+
* @returns The secret's `SecretString` value.
|
|
32
|
+
* @throws If the response does not contain a `SecretString` (e.g. the secret
|
|
33
|
+
* stores binary data).
|
|
34
|
+
*/
|
|
35
|
+
getSecret(secretId: string): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Fetch a secret and parse it as JSON.
|
|
38
|
+
* @param secretId - The ARN or friendly name of the secret.
|
|
39
|
+
* @template T - Expected shape of the parsed secret.
|
|
40
|
+
* @returns The parsed secret value.
|
|
41
|
+
* @throws If the secret has no `SecretString` or the value is not valid JSON.
|
|
42
|
+
*/
|
|
43
|
+
getJsonSecret<T>(secretId: string): Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new secret. At INFO level the log line includes only identity
|
|
46
|
+
* and non-secret metadata; `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the full
|
|
47
|
+
* input (including `SecretString` / `SecretBinary`).
|
|
48
|
+
*
|
|
49
|
+
* Prefer IaC (CDK / Terraform) for secret lifecycle — use this for
|
|
50
|
+
* dynamically-issued credentials only.
|
|
51
|
+
*/
|
|
52
|
+
createSecret(input: CreateSecretCommandInput): Promise<CreateSecretCommandOutput>;
|
|
53
|
+
/**
|
|
54
|
+
* Update an existing secret's metadata or value. At INFO level the log
|
|
55
|
+
* line omits `SecretString` / `SecretBinary`; `POWERTOOLS_LOG_LEVEL=DEBUG`
|
|
56
|
+
* unlocks the full input.
|
|
57
|
+
*
|
|
58
|
+
* Prefer IaC (CDK / Terraform) for secret lifecycle — use this for
|
|
59
|
+
* runtime metadata updates only.
|
|
60
|
+
*/
|
|
61
|
+
updateSecret(input: UpdateSecretCommandInput): Promise<UpdateSecretCommandOutput>;
|
|
62
|
+
/**
|
|
63
|
+
* Store a new version of a secret's value. At INFO level the log line
|
|
64
|
+
* omits `SecretString` / `SecretBinary`; `POWERTOOLS_LOG_LEVEL=DEBUG`
|
|
65
|
+
* unlocks the full input.
|
|
66
|
+
*
|
|
67
|
+
* Typically used by rotation flows.
|
|
68
|
+
*/
|
|
69
|
+
putSecretValue(input: PutSecretValueCommandInput): Promise<PutSecretValueCommandOutput>;
|
|
70
|
+
/**
|
|
71
|
+
* Delete a secret. Pass `ForceDeleteWithoutRecovery: true` to bypass the
|
|
72
|
+
* default 7-30 day recovery window (irreversible).
|
|
73
|
+
*
|
|
74
|
+
* Prefer IaC (CDK / Terraform) for secret lifecycle.
|
|
75
|
+
*/
|
|
76
|
+
deleteSecret(input: DeleteSecretCommandInput): Promise<DeleteSecretCommandOutput>;
|
|
77
|
+
private fetchSecretString;
|
|
78
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { DescribeExecutionCommandInput, DescribeExecutionCommandOutput, ExecutionListItem, ListExecutionsCommandInput, SFNClient, StartExecutionCommandInput, StartExecutionCommandOutput, StopExecutionCommandInput, StopExecutionCommandOutput } from '@aws-sdk/client-sfn';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS Step Functions client providing structured
|
|
5
|
+
* Powertools logging and X-Ray tracing by default.
|
|
6
|
+
*/
|
|
7
|
+
export declare class StepFunctionsService {
|
|
8
|
+
private readonly client;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
/**
|
|
11
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
12
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
13
|
+
* @param opts.client - Optional pre-configured `SFNClient`. When supplied,
|
|
14
|
+
* the wrapper does not apply X-Ray instrumentation.
|
|
15
|
+
*/
|
|
16
|
+
constructor(opts?: {
|
|
17
|
+
logger?: LoggerInterface;
|
|
18
|
+
client?: SFNClient;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* List all executions for a state machine, auto-paginating across all
|
|
22
|
+
* pages. Typically bounded by `statusFilter` and state-machine retention,
|
|
23
|
+
* so the flat-array shape is safe in practice.
|
|
24
|
+
*/
|
|
25
|
+
listExecutions(input: ListExecutionsCommandInput): Promise<ExecutionListItem[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Start a new Step Functions execution.
|
|
28
|
+
*/
|
|
29
|
+
startExecution(input: StartExecutionCommandInput): Promise<StartExecutionCommandOutput>;
|
|
30
|
+
/**
|
|
31
|
+
* Describe an existing Step Functions execution.
|
|
32
|
+
*/
|
|
33
|
+
describeExecution(input: DescribeExecutionCommandInput): Promise<DescribeExecutionCommandOutput>;
|
|
34
|
+
/**
|
|
35
|
+
* Stop an in-progress Step Functions execution.
|
|
36
|
+
*/
|
|
37
|
+
stopExecution(input: StopExecutionCommandInput): Promise<StopExecutionCommandOutput>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { PublishBatchCommandInput, PublishBatchCommandOutput, PublishCommandInput, PublishCommandOutput, SNSClient } from '@aws-sdk/client-sns';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS SNS client providing structured Powertools logging
|
|
5
|
+
* and X-Ray tracing by default.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SNSService {
|
|
8
|
+
private readonly client;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly truncate;
|
|
11
|
+
/**
|
|
12
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
13
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
14
|
+
* @param opts.client - Optional pre-configured `SNSClient`. When supplied,
|
|
15
|
+
* the wrapper does not apply X-Ray instrumentation.
|
|
16
|
+
* @param opts.truncate - When `true`, oversized `Message` / `Subject` are
|
|
17
|
+
* truncated (byte-safe / codepoint-safe) before sending instead of failing
|
|
18
|
+
* at the SDK. Defaults to `false` — the SDK throws on oversize, which is
|
|
19
|
+
* usually the right failure mode. Each `publish` call can override via
|
|
20
|
+
* its own `truncate` option.
|
|
21
|
+
*/
|
|
22
|
+
constructor(opts?: {
|
|
23
|
+
logger?: LoggerInterface;
|
|
24
|
+
client?: SNSClient;
|
|
25
|
+
truncate?: boolean;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* Publish a single message to an SNS topic.
|
|
29
|
+
*
|
|
30
|
+
* At INFO level the log line includes only routing / dedup metadata; see
|
|
31
|
+
* `PUBLISH_SAFE_FIELDS` for the list. Setting `POWERTOOLS_LOG_LEVEL=DEBUG`
|
|
32
|
+
* unlocks the full input.
|
|
33
|
+
*
|
|
34
|
+
* @param input - PublishCommandInput including TopicArn and Message.
|
|
35
|
+
*/
|
|
36
|
+
publish(input: PublishCommandInput, opts?: {
|
|
37
|
+
truncate?: boolean;
|
|
38
|
+
}): Promise<PublishCommandOutput>;
|
|
39
|
+
private applyTruncation;
|
|
40
|
+
/**
|
|
41
|
+
* Publish a batch of messages to an SNS topic. The SNS API caps
|
|
42
|
+
* PublishBatch at 10 entries per request, so this method auto-chunks
|
|
43
|
+
* the caller's `PublishBatchRequestEntries` and sends one request per
|
|
44
|
+
* chunk, returning the array of outputs.
|
|
45
|
+
* @param input - PublishBatchCommandInput including TopicArn and entries.
|
|
46
|
+
*/
|
|
47
|
+
publishBatch(input: PublishBatchCommandInput): Promise<PublishBatchCommandOutput[]>;
|
|
48
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { DeleteMessageBatchCommandInput, DeleteMessageBatchCommandOutput, DeleteMessageCommandInput, DeleteMessageCommandOutput, Message, ReceiveMessageCommandInput, SendMessageBatchCommandInput, SendMessageBatchCommandOutput, SendMessageCommandInput, SendMessageCommandOutput, SQSClient } from '@aws-sdk/client-sqs';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS SQS client providing structured Powertools logging
|
|
5
|
+
* and X-Ray tracing by default.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SQSService {
|
|
8
|
+
private readonly client;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly truncate;
|
|
11
|
+
/**
|
|
12
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
13
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
14
|
+
* @param opts.client - Optional pre-configured `SQSClient`. When supplied,
|
|
15
|
+
* the wrapper does not apply X-Ray instrumentation.
|
|
16
|
+
* @param opts.truncate - When `true`, oversized `MessageBody` is truncated
|
|
17
|
+
* (byte-safe) before sending instead of failing at the SDK. Defaults to
|
|
18
|
+
* `false`. Each `sendMessage` call can override via its own `truncate`
|
|
19
|
+
* option.
|
|
20
|
+
*/
|
|
21
|
+
constructor(opts?: {
|
|
22
|
+
logger?: LoggerInterface;
|
|
23
|
+
client?: SQSClient;
|
|
24
|
+
truncate?: boolean;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Send a single message to an SQS queue.
|
|
28
|
+
*
|
|
29
|
+
* At INFO level the log line includes only queue routing / FIFO metadata;
|
|
30
|
+
* see `SEND_MESSAGE_SAFE_FIELDS`. `POWERTOOLS_LOG_LEVEL=DEBUG` unlocks the
|
|
31
|
+
* full input.
|
|
32
|
+
*/
|
|
33
|
+
sendMessage(input: SendMessageCommandInput, opts?: {
|
|
34
|
+
truncate?: boolean;
|
|
35
|
+
}): Promise<SendMessageCommandOutput>;
|
|
36
|
+
private applyTruncation;
|
|
37
|
+
/**
|
|
38
|
+
* Receive messages from an SQS queue. Returns an empty array when no
|
|
39
|
+
* messages are available. No automatic deletion is performed — visibility
|
|
40
|
+
* timeout semantics are the caller's responsibility.
|
|
41
|
+
* @returns The `Messages` array from the response, or `[]` if absent.
|
|
42
|
+
*/
|
|
43
|
+
receiveMessages(input: ReceiveMessageCommandInput): Promise<Message[]>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a single message from an SQS queue.
|
|
46
|
+
*/
|
|
47
|
+
deleteMessage(input: DeleteMessageCommandInput): Promise<DeleteMessageCommandOutput>;
|
|
48
|
+
/**
|
|
49
|
+
* Send a batch of messages to an SQS queue. The SQS API caps
|
|
50
|
+
* SendMessageBatch at 10 entries per request, so this method auto-chunks
|
|
51
|
+
* the caller's entries and sends one request per chunk.
|
|
52
|
+
*/
|
|
53
|
+
sendMessageBatch(input: SendMessageBatchCommandInput): Promise<SendMessageBatchCommandOutput[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Delete a batch of messages from an SQS queue. The SQS API caps
|
|
56
|
+
* DeleteMessageBatch at 10 entries per request, so this method auto-chunks
|
|
57
|
+
* the caller's entries and sends one request per chunk.
|
|
58
|
+
*/
|
|
59
|
+
deleteMessageBatch(input: DeleteMessageBatchCommandInput): Promise<DeleteMessageBatchCommandOutput[]>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
2
|
+
import { Parameter, PutParameterCommandInput, PutParameterCommandOutput, SSMClient } from '@aws-sdk/client-ssm';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper around the AWS SSM Parameter Store client providing structured
|
|
5
|
+
* Powertools logging and X-Ray tracing by default. All read operations enable
|
|
6
|
+
* `WithDecryption` — callers needing plaintext should use `SSMClient`
|
|
7
|
+
* directly.
|
|
8
|
+
*
|
|
9
|
+
* Write operations (`putParameter`, `deleteParameter`) are exposed for
|
|
10
|
+
* convenience but should be used with care: parameter lifecycle is usually
|
|
11
|
+
* managed by IaC (CDK / Terraform). Prefer IaC for anything that exists at
|
|
12
|
+
* deploy time; reserve runtime writes for values that genuinely need to
|
|
13
|
+
* mutate within the application.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SSMService {
|
|
16
|
+
private readonly client;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
/**
|
|
19
|
+
* @param opts.logger - Optional Powertools logger. Defaults to `new Logger()`,
|
|
20
|
+
* which picks up `POWERTOOLS_SERVICE_NAME` from the environment.
|
|
21
|
+
* @param opts.client - Optional pre-configured `SSMClient`. When supplied,
|
|
22
|
+
* the wrapper does not apply X-Ray instrumentation.
|
|
23
|
+
*/
|
|
24
|
+
constructor(opts?: {
|
|
25
|
+
logger?: LoggerInterface;
|
|
26
|
+
client?: SSMClient;
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* Fetch a single SSM parameter's value.
|
|
30
|
+
* @param name - The parameter name (or ARN).
|
|
31
|
+
* @returns The parameter value, or `undefined` if the parameter has no
|
|
32
|
+
* value set.
|
|
33
|
+
*/
|
|
34
|
+
getParameter(name: string): Promise<string | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* Fetch multiple SSM parameters in a single request. Callers supply an
|
|
37
|
+
* alias-to-path record, and the returned record is keyed by the same
|
|
38
|
+
* aliases — so the SSM path is only mentioned at the call site and the
|
|
39
|
+
* destructured names are whatever the caller wants to use locally:
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* const { username, password } = await ssm.getParameters({
|
|
43
|
+
* username: '/myapp/db/username',
|
|
44
|
+
* password: '/myapp/db/password',
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @param aliases - Record mapping each desired local alias to its SSM
|
|
49
|
+
* parameter name (or ARN).
|
|
50
|
+
* @returns A record keyed by the same aliases, mapping each to the
|
|
51
|
+
* parameter's value, or `undefined` when the parameter is missing or has
|
|
52
|
+
* no value.
|
|
53
|
+
*/
|
|
54
|
+
getParameters<K extends string>(aliases: Record<K, string>): Promise<Record<K, string | undefined>>;
|
|
55
|
+
/**
|
|
56
|
+
* Create or update an SSM parameter. The log line omits `Value` to avoid
|
|
57
|
+
* leaking secret material.
|
|
58
|
+
*
|
|
59
|
+
* Prefer IaC (CDK / Terraform) for parameter lifecycle — use this for
|
|
60
|
+
* runtime values only.
|
|
61
|
+
*/
|
|
62
|
+
putParameter(input: PutParameterCommandInput): Promise<PutParameterCommandOutput>;
|
|
63
|
+
/**
|
|
64
|
+
* Delete an SSM parameter by name.
|
|
65
|
+
*
|
|
66
|
+
* Prefer IaC (CDK / Terraform) for parameter lifecycle — use this for
|
|
67
|
+
* runtime cleanup only.
|
|
68
|
+
*/
|
|
69
|
+
deleteParameter(name: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Fetch all parameters under an SSM hierarchy path, auto-paginating across
|
|
72
|
+
* all pages. `Recursive` defaults to `true` (overriding the AWS SDK
|
|
73
|
+
* default of `false`) to match the typical "load all config under
|
|
74
|
+
* `/myapp/`" use case.
|
|
75
|
+
* @param path - The parameter path prefix (e.g. `/myapp/`).
|
|
76
|
+
* @param opts.recursive - Whether to recurse into nested paths. Defaults
|
|
77
|
+
* to `true`.
|
|
78
|
+
* @returns The full `Parameter` objects (including `Version`,
|
|
79
|
+
* `LastModifiedDate`, etc.).
|
|
80
|
+
*/
|
|
81
|
+
getParametersByPath(path: string, opts?: {
|
|
82
|
+
recursive?: boolean;
|
|
83
|
+
}): Promise<Parameter[]>;
|
|
84
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.filterFieldsForLogLevel = filterFieldsForLogLevel;
|
|
1
|
+
import type { LoggerInterface } from '@aws-lambda-powertools/logger/types';
|
|
4
2
|
/**
|
|
5
3
|
* Return a log-safe projection of `input` based on the logger's configured level.
|
|
6
4
|
*
|
|
@@ -17,13 +15,4 @@ exports.filterFieldsForLogLevel = filterFieldsForLogLevel;
|
|
|
17
15
|
* lives in one place. See `packages/aws-wrappers/CLAUDE.md` ("Logging") for
|
|
18
16
|
* the design rationale and conventions on building the safe-field lists.
|
|
19
17
|
*/
|
|
20
|
-
function filterFieldsForLogLevel(logger, input, safeFields)
|
|
21
|
-
if (logger.getLevelName() === 'DEBUG')
|
|
22
|
-
return input;
|
|
23
|
-
const out = {};
|
|
24
|
-
for (const key of safeFields) {
|
|
25
|
-
if (key in input)
|
|
26
|
-
out[key] = input[key];
|
|
27
|
-
}
|
|
28
|
-
return out;
|
|
29
|
-
}
|
|
18
|
+
export declare function filterFieldsForLogLevel<T extends object, K extends keyof T>(logger: LoggerInterface, input: T, safeFields: readonly K[]): T | Pick<T, K>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truncate a UTF-8 string to fit within `maxBytes` when encoded as UTF-8.
|
|
3
|
+
*
|
|
4
|
+
* Walks back from the cut point to the start of the previous codepoint, so the
|
|
5
|
+
* result is never a malformed UTF-8 sequence. Returns the input unchanged when
|
|
6
|
+
* it already fits.
|
|
7
|
+
*/
|
|
8
|
+
export declare function truncateUtf8(str: string, maxBytes: number): string;
|
|
9
|
+
/**
|
|
10
|
+
* Truncate a string to at most `maxChars` Unicode codepoints. Splits the
|
|
11
|
+
* string via `Array.from` so surrogate pairs (emoji, supplementary-plane
|
|
12
|
+
* characters) are not split in the middle. Returns the input unchanged when
|
|
13
|
+
* it already fits.
|
|
14
|
+
*/
|
|
15
|
+
export declare function truncateCodepoints(str: string, maxChars: number): string;
|