@ttoss/lambda-postgres-query 1.0.1 → 1.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/README.md
CHANGED
|
@@ -289,6 +289,31 @@ Each function in `createLambdaPostgresQueryTemplate` can use different `database
|
|
|
289
289
|
|
|
290
290
|
Grant each consumer `lambda:InvokeFunction` only for the ARN output it needs, such as `LambdaPostgresReadQueryFunctionArn` for read-only consumers.
|
|
291
291
|
|
|
292
|
+
ARN outputs are exported with this CloudFormation export name pattern:
|
|
293
|
+
|
|
294
|
+
- `${AWS::StackName}-${outputArnName}`
|
|
295
|
+
|
|
296
|
+
The practical reason to export these names is also deletion safety: when another stack imports an ARN export, CloudFormation blocks deleting the producer stack resource until that import is removed.
|
|
297
|
+
|
|
298
|
+
For example, `LambdaPostgresReadQueryFunctionArn` is exported as `${AWS::StackName}-LambdaPostgresReadQueryFunctionArn`.
|
|
299
|
+
|
|
300
|
+
In a consumer stack, define a parameter with that export name and import it using `importValueFromParameter`:
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import { importValueFromParameter } from '@ttoss/cloudformation';
|
|
304
|
+
|
|
305
|
+
const resources = {
|
|
306
|
+
InvokePermission: {
|
|
307
|
+
Type: 'AWS::Lambda::Permission',
|
|
308
|
+
Properties: {
|
|
309
|
+
FunctionName: importValueFromParameter('ReadQueryFunctionArnExportName'),
|
|
310
|
+
Action: 'lambda:InvokeFunction',
|
|
311
|
+
Principal: 'apigateway.amazonaws.com',
|
|
312
|
+
},
|
|
313
|
+
},
|
|
314
|
+
};
|
|
315
|
+
```
|
|
316
|
+
|
|
292
317
|
## API Reference
|
|
293
318
|
|
|
294
319
|
### `createLambdaPostgresQueryTemplate(options?)`
|
|
@@ -303,8 +328,10 @@ Creates a CloudFormation template for one or more PostgreSQL query Lambdas.
|
|
|
303
328
|
- `handler` (string, optional): Handler function. Default: `'handler.handler'`
|
|
304
329
|
- `databaseParameters` (object, optional): CloudFormation parameter names used to inject database settings into that Lambda
|
|
305
330
|
- `outputArnName` (string, optional): Output key for the function ARN. Default: `${name}Arn`
|
|
331
|
+
- The ARN output is exported with `Export.Name = ${AWS::StackName}-${outputArnName}`
|
|
306
332
|
- `memorySize` (number, optional): Lambda memory size in MB. Default: `128`
|
|
307
333
|
- `timeout` (number, optional): Lambda timeout in seconds. Default: `30`
|
|
334
|
+
- `deletionProtection` (boolean, optional): Adds `DeletionPolicy: Retain` and `UpdateReplacePolicy: Retain` to each Lambda resource so stack updates/deletes do not remove functions. Default: `false`
|
|
308
335
|
|
|
309
336
|
#### Returns
|
|
310
337
|
|
|
@@ -26,9 +26,10 @@ type CreateLambdaPostgresQueryTemplateOptions = {
|
|
|
26
26
|
functions?: LambdaDefinition[];
|
|
27
27
|
memorySize?: number;
|
|
28
28
|
timeout?: number;
|
|
29
|
+
deletionProtection?: boolean;
|
|
29
30
|
};
|
|
30
31
|
declare const DATABASE_PARAMETERS_DEFAULT: DatabaseParameters;
|
|
31
|
-
declare const createLambdaPostgresQueryTemplate: ({ functions, memorySize, timeout, }?: CreateLambdaPostgresQueryTemplateOptions) => CloudFormationTemplate;
|
|
32
|
+
declare const createLambdaPostgresQueryTemplate: ({ functions, memorySize, timeout, deletionProtection, }?: CreateLambdaPostgresQueryTemplateOptions) => CloudFormationTemplate;
|
|
32
33
|
|
|
33
34
|
declare const handler: Handler<QueryParams>;
|
|
34
35
|
|
|
@@ -26,9 +26,10 @@ type CreateLambdaPostgresQueryTemplateOptions = {
|
|
|
26
26
|
functions?: LambdaDefinition[];
|
|
27
27
|
memorySize?: number;
|
|
28
28
|
timeout?: number;
|
|
29
|
+
deletionProtection?: boolean;
|
|
29
30
|
};
|
|
30
31
|
declare const DATABASE_PARAMETERS_DEFAULT: DatabaseParameters;
|
|
31
|
-
declare const createLambdaPostgresQueryTemplate: ({ functions, memorySize, timeout, }?: CreateLambdaPostgresQueryTemplateOptions) => CloudFormationTemplate;
|
|
32
|
+
declare const createLambdaPostgresQueryTemplate: ({ functions, memorySize, timeout, deletionProtection, }?: CreateLambdaPostgresQueryTemplateOptions) => CloudFormationTemplate;
|
|
32
33
|
|
|
33
34
|
declare const handler: Handler<QueryParams>;
|
|
34
35
|
|
|
@@ -147,11 +147,17 @@ var createLambdaResource = /* @__PURE__ */__name(({
|
|
|
147
147
|
handler: handler2,
|
|
148
148
|
databaseParameters,
|
|
149
149
|
memorySize,
|
|
150
|
-
timeout
|
|
150
|
+
timeout,
|
|
151
|
+
deletionProtection
|
|
151
152
|
}) => {
|
|
153
|
+
const resourcePolicies = deletionProtection ? {
|
|
154
|
+
DeletionPolicy: "Retain",
|
|
155
|
+
UpdateReplacePolicy: "Retain"
|
|
156
|
+
} : {};
|
|
152
157
|
return {
|
|
153
158
|
[functionName]: {
|
|
154
159
|
Type: "AWS::Lambda::Function",
|
|
160
|
+
...resourcePolicies,
|
|
155
161
|
Properties: {
|
|
156
162
|
Code: {
|
|
157
163
|
S3Bucket: {
|
|
@@ -223,7 +229,8 @@ var createLambdaLogResource = /* @__PURE__ */__name(({
|
|
|
223
229
|
var createResources = /* @__PURE__ */__name(({
|
|
224
230
|
functions,
|
|
225
231
|
memorySize,
|
|
226
|
-
timeout
|
|
232
|
+
timeout,
|
|
233
|
+
deletionProtection
|
|
227
234
|
}) => {
|
|
228
235
|
return functions.reduce((allResources, lambdaFunction) => {
|
|
229
236
|
const {
|
|
@@ -238,7 +245,8 @@ var createResources = /* @__PURE__ */__name(({
|
|
|
238
245
|
handler: handler2,
|
|
239
246
|
databaseParameters,
|
|
240
247
|
memorySize,
|
|
241
|
-
timeout
|
|
248
|
+
timeout,
|
|
249
|
+
deletionProtection
|
|
242
250
|
}),
|
|
243
251
|
...createLambdaLogResource({
|
|
244
252
|
logicalId: name
|
|
@@ -266,6 +274,11 @@ var createOutputs = /* @__PURE__ */__name(({
|
|
|
266
274
|
Description: `Lambda function to query PostgreSQL (${name}) ARN.`,
|
|
267
275
|
Value: {
|
|
268
276
|
"Fn::GetAtt": [name, "Arn"]
|
|
277
|
+
},
|
|
278
|
+
Export: {
|
|
279
|
+
Name: {
|
|
280
|
+
"Fn::Sub": `\${AWS::StackName}-${outputArnName}`
|
|
281
|
+
}
|
|
269
282
|
}
|
|
270
283
|
}
|
|
271
284
|
};
|
|
@@ -321,7 +334,8 @@ var createExecutionRoleResource = /* @__PURE__ */__name(() => {
|
|
|
321
334
|
var createLambdaPostgresQueryTemplate = /* @__PURE__ */__name(({
|
|
322
335
|
functions,
|
|
323
336
|
memorySize = MEMORY_SIZE_DEFAULT,
|
|
324
|
-
timeout = TIMEOUT_DEFAULT
|
|
337
|
+
timeout = TIMEOUT_DEFAULT,
|
|
338
|
+
deletionProtection = false
|
|
325
339
|
} = {}) => {
|
|
326
340
|
const templateFunctions = normalizeFunctions({
|
|
327
341
|
functions
|
|
@@ -332,7 +346,8 @@ var createLambdaPostgresQueryTemplate = /* @__PURE__ */__name(({
|
|
|
332
346
|
const templateResources = createResources({
|
|
333
347
|
functions: templateFunctions,
|
|
334
348
|
memorySize,
|
|
335
|
-
timeout
|
|
349
|
+
timeout,
|
|
350
|
+
deletionProtection
|
|
336
351
|
});
|
|
337
352
|
const templateOutputs = createOutputs({
|
|
338
353
|
functions: templateFunctions
|
|
@@ -107,11 +107,17 @@ var createLambdaResource = /* @__PURE__ */__name(({
|
|
|
107
107
|
handler: handler2,
|
|
108
108
|
databaseParameters,
|
|
109
109
|
memorySize,
|
|
110
|
-
timeout
|
|
110
|
+
timeout,
|
|
111
|
+
deletionProtection
|
|
111
112
|
}) => {
|
|
113
|
+
const resourcePolicies = deletionProtection ? {
|
|
114
|
+
DeletionPolicy: "Retain",
|
|
115
|
+
UpdateReplacePolicy: "Retain"
|
|
116
|
+
} : {};
|
|
112
117
|
return {
|
|
113
118
|
[functionName]: {
|
|
114
119
|
Type: "AWS::Lambda::Function",
|
|
120
|
+
...resourcePolicies,
|
|
115
121
|
Properties: {
|
|
116
122
|
Code: {
|
|
117
123
|
S3Bucket: {
|
|
@@ -183,7 +189,8 @@ var createLambdaLogResource = /* @__PURE__ */__name(({
|
|
|
183
189
|
var createResources = /* @__PURE__ */__name(({
|
|
184
190
|
functions,
|
|
185
191
|
memorySize,
|
|
186
|
-
timeout
|
|
192
|
+
timeout,
|
|
193
|
+
deletionProtection
|
|
187
194
|
}) => {
|
|
188
195
|
return functions.reduce((allResources, lambdaFunction) => {
|
|
189
196
|
const {
|
|
@@ -198,7 +205,8 @@ var createResources = /* @__PURE__ */__name(({
|
|
|
198
205
|
handler: handler2,
|
|
199
206
|
databaseParameters,
|
|
200
207
|
memorySize,
|
|
201
|
-
timeout
|
|
208
|
+
timeout,
|
|
209
|
+
deletionProtection
|
|
202
210
|
}),
|
|
203
211
|
...createLambdaLogResource({
|
|
204
212
|
logicalId: name
|
|
@@ -226,6 +234,11 @@ var createOutputs = /* @__PURE__ */__name(({
|
|
|
226
234
|
Description: `Lambda function to query PostgreSQL (${name}) ARN.`,
|
|
227
235
|
Value: {
|
|
228
236
|
"Fn::GetAtt": [name, "Arn"]
|
|
237
|
+
},
|
|
238
|
+
Export: {
|
|
239
|
+
Name: {
|
|
240
|
+
"Fn::Sub": `\${AWS::StackName}-${outputArnName}`
|
|
241
|
+
}
|
|
229
242
|
}
|
|
230
243
|
}
|
|
231
244
|
};
|
|
@@ -281,7 +294,8 @@ var createExecutionRoleResource = /* @__PURE__ */__name(() => {
|
|
|
281
294
|
var createLambdaPostgresQueryTemplate = /* @__PURE__ */__name(({
|
|
282
295
|
functions,
|
|
283
296
|
memorySize = MEMORY_SIZE_DEFAULT,
|
|
284
|
-
timeout = TIMEOUT_DEFAULT
|
|
297
|
+
timeout = TIMEOUT_DEFAULT,
|
|
298
|
+
deletionProtection = false
|
|
285
299
|
} = {}) => {
|
|
286
300
|
const templateFunctions = normalizeFunctions({
|
|
287
301
|
functions
|
|
@@ -292,7 +306,8 @@ var createLambdaPostgresQueryTemplate = /* @__PURE__ */__name(({
|
|
|
292
306
|
const templateResources = createResources({
|
|
293
307
|
functions: templateFunctions,
|
|
294
308
|
memorySize,
|
|
295
|
-
timeout
|
|
309
|
+
timeout,
|
|
310
|
+
deletionProtection
|
|
296
311
|
});
|
|
297
312
|
const templateOutputs = createOutputs({
|
|
298
313
|
functions: templateFunctions
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/lambda-postgres-query",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Create a Lambda function that queries a PostgreSQL database.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@aws-sdk/client-lambda": "^3.1025.0",
|
|
38
38
|
"camelcase-keys": "^7.0.2",
|
|
39
39
|
"pg": "^8.20.0",
|
|
40
|
-
"@ttoss/cloudformation": "^0.
|
|
40
|
+
"@ttoss/cloudformation": "^0.13.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/jest": "^30.0.0",
|