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