@ttoss/lambda-postgres-query 0.6.1 → 1.0.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 +213 -56
- package/dist/cloudformation/index.d.cts +20 -7
- package/dist/cloudformation/index.d.ts +20 -7
- package/dist/cloudformation/index.js +290 -293
- package/dist/esm/cloudformation/index.js +285 -288
- package/dist/esm/index.js +2 -3
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -3
- package/package.json +13 -13
|
@@ -3,268 +3,312 @@ 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
|
-
MemorySize: memorySize,
|
|
116
|
-
Timeout: timeout,
|
|
117
|
-
Handler: handler2,
|
|
118
|
-
Role: {
|
|
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
|
+
}) => {
|
|
112
|
+
return {
|
|
113
|
+
[functionName]: {
|
|
114
|
+
Type: "AWS::Lambda::Function",
|
|
115
|
+
Properties: {
|
|
116
|
+
Code: {
|
|
117
|
+
S3Bucket: {
|
|
118
|
+
Ref: "LambdaS3Bucket"
|
|
120
119
|
},
|
|
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
|
-
}
|
|
120
|
+
S3Key: {
|
|
121
|
+
Ref: "LambdaS3Key"
|
|
140
122
|
},
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
Ref: "SecurityGroupIds"
|
|
144
|
-
},
|
|
145
|
-
SubnetIds: {
|
|
146
|
-
Ref: "SubnetIds"
|
|
147
|
-
}
|
|
123
|
+
S3ObjectVersion: {
|
|
124
|
+
Ref: "LambdaS3ObjectVersion"
|
|
148
125
|
}
|
|
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"
|
|
126
|
+
},
|
|
127
|
+
MemorySize: memorySize,
|
|
128
|
+
Timeout: timeout,
|
|
129
|
+
Handler: handler2,
|
|
130
|
+
Role: {
|
|
131
|
+
"Fn::GetAtt": ["LambdaQueryExecutionRole", "Arn"]
|
|
132
|
+
},
|
|
133
|
+
Runtime: "nodejs24.x",
|
|
134
|
+
Environment: {
|
|
135
|
+
Variables: {
|
|
136
|
+
DATABASE_HOST: {
|
|
137
|
+
Ref: databaseParameters.host
|
|
169
138
|
},
|
|
170
|
-
|
|
171
|
-
Ref:
|
|
139
|
+
DATABASE_NAME: {
|
|
140
|
+
Ref: databaseParameters.name
|
|
172
141
|
},
|
|
173
|
-
|
|
174
|
-
Ref:
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
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"
|
|
142
|
+
DATABASE_USERNAME: {
|
|
143
|
+
Ref: databaseParameters.username
|
|
144
|
+
},
|
|
145
|
+
DATABASE_PASSWORD: {
|
|
146
|
+
Ref: databaseParameters.password
|
|
221
147
|
},
|
|
222
|
-
|
|
223
|
-
Ref:
|
|
148
|
+
DATABASE_PORT: {
|
|
149
|
+
Ref: databaseParameters.port
|
|
224
150
|
}
|
|
225
151
|
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
DependsOn: "LambdaReadOnlyQueryFunction",
|
|
231
|
-
Properties: {
|
|
232
|
-
LogGroupName: {
|
|
233
|
-
"Fn::Join": ["", ["/aws/lambda/", {
|
|
234
|
-
Ref: "LambdaReadOnlyQueryFunction"
|
|
235
|
-
}]]
|
|
152
|
+
},
|
|
153
|
+
VpcConfig: {
|
|
154
|
+
SecurityGroupIds: {
|
|
155
|
+
Ref: "SecurityGroupIds"
|
|
236
156
|
},
|
|
237
|
-
|
|
157
|
+
SubnetIds: {
|
|
158
|
+
Ref: "SubnetIds"
|
|
159
|
+
}
|
|
238
160
|
}
|
|
239
161
|
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
}, "createLambdaResource");
|
|
165
|
+
var createLambdaLogResource = /* @__PURE__ */__name(({
|
|
166
|
+
logicalId
|
|
167
|
+
}) => {
|
|
168
|
+
return {
|
|
169
|
+
[`${logicalId}Logs`]: {
|
|
170
|
+
Type: "AWS::Logs::LogGroup",
|
|
171
|
+
DependsOn: logicalId,
|
|
172
|
+
Properties: {
|
|
173
|
+
LogGroupName: {
|
|
174
|
+
"Fn::Join": ["", ["/aws/lambda/", {
|
|
175
|
+
Ref: logicalId
|
|
176
|
+
}]]
|
|
177
|
+
},
|
|
178
|
+
RetentionInDays: 3
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}, "createLambdaLogResource");
|
|
183
|
+
var createResources = /* @__PURE__ */__name(({
|
|
184
|
+
functions,
|
|
185
|
+
memorySize,
|
|
186
|
+
timeout
|
|
187
|
+
}) => {
|
|
188
|
+
return functions.reduce((allResources, lambdaFunction) => {
|
|
189
|
+
const {
|
|
190
|
+
name,
|
|
191
|
+
handler: handler2,
|
|
192
|
+
databaseParameters
|
|
193
|
+
} = lambdaFunction;
|
|
194
|
+
return {
|
|
195
|
+
...allResources,
|
|
196
|
+
...createLambdaResource({
|
|
197
|
+
functionName: name,
|
|
198
|
+
handler: handler2,
|
|
199
|
+
databaseParameters,
|
|
200
|
+
memorySize,
|
|
201
|
+
timeout
|
|
202
|
+
}),
|
|
203
|
+
...createLambdaLogResource({
|
|
204
|
+
logicalId: name
|
|
205
|
+
})
|
|
206
|
+
};
|
|
207
|
+
}, {});
|
|
208
|
+
}, "createResources");
|
|
209
|
+
var createOutputs = /* @__PURE__ */__name(({
|
|
210
|
+
functions
|
|
211
|
+
}) => {
|
|
212
|
+
return functions.reduce((allOutputs, lambdaFunction) => {
|
|
213
|
+
const {
|
|
214
|
+
name,
|
|
215
|
+
outputArnName
|
|
216
|
+
} = lambdaFunction;
|
|
217
|
+
return {
|
|
218
|
+
...allOutputs,
|
|
219
|
+
[name]: {
|
|
220
|
+
Description: `Lambda function to query PostgreSQL (${name}).`,
|
|
256
221
|
Value: {
|
|
257
|
-
Ref:
|
|
222
|
+
Ref: name
|
|
258
223
|
}
|
|
259
224
|
},
|
|
260
|
-
|
|
261
|
-
Description:
|
|
225
|
+
[outputArnName]: {
|
|
226
|
+
Description: `Lambda function to query PostgreSQL (${name}) ARN.`,
|
|
262
227
|
Value: {
|
|
263
|
-
"Fn::GetAtt": [
|
|
228
|
+
"Fn::GetAtt": [name, "Arn"]
|
|
264
229
|
}
|
|
265
230
|
}
|
|
231
|
+
};
|
|
232
|
+
}, {});
|
|
233
|
+
}, "createOutputs");
|
|
234
|
+
var createTemplateParameters = /* @__PURE__ */__name(({
|
|
235
|
+
credentialsParameters
|
|
236
|
+
}) => {
|
|
237
|
+
return {
|
|
238
|
+
...credentialsParameters,
|
|
239
|
+
LambdaS3Bucket: {
|
|
240
|
+
Type: "String",
|
|
241
|
+
Description: "The S3 bucket where the Lambda code is stored."
|
|
242
|
+
},
|
|
243
|
+
LambdaS3Key: {
|
|
244
|
+
Type: "String",
|
|
245
|
+
Description: "The S3 key where the Lambda code is stored."
|
|
246
|
+
},
|
|
247
|
+
LambdaS3ObjectVersion: {
|
|
248
|
+
Type: "String",
|
|
249
|
+
Description: "The S3 object version of the Lambda code."
|
|
250
|
+
},
|
|
251
|
+
SecurityGroupIds: {
|
|
252
|
+
Description: "Security Group IDs",
|
|
253
|
+
Type: "List<AWS::EC2::SecurityGroup::Id>"
|
|
254
|
+
},
|
|
255
|
+
SubnetIds: {
|
|
256
|
+
Description: "Subnet IDs",
|
|
257
|
+
Type: "List<AWS::EC2::Subnet::Id>"
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}, "createTemplateParameters");
|
|
261
|
+
var createExecutionRoleResource = /* @__PURE__ */__name(() => {
|
|
262
|
+
return {
|
|
263
|
+
LambdaQueryExecutionRole: {
|
|
264
|
+
Type: "AWS::IAM::Role",
|
|
265
|
+
Properties: {
|
|
266
|
+
AssumeRolePolicyDocument: {
|
|
267
|
+
Version: "2012-10-17",
|
|
268
|
+
Statement: [{
|
|
269
|
+
Effect: "Allow",
|
|
270
|
+
Principal: {
|
|
271
|
+
Service: "lambda.amazonaws.com"
|
|
272
|
+
},
|
|
273
|
+
Action: "sts:AssumeRole"
|
|
274
|
+
}]
|
|
275
|
+
},
|
|
276
|
+
ManagedPolicyArns: ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole"]
|
|
277
|
+
}
|
|
266
278
|
}
|
|
267
279
|
};
|
|
280
|
+
}, "createExecutionRoleResource");
|
|
281
|
+
var createLambdaPostgresQueryTemplate = /* @__PURE__ */__name(({
|
|
282
|
+
functions,
|
|
283
|
+
memorySize = MEMORY_SIZE_DEFAULT,
|
|
284
|
+
timeout = TIMEOUT_DEFAULT
|
|
285
|
+
} = {}) => {
|
|
286
|
+
const templateFunctions = normalizeFunctions({
|
|
287
|
+
functions
|
|
288
|
+
});
|
|
289
|
+
const credentialsParameters = createCredentialsParameters({
|
|
290
|
+
functions: templateFunctions
|
|
291
|
+
});
|
|
292
|
+
const templateResources = createResources({
|
|
293
|
+
functions: templateFunctions,
|
|
294
|
+
memorySize,
|
|
295
|
+
timeout
|
|
296
|
+
});
|
|
297
|
+
const templateOutputs = createOutputs({
|
|
298
|
+
functions: templateFunctions
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
AWSTemplateFormatVersion: "2010-09-09",
|
|
302
|
+
Description: "A Lambda function to query PostgreSQL.",
|
|
303
|
+
Parameters: createTemplateParameters({
|
|
304
|
+
credentialsParameters
|
|
305
|
+
}),
|
|
306
|
+
Resources: {
|
|
307
|
+
...createExecutionRoleResource(),
|
|
308
|
+
...templateResources
|
|
309
|
+
},
|
|
310
|
+
Outputs: templateOutputs
|
|
311
|
+
};
|
|
268
312
|
}, "createLambdaPostgresQueryTemplate");
|
|
269
313
|
|
|
270
314
|
// src/cloudformation/lambdaQueryHandler.ts
|
|
@@ -298,51 +342,4 @@ var handler = /* @__PURE__ */__name(async event => {
|
|
|
298
342
|
throw error;
|
|
299
343
|
}
|
|
300
344
|
}, "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 readOnlyHandler = /* @__PURE__ */__name(async event => {
|
|
310
|
-
if (!databaseReadOnly && !usernameReadOnly && !passwordReadOnly && !hostReadOnly && !portReadOnly) {
|
|
311
|
-
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.");
|
|
312
|
-
}
|
|
313
|
-
const database2 = databaseReadOnly || process.env.DATABASE_NAME;
|
|
314
|
-
const username2 = usernameReadOnly || process.env.DATABASE_USERNAME;
|
|
315
|
-
const password2 = passwordReadOnly || process.env.DATABASE_PASSWORD;
|
|
316
|
-
const host2 = hostReadOnly || process.env.DATABASE_HOST;
|
|
317
|
-
const port2 = portReadOnly || process.env.DATABASE_PORT;
|
|
318
|
-
try {
|
|
319
|
-
const client = new Client2({
|
|
320
|
-
database: database2,
|
|
321
|
-
user: username2,
|
|
322
|
-
password: password2,
|
|
323
|
-
host: host2,
|
|
324
|
-
port: Number(port2)
|
|
325
|
-
});
|
|
326
|
-
await client.connect();
|
|
327
|
-
try {
|
|
328
|
-
await client.query("BEGIN READ ONLY");
|
|
329
|
-
try {
|
|
330
|
-
const res = await client.query(event);
|
|
331
|
-
await client.query("COMMIT");
|
|
332
|
-
return res;
|
|
333
|
-
} catch (queryError) {
|
|
334
|
-
await client.query("ROLLBACK");
|
|
335
|
-
throw queryError;
|
|
336
|
-
}
|
|
337
|
-
} finally {
|
|
338
|
-
await client.end();
|
|
339
|
-
}
|
|
340
|
-
} catch (error) {
|
|
341
|
-
console.error("Error running read-only query", {
|
|
342
|
-
error,
|
|
343
|
-
event
|
|
344
|
-
});
|
|
345
|
-
throw error;
|
|
346
|
-
}
|
|
347
|
-
}, "readOnlyHandler");
|
|
348
|
-
export { HANDLER_DEFAULT, HANDLER_READ_ONLY_DEFAULT, MEMORY_SIZE_DEFAULT, TIMEOUT_DEFAULT, createLambdaPostgresQueryTemplate, handler, readOnlyHandler };
|
|
345
|
+
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,15 +9,14 @@ var textDecoder = new TextDecoder("utf-8");
|
|
|
9
9
|
var query = /* @__PURE__ */__name(async params => {
|
|
10
10
|
try {
|
|
11
11
|
const {
|
|
12
|
-
|
|
13
|
-
lambdaPostgresQueryFunction = process.env.LAMBDA_POSTGRES_QUERY_FUNCTION,
|
|
12
|
+
functionName,
|
|
14
13
|
camelCaseKeys = true,
|
|
15
14
|
...pgParams
|
|
16
15
|
} = typeof params === "string" ? {
|
|
17
16
|
text: params
|
|
18
17
|
} : params;
|
|
19
18
|
const input = {
|
|
20
|
-
FunctionName:
|
|
19
|
+
FunctionName: functionName || process.env.LAMBDA_POSTGRES_QUERY_FUNCTION_NAME,
|
|
21
20
|
Payload: JSON.stringify({
|
|
22
21
|
...pgParams
|
|
23
22
|
})
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -54,15 +54,14 @@ var textDecoder = new TextDecoder("utf-8");
|
|
|
54
54
|
var query = /* @__PURE__ */__name(async params => {
|
|
55
55
|
try {
|
|
56
56
|
const {
|
|
57
|
-
|
|
58
|
-
lambdaPostgresQueryFunction = process.env.LAMBDA_POSTGRES_QUERY_FUNCTION,
|
|
57
|
+
functionName,
|
|
59
58
|
camelCaseKeys = true,
|
|
60
59
|
...pgParams
|
|
61
60
|
} = typeof params === "string" ? {
|
|
62
61
|
text: params
|
|
63
62
|
} : params;
|
|
64
63
|
const input = {
|
|
65
|
-
FunctionName:
|
|
64
|
+
FunctionName: functionName || process.env.LAMBDA_POSTGRES_QUERY_FUNCTION_NAME,
|
|
66
65
|
Payload: JSON.stringify({
|
|
67
66
|
...pgParams
|
|
68
67
|
})
|