@ttoss/lambda-postgres-query 0.6.2 → 1.1.0
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 +240 -56
- package/dist/cloudformation/index.d.cts +21 -7
- package/dist/cloudformation/index.d.ts +21 -7
- package/dist/cloudformation/index.js +305 -304
- package/dist/esm/cloudformation/index.js +300 -299
- package/dist/esm/index.js +2 -2
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +13 -13
|
@@ -3,268 +3,327 @@ import { __name } from "../chunk-V4MHYKRI.js";
|
|
|
3
3
|
|
|
4
4
|
// src/cloudformation/createLambdaPostgresQueryTemplate.ts
|
|
5
5
|
var HANDLER_DEFAULT = "handler.handler";
|
|
6
|
-
var
|
|
6
|
+
var LAMBDA_POSTGRES_QUERY_FUNCTION_DEFAULT_NAME = "LambdaPostgresQueryFunction";
|
|
7
7
|
var MEMORY_SIZE_DEFAULT = 128;
|
|
8
8
|
var TIMEOUT_DEFAULT = 30;
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
var DATABASE_PARAMETERS_DEFAULT = {
|
|
10
|
+
host: "DatabaseHost",
|
|
11
|
+
name: "DatabaseName",
|
|
12
|
+
username: "DatabaseUsername",
|
|
13
|
+
password: "DatabasePassword",
|
|
14
|
+
port: "DatabasePort"
|
|
15
|
+
};
|
|
16
|
+
var createParameter = /* @__PURE__ */__name(({
|
|
17
|
+
description,
|
|
18
|
+
noEcho,
|
|
19
|
+
defaultValue
|
|
20
|
+
}) => {
|
|
15
21
|
return {
|
|
16
|
-
|
|
17
|
-
Description:
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
"Fn::GetAtt": ["LambdaQueryExecutionRole", "Arn"]
|
|
22
|
+
Type: "String",
|
|
23
|
+
Description: description,
|
|
24
|
+
...(noEcho ? {
|
|
25
|
+
NoEcho: true
|
|
26
|
+
} : {}),
|
|
27
|
+
...(defaultValue ? {
|
|
28
|
+
Default: defaultValue
|
|
29
|
+
} : {})
|
|
30
|
+
};
|
|
31
|
+
}, "createParameter");
|
|
32
|
+
var createDefaultFunction = /* @__PURE__ */__name(() => {
|
|
33
|
+
return {
|
|
34
|
+
name: LAMBDA_POSTGRES_QUERY_FUNCTION_DEFAULT_NAME,
|
|
35
|
+
handler: HANDLER_DEFAULT,
|
|
36
|
+
databaseParameters: DATABASE_PARAMETERS_DEFAULT,
|
|
37
|
+
outputArnName: "LambdaPostgresQueryFunctionArn"
|
|
38
|
+
};
|
|
39
|
+
}, "createDefaultFunction");
|
|
40
|
+
var resolveFunctionName = /* @__PURE__ */__name(({
|
|
41
|
+
name,
|
|
42
|
+
logicalId
|
|
43
|
+
}) => {
|
|
44
|
+
const functionName = name || logicalId;
|
|
45
|
+
return functionName || LAMBDA_POSTGRES_QUERY_FUNCTION_DEFAULT_NAME;
|
|
46
|
+
}, "resolveFunctionName");
|
|
47
|
+
var normalizeFunctions = /* @__PURE__ */__name(({
|
|
48
|
+
functions
|
|
49
|
+
}) => {
|
|
50
|
+
if (!functions?.length) {
|
|
51
|
+
return [createDefaultFunction()];
|
|
52
|
+
}
|
|
53
|
+
return functions.map(lambdaFunction => {
|
|
54
|
+
const functionName = resolveFunctionName({
|
|
55
|
+
name: lambdaFunction.name,
|
|
56
|
+
logicalId: lambdaFunction.logicalId
|
|
57
|
+
});
|
|
58
|
+
return {
|
|
59
|
+
name: functionName,
|
|
60
|
+
handler: lambdaFunction.handler || HANDLER_DEFAULT,
|
|
61
|
+
outputArnName: lambdaFunction.outputArnName || `${functionName}Arn`,
|
|
62
|
+
databaseParameters: lambdaFunction.databaseParameters || DATABASE_PARAMETERS_DEFAULT
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}, "normalizeFunctions");
|
|
66
|
+
var createDatabaseParametersForFunction = /* @__PURE__ */__name(({
|
|
67
|
+
databaseParameters,
|
|
68
|
+
functionName,
|
|
69
|
+
allParameters
|
|
70
|
+
}) => {
|
|
71
|
+
return {
|
|
72
|
+
[databaseParameters.host]: allParameters[databaseParameters.host] || createParameter({
|
|
73
|
+
description: `Database host for ${functionName}.`
|
|
74
|
+
}),
|
|
75
|
+
[databaseParameters.name]: allParameters[databaseParameters.name] || createParameter({
|
|
76
|
+
description: `Database name for ${functionName}.`
|
|
77
|
+
}),
|
|
78
|
+
[databaseParameters.username]: allParameters[databaseParameters.username] || createParameter({
|
|
79
|
+
description: `Database username for ${functionName}.`
|
|
80
|
+
}),
|
|
81
|
+
[databaseParameters.password]: allParameters[databaseParameters.password] || createParameter({
|
|
82
|
+
description: `Database password for ${functionName}.`,
|
|
83
|
+
noEcho: true
|
|
84
|
+
}),
|
|
85
|
+
[databaseParameters.port]: allParameters[databaseParameters.port] || createParameter({
|
|
86
|
+
description: `Database port for ${functionName}.`,
|
|
87
|
+
defaultValue: "5432"
|
|
88
|
+
})
|
|
89
|
+
};
|
|
90
|
+
}, "createDatabaseParametersForFunction");
|
|
91
|
+
var createCredentialsParameters = /* @__PURE__ */__name(({
|
|
92
|
+
functions
|
|
93
|
+
}) => {
|
|
94
|
+
return functions.reduce((allParameters, lambdaFunction) => {
|
|
95
|
+
return {
|
|
96
|
+
...allParameters,
|
|
97
|
+
...createDatabaseParametersForFunction({
|
|
98
|
+
databaseParameters: lambdaFunction.databaseParameters,
|
|
99
|
+
functionName: lambdaFunction.name,
|
|
100
|
+
allParameters
|
|
101
|
+
})
|
|
102
|
+
};
|
|
103
|
+
}, {});
|
|
104
|
+
}, "createCredentialsParameters");
|
|
105
|
+
var createLambdaResource = /* @__PURE__ */__name(({
|
|
106
|
+
functionName,
|
|
107
|
+
handler: handler2,
|
|
108
|
+
databaseParameters,
|
|
109
|
+
memorySize,
|
|
110
|
+
timeout,
|
|
111
|
+
deletionProtection
|
|
112
|
+
}) => {
|
|
113
|
+
const resourcePolicies = deletionProtection ? {
|
|
114
|
+
DeletionPolicy: "Retain",
|
|
115
|
+
UpdateReplacePolicy: "Retain"
|
|
116
|
+
} : {};
|
|
117
|
+
return {
|
|
118
|
+
[functionName]: {
|
|
119
|
+
Type: "AWS::Lambda::Function",
|
|
120
|
+
...resourcePolicies,
|
|
121
|
+
Properties: {
|
|
122
|
+
Code: {
|
|
123
|
+
S3Bucket: {
|
|
124
|
+
Ref: "LambdaS3Bucket"
|
|
120
125
|
},
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
Variables: {
|
|
124
|
-
DATABASE_HOST: {
|
|
125
|
-
Ref: "DatabaseHost"
|
|
126
|
-
},
|
|
127
|
-
DATABASE_NAME: {
|
|
128
|
-
Ref: "DatabaseName"
|
|
129
|
-
},
|
|
130
|
-
DATABASE_USERNAME: {
|
|
131
|
-
Ref: "DatabaseUsername"
|
|
132
|
-
},
|
|
133
|
-
DATABASE_PASSWORD: {
|
|
134
|
-
Ref: "DatabasePassword"
|
|
135
|
-
},
|
|
136
|
-
DATABASE_PORT: {
|
|
137
|
-
Ref: "DatabasePort"
|
|
138
|
-
}
|
|
139
|
-
}
|
|
126
|
+
S3Key: {
|
|
127
|
+
Ref: "LambdaS3Key"
|
|
140
128
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Ref: "SecurityGroupIds"
|
|
144
|
-
},
|
|
145
|
-
SubnetIds: {
|
|
146
|
-
Ref: "SubnetIds"
|
|
147
|
-
}
|
|
129
|
+
S3ObjectVersion: {
|
|
130
|
+
Ref: "LambdaS3ObjectVersion"
|
|
148
131
|
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
LambdaReadOnlyQueryFunction: {
|
|
164
|
-
Type: "AWS::Lambda::Function",
|
|
165
|
-
Properties: {
|
|
166
|
-
Code: {
|
|
167
|
-
S3Bucket: {
|
|
168
|
-
Ref: "LambdaS3Bucket"
|
|
132
|
+
},
|
|
133
|
+
MemorySize: memorySize,
|
|
134
|
+
Timeout: timeout,
|
|
135
|
+
Handler: handler2,
|
|
136
|
+
Role: {
|
|
137
|
+
"Fn::GetAtt": ["LambdaQueryExecutionRole", "Arn"]
|
|
138
|
+
},
|
|
139
|
+
Runtime: "nodejs24.x",
|
|
140
|
+
Environment: {
|
|
141
|
+
Variables: {
|
|
142
|
+
DATABASE_HOST: {
|
|
143
|
+
Ref: databaseParameters.host
|
|
169
144
|
},
|
|
170
|
-
|
|
171
|
-
Ref:
|
|
145
|
+
DATABASE_NAME: {
|
|
146
|
+
Ref: databaseParameters.name
|
|
172
147
|
},
|
|
173
|
-
|
|
174
|
-
Ref:
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
MemorySize: memorySize,
|
|
178
|
-
Timeout: timeout,
|
|
179
|
-
Handler: readOnlyHandler2,
|
|
180
|
-
Role: {
|
|
181
|
-
"Fn::GetAtt": ["LambdaQueryExecutionRole", "Arn"]
|
|
182
|
-
},
|
|
183
|
-
Runtime: "nodejs24.x",
|
|
184
|
-
Environment: {
|
|
185
|
-
Variables: {
|
|
186
|
-
DATABASE_HOST: {
|
|
187
|
-
Ref: "DatabaseHost"
|
|
188
|
-
},
|
|
189
|
-
DATABASE_NAME: {
|
|
190
|
-
Ref: "DatabaseName"
|
|
191
|
-
},
|
|
192
|
-
DATABASE_USERNAME: {
|
|
193
|
-
Ref: "DatabaseUsername"
|
|
194
|
-
},
|
|
195
|
-
DATABASE_PASSWORD: {
|
|
196
|
-
Ref: "DatabasePassword"
|
|
197
|
-
},
|
|
198
|
-
DATABASE_PORT: {
|
|
199
|
-
Ref: "DatabasePort"
|
|
200
|
-
},
|
|
201
|
-
DATABASE_HOST_READ_ONLY: {
|
|
202
|
-
Ref: "DatabaseHostReadOnly"
|
|
203
|
-
},
|
|
204
|
-
DATABASE_NAME_READ_ONLY: {
|
|
205
|
-
Ref: "DatabaseNameReadOnly"
|
|
206
|
-
},
|
|
207
|
-
DATABASE_USERNAME_READ_ONLY: {
|
|
208
|
-
Ref: "DatabaseUsernameReadOnly"
|
|
209
|
-
},
|
|
210
|
-
DATABASE_PASSWORD_READ_ONLY: {
|
|
211
|
-
Ref: "DatabasePasswordReadOnly"
|
|
212
|
-
},
|
|
213
|
-
DATABASE_PORT_READ_ONLY: {
|
|
214
|
-
Ref: "DatabasePortReadOnly"
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
VpcConfig: {
|
|
219
|
-
SecurityGroupIds: {
|
|
220
|
-
Ref: "SecurityGroupIds"
|
|
148
|
+
DATABASE_USERNAME: {
|
|
149
|
+
Ref: databaseParameters.username
|
|
221
150
|
},
|
|
222
|
-
|
|
223
|
-
Ref:
|
|
151
|
+
DATABASE_PASSWORD: {
|
|
152
|
+
Ref: databaseParameters.password
|
|
153
|
+
},
|
|
154
|
+
DATABASE_PORT: {
|
|
155
|
+
Ref: databaseParameters.port
|
|
224
156
|
}
|
|
225
157
|
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
DependsOn: "LambdaReadOnlyQueryFunction",
|
|
231
|
-
Properties: {
|
|
232
|
-
LogGroupName: {
|
|
233
|
-
"Fn::Join": ["", ["/aws/lambda/", {
|
|
234
|
-
Ref: "LambdaReadOnlyQueryFunction"
|
|
235
|
-
}]]
|
|
158
|
+
},
|
|
159
|
+
VpcConfig: {
|
|
160
|
+
SecurityGroupIds: {
|
|
161
|
+
Ref: "SecurityGroupIds"
|
|
236
162
|
},
|
|
237
|
-
|
|
163
|
+
SubnetIds: {
|
|
164
|
+
Ref: "SubnetIds"
|
|
165
|
+
}
|
|
238
166
|
}
|
|
239
167
|
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
}, "createLambdaResource");
|
|
171
|
+
var createLambdaLogResource = /* @__PURE__ */__name(({
|
|
172
|
+
logicalId
|
|
173
|
+
}) => {
|
|
174
|
+
return {
|
|
175
|
+
[`${logicalId}Logs`]: {
|
|
176
|
+
Type: "AWS::Logs::LogGroup",
|
|
177
|
+
DependsOn: logicalId,
|
|
178
|
+
Properties: {
|
|
179
|
+
LogGroupName: {
|
|
180
|
+
"Fn::Join": ["", ["/aws/lambda/", {
|
|
181
|
+
Ref: logicalId
|
|
182
|
+
}]]
|
|
183
|
+
},
|
|
184
|
+
RetentionInDays: 3
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
}, "createLambdaLogResource");
|
|
189
|
+
var createResources = /* @__PURE__ */__name(({
|
|
190
|
+
functions,
|
|
191
|
+
memorySize,
|
|
192
|
+
timeout,
|
|
193
|
+
deletionProtection
|
|
194
|
+
}) => {
|
|
195
|
+
return functions.reduce((allResources, lambdaFunction) => {
|
|
196
|
+
const {
|
|
197
|
+
name,
|
|
198
|
+
handler: handler2,
|
|
199
|
+
databaseParameters
|
|
200
|
+
} = lambdaFunction;
|
|
201
|
+
return {
|
|
202
|
+
...allResources,
|
|
203
|
+
...createLambdaResource({
|
|
204
|
+
functionName: name,
|
|
205
|
+
handler: handler2,
|
|
206
|
+
databaseParameters,
|
|
207
|
+
memorySize,
|
|
208
|
+
timeout,
|
|
209
|
+
deletionProtection
|
|
210
|
+
}),
|
|
211
|
+
...createLambdaLogResource({
|
|
212
|
+
logicalId: name
|
|
213
|
+
})
|
|
214
|
+
};
|
|
215
|
+
}, {});
|
|
216
|
+
}, "createResources");
|
|
217
|
+
var createOutputs = /* @__PURE__ */__name(({
|
|
218
|
+
functions
|
|
219
|
+
}) => {
|
|
220
|
+
return functions.reduce((allOutputs, lambdaFunction) => {
|
|
221
|
+
const {
|
|
222
|
+
name,
|
|
223
|
+
outputArnName
|
|
224
|
+
} = lambdaFunction;
|
|
225
|
+
return {
|
|
226
|
+
...allOutputs,
|
|
227
|
+
[name]: {
|
|
228
|
+
Description: `Lambda function to query PostgreSQL (${name}).`,
|
|
256
229
|
Value: {
|
|
257
|
-
Ref:
|
|
230
|
+
Ref: name
|
|
258
231
|
}
|
|
259
232
|
},
|
|
260
|
-
|
|
261
|
-
Description:
|
|
233
|
+
[outputArnName]: {
|
|
234
|
+
Description: `Lambda function to query PostgreSQL (${name}) ARN.`,
|
|
262
235
|
Value: {
|
|
263
|
-
"Fn::GetAtt": [
|
|
236
|
+
"Fn::GetAtt": [name, "Arn"]
|
|
237
|
+
},
|
|
238
|
+
Export: {
|
|
239
|
+
Name: {
|
|
240
|
+
"Fn::Sub": `\${AWS::StackName}-${outputArnName}`
|
|
241
|
+
}
|
|
264
242
|
}
|
|
265
243
|
}
|
|
244
|
+
};
|
|
245
|
+
}, {});
|
|
246
|
+
}, "createOutputs");
|
|
247
|
+
var createTemplateParameters = /* @__PURE__ */__name(({
|
|
248
|
+
credentialsParameters
|
|
249
|
+
}) => {
|
|
250
|
+
return {
|
|
251
|
+
...credentialsParameters,
|
|
252
|
+
LambdaS3Bucket: {
|
|
253
|
+
Type: "String",
|
|
254
|
+
Description: "The S3 bucket where the Lambda code is stored."
|
|
255
|
+
},
|
|
256
|
+
LambdaS3Key: {
|
|
257
|
+
Type: "String",
|
|
258
|
+
Description: "The S3 key where the Lambda code is stored."
|
|
259
|
+
},
|
|
260
|
+
LambdaS3ObjectVersion: {
|
|
261
|
+
Type: "String",
|
|
262
|
+
Description: "The S3 object version of the Lambda code."
|
|
263
|
+
},
|
|
264
|
+
SecurityGroupIds: {
|
|
265
|
+
Description: "Security Group IDs",
|
|
266
|
+
Type: "List<AWS::EC2::SecurityGroup::Id>"
|
|
267
|
+
},
|
|
268
|
+
SubnetIds: {
|
|
269
|
+
Description: "Subnet IDs",
|
|
270
|
+
Type: "List<AWS::EC2::Subnet::Id>"
|
|
266
271
|
}
|
|
267
272
|
};
|
|
273
|
+
}, "createTemplateParameters");
|
|
274
|
+
var createExecutionRoleResource = /* @__PURE__ */__name(() => {
|
|
275
|
+
return {
|
|
276
|
+
LambdaQueryExecutionRole: {
|
|
277
|
+
Type: "AWS::IAM::Role",
|
|
278
|
+
Properties: {
|
|
279
|
+
AssumeRolePolicyDocument: {
|
|
280
|
+
Version: "2012-10-17",
|
|
281
|
+
Statement: [{
|
|
282
|
+
Effect: "Allow",
|
|
283
|
+
Principal: {
|
|
284
|
+
Service: "lambda.amazonaws.com"
|
|
285
|
+
},
|
|
286
|
+
Action: "sts:AssumeRole"
|
|
287
|
+
}]
|
|
288
|
+
},
|
|
289
|
+
ManagedPolicyArns: ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"]
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}, "createExecutionRoleResource");
|
|
294
|
+
var createLambdaPostgresQueryTemplate = /* @__PURE__ */__name(({
|
|
295
|
+
functions,
|
|
296
|
+
memorySize = MEMORY_SIZE_DEFAULT,
|
|
297
|
+
timeout = TIMEOUT_DEFAULT,
|
|
298
|
+
deletionProtection = false
|
|
299
|
+
} = {}) => {
|
|
300
|
+
const templateFunctions = normalizeFunctions({
|
|
301
|
+
functions
|
|
302
|
+
});
|
|
303
|
+
const credentialsParameters = createCredentialsParameters({
|
|
304
|
+
functions: templateFunctions
|
|
305
|
+
});
|
|
306
|
+
const templateResources = createResources({
|
|
307
|
+
functions: templateFunctions,
|
|
308
|
+
memorySize,
|
|
309
|
+
timeout,
|
|
310
|
+
deletionProtection
|
|
311
|
+
});
|
|
312
|
+
const templateOutputs = createOutputs({
|
|
313
|
+
functions: templateFunctions
|
|
314
|
+
});
|
|
315
|
+
return {
|
|
316
|
+
AWSTemplateFormatVersion: "2010-09-09",
|
|
317
|
+
Description: "A Lambda function to query PostgreSQL.",
|
|
318
|
+
Parameters: createTemplateParameters({
|
|
319
|
+
credentialsParameters
|
|
320
|
+
}),
|
|
321
|
+
Resources: {
|
|
322
|
+
...createExecutionRoleResource(),
|
|
323
|
+
...templateResources
|
|
324
|
+
},
|
|
325
|
+
Outputs: templateOutputs
|
|
326
|
+
};
|
|
268
327
|
}, "createLambdaPostgresQueryTemplate");
|
|
269
328
|
|
|
270
329
|
// src/cloudformation/lambdaQueryHandler.ts
|
|
@@ -298,62 +357,4 @@ var handler = /* @__PURE__ */__name(async event => {
|
|
|
298
357
|
throw error;
|
|
299
358
|
}
|
|
300
359
|
}, "handler");
|
|
301
|
-
|
|
302
|
-
// src/cloudformation/lambdaReadOnlyQueryHandler.ts
|
|
303
|
-
import { Client as Client2 } from "pg";
|
|
304
|
-
var databaseReadOnly = process.env.DATABASE_NAME_READ_ONLY;
|
|
305
|
-
var usernameReadOnly = process.env.DATABASE_USERNAME_READ_ONLY;
|
|
306
|
-
var passwordReadOnly = process.env.DATABASE_PASSWORD_READ_ONLY;
|
|
307
|
-
var hostReadOnly = process.env.DATABASE_HOST_READ_ONLY;
|
|
308
|
-
var portReadOnly = process.env.DATABASE_PORT_READ_ONLY;
|
|
309
|
-
var getConnectionConfig = /* @__PURE__ */__name(() => {
|
|
310
|
-
return {
|
|
311
|
-
database: databaseReadOnly || process.env.DATABASE_NAME,
|
|
312
|
-
username: usernameReadOnly || process.env.DATABASE_USERNAME,
|
|
313
|
-
password: passwordReadOnly || process.env.DATABASE_PASSWORD,
|
|
314
|
-
host: hostReadOnly || process.env.DATABASE_HOST,
|
|
315
|
-
port: portReadOnly || process.env.DATABASE_PORT
|
|
316
|
-
};
|
|
317
|
-
}, "getConnectionConfig");
|
|
318
|
-
var readOnlyHandler = /* @__PURE__ */__name(async event => {
|
|
319
|
-
if (!databaseReadOnly && !usernameReadOnly && !passwordReadOnly && !hostReadOnly && !portReadOnly) {
|
|
320
|
-
throw new Error("At least one read-only override must be defined (DATABASE_NAME_READ_ONLY, DATABASE_USERNAME_READ_ONLY, DATABASE_PASSWORD_READ_ONLY, DATABASE_HOST_READ_ONLY, DATABASE_PORT_READ_ONLY). Unset overrides fall back to the corresponding non-read-only env vars.");
|
|
321
|
-
}
|
|
322
|
-
const {
|
|
323
|
-
database: database2,
|
|
324
|
-
username: username2,
|
|
325
|
-
password: password2,
|
|
326
|
-
host: host2,
|
|
327
|
-
port: port2
|
|
328
|
-
} = getConnectionConfig();
|
|
329
|
-
try {
|
|
330
|
-
const client = new Client2({
|
|
331
|
-
database: database2,
|
|
332
|
-
user: username2,
|
|
333
|
-
password: password2,
|
|
334
|
-
host: host2,
|
|
335
|
-
port: Number(port2)
|
|
336
|
-
});
|
|
337
|
-
await client.connect();
|
|
338
|
-
try {
|
|
339
|
-
await client.query("BEGIN READ ONLY");
|
|
340
|
-
try {
|
|
341
|
-
const res = await client.query(event);
|
|
342
|
-
await client.query("COMMIT");
|
|
343
|
-
return res;
|
|
344
|
-
} catch (queryError) {
|
|
345
|
-
await client.query("ROLLBACK");
|
|
346
|
-
throw queryError;
|
|
347
|
-
}
|
|
348
|
-
} finally {
|
|
349
|
-
await client.end();
|
|
350
|
-
}
|
|
351
|
-
} catch (error) {
|
|
352
|
-
console.error("Error running read-only query", {
|
|
353
|
-
error,
|
|
354
|
-
event
|
|
355
|
-
});
|
|
356
|
-
throw error;
|
|
357
|
-
}
|
|
358
|
-
}, "readOnlyHandler");
|
|
359
|
-
export { HANDLER_DEFAULT, HANDLER_READ_ONLY_DEFAULT, MEMORY_SIZE_DEFAULT, TIMEOUT_DEFAULT, createLambdaPostgresQueryTemplate, handler, readOnlyHandler };
|
|
360
|
+
export { DATABASE_PARAMETERS_DEFAULT, HANDLER_DEFAULT, LAMBDA_POSTGRES_QUERY_FUNCTION_DEFAULT_NAME, MEMORY_SIZE_DEFAULT, TIMEOUT_DEFAULT, createLambdaPostgresQueryTemplate, handler };
|
package/dist/esm/index.js
CHANGED
|
@@ -9,14 +9,14 @@ var textDecoder = new TextDecoder("utf-8");
|
|
|
9
9
|
var query = /* @__PURE__ */__name(async params => {
|
|
10
10
|
try {
|
|
11
11
|
const {
|
|
12
|
-
|
|
12
|
+
functionName,
|
|
13
13
|
camelCaseKeys = true,
|
|
14
14
|
...pgParams
|
|
15
15
|
} = typeof params === "string" ? {
|
|
16
16
|
text: params
|
|
17
17
|
} : params;
|
|
18
18
|
const input = {
|
|
19
|
-
FunctionName:
|
|
19
|
+
FunctionName: functionName || process.env.LAMBDA_POSTGRES_QUERY_FUNCTION_NAME,
|
|
20
20
|
Payload: JSON.stringify({
|
|
21
21
|
...pgParams
|
|
22
22
|
})
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED