@certenza/aws-cdk-infrastructure-commons 2.4.0 → 2.4.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/dist/src/apigateway.d.ts +9 -1
- package/dist/src/apigateway.js +29 -3
- package/package.json +1 -1
package/dist/src/apigateway.d.ts
CHANGED
|
@@ -31,6 +31,14 @@ declare const createApiGateway: (scope: Construct, apiName: string, domainName:
|
|
|
31
31
|
* @returns The HTTP API Gateway
|
|
32
32
|
*/
|
|
33
33
|
declare const createHttpApiGateway: (scope: Construct, apiName: string, domainName: string, hostedZoneId: string, zoneName: string, defaultAuthorizer?: apigatewayv2.IHttpRouteAuthorizer) => apigatewayv2.HttpApi;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an HTTP API Gateway Lambda endpoint
|
|
36
|
+
* @param method - The HTTP method for the endpoint (POST, GET, PUT, DELETE, PATCH, OPTIONS, HEAD)
|
|
37
|
+
* @param path - The path for the endpoint (e.g., "/messages")
|
|
38
|
+
* @param lambdaFunction - The Lambda function to integrate
|
|
39
|
+
* @param api - The HTTP API Gateway to add the endpoint to
|
|
40
|
+
* @returns The HTTP API Gateway Lambda endpoint
|
|
41
|
+
*/
|
|
34
42
|
declare const createHttpApiGatewayLambdaEndpoint: (method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD", path: string, lambdaFunction: lambda.IFunction, api: apigatewayv2.HttpApi) => apigatewayv2.IHttpRoute[];
|
|
35
43
|
/**
|
|
36
44
|
* Creates an HTTP API Gateway SQS endpoint
|
|
@@ -38,7 +46,7 @@ declare const createHttpApiGatewayLambdaEndpoint: (method: "POST" | "GET" | "PUT
|
|
|
38
46
|
* @param path - The path for the endpoint (e.g., "/messages")
|
|
39
47
|
* @param queue - The SQS queue to integrate with
|
|
40
48
|
* @param api - The HTTP API Gateway to add the endpoint to
|
|
41
|
-
* @returns The
|
|
49
|
+
* @returns The HTTP API Gateway SQS endpoint
|
|
42
50
|
*/
|
|
43
51
|
declare const createHttpApiGatewaySQSEndpoint: (method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD", path: string, queue: sqs.IQueue, api: apigatewayv2.HttpApi) => apigatewayv2.IHttpRoute[];
|
|
44
52
|
export { createApiGateway, createHttpApiGateway, createHttpApiGatewayLambdaEndpoint, createHttpApiGatewaySQSEndpoint, getApiGatewayDomainName, };
|
package/dist/src/apigateway.js
CHANGED
|
@@ -162,11 +162,28 @@ const getHttpMethod = (method) => {
|
|
|
162
162
|
return apigatewayv2.HttpMethod.HEAD;
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
|
+
/**
|
|
166
|
+
* Creates an HTTP API Gateway Lambda endpoint
|
|
167
|
+
* @param method - The HTTP method for the endpoint (POST, GET, PUT, DELETE, PATCH, OPTIONS, HEAD)
|
|
168
|
+
* @param path - The path for the endpoint (e.g., "/messages")
|
|
169
|
+
* @param lambdaFunction - The Lambda function to integrate
|
|
170
|
+
* @param api - The HTTP API Gateway to add the endpoint to
|
|
171
|
+
* @returns The HTTP API Gateway Lambda endpoint
|
|
172
|
+
*/
|
|
165
173
|
const createHttpApiGatewayLambdaEndpoint = (method, path, lambdaFunction, api) => {
|
|
174
|
+
// Create a unique ID by combining path and method to avoid construct ID conflicts
|
|
175
|
+
// when the same Lambda function is used for multiple routes
|
|
176
|
+
// Path and method are concrete strings (not tokens), so this is safe
|
|
177
|
+
// Handle path parameters like {userId} by removing curly braces
|
|
178
|
+
const sanitizedPath = path
|
|
179
|
+
.replace(/\{([^}]+)\}/g, "$1")
|
|
180
|
+
.replace(/\//g, "-")
|
|
181
|
+
.replace(/^-/, "")
|
|
182
|
+
.replace(/-$/, "") || "root";
|
|
166
183
|
return api.addRoutes({
|
|
167
184
|
path: path,
|
|
168
185
|
methods: [getHttpMethod(method)],
|
|
169
|
-
integration: new apigatewayv2_integrations.HttpLambdaIntegration(
|
|
186
|
+
integration: new apigatewayv2_integrations.HttpLambdaIntegration(`${method}-${sanitizedPath}`, lambdaFunction),
|
|
170
187
|
});
|
|
171
188
|
};
|
|
172
189
|
exports.createHttpApiGatewayLambdaEndpoint = createHttpApiGatewayLambdaEndpoint;
|
|
@@ -176,17 +193,26 @@ exports.createHttpApiGatewayLambdaEndpoint = createHttpApiGatewayLambdaEndpoint;
|
|
|
176
193
|
* @param path - The path for the endpoint (e.g., "/messages")
|
|
177
194
|
* @param queue - The SQS queue to integrate with
|
|
178
195
|
* @param api - The HTTP API Gateway to add the endpoint to
|
|
179
|
-
* @returns The
|
|
196
|
+
* @returns The HTTP API Gateway SQS endpoint
|
|
180
197
|
*/
|
|
181
198
|
const createHttpApiGatewaySQSEndpoint = (method, path, queue, api) => {
|
|
182
199
|
// Grant API Gateway service permission to send messages to SQS
|
|
183
200
|
// This matches the behavior of createSQSApiGatewayIntegration
|
|
184
201
|
// For HTTP API Gateway v2, we grant permissions directly to the service principal
|
|
185
202
|
queue.grantSendMessages(new iam.ServicePrincipal("apigateway.amazonaws.com"));
|
|
203
|
+
// Create a unique ID by combining path and method to avoid construct ID conflicts
|
|
204
|
+
// when the same queue is used for multiple routes
|
|
205
|
+
// Path and method are concrete strings (not tokens), so this is safe
|
|
206
|
+
// Handle path parameters like {userId} by removing curly braces
|
|
207
|
+
const sanitizedPath = path
|
|
208
|
+
.replace(/\{([^}]+)\}/g, "$1")
|
|
209
|
+
.replace(/\//g, "-")
|
|
210
|
+
.replace(/^-/, "")
|
|
211
|
+
.replace(/-$/, "") || "root";
|
|
186
212
|
return api.addRoutes({
|
|
187
213
|
path: path,
|
|
188
214
|
methods: [getHttpMethod(method)],
|
|
189
|
-
integration: new apigatewayv2_integrations.HttpSqsIntegration(
|
|
215
|
+
integration: new apigatewayv2_integrations.HttpSqsIntegration(`${method}-${sanitizedPath}`, {
|
|
190
216
|
queue: queue,
|
|
191
217
|
}),
|
|
192
218
|
});
|
package/package.json
CHANGED