@certenza/aws-cdk-infrastructure-commons 2.4.0 → 2.4.2

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.
@@ -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 route configuration
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, };
@@ -126,6 +126,9 @@ const createHttpApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName
126
126
  description: `Public HTTP API Gateway for ${apiName}`,
127
127
  defaultDomainMapping: {
128
128
  domainName: apiDomainName,
129
+ // Explicitly set mappingKey to empty string for root path mapping
130
+ // to avoid "undefined" appearing in resource names
131
+ mappingKey: "",
129
132
  },
130
133
  defaultAuthorizer: defaultAuthorizer ?? new aws_apigatewayv2_authorizers_1.HttpIamAuthorizer(),
131
134
  });
@@ -162,11 +165,28 @@ const getHttpMethod = (method) => {
162
165
  return apigatewayv2.HttpMethod.HEAD;
163
166
  }
164
167
  };
168
+ /**
169
+ * Creates an HTTP API Gateway Lambda endpoint
170
+ * @param method - The HTTP method for the endpoint (POST, GET, PUT, DELETE, PATCH, OPTIONS, HEAD)
171
+ * @param path - The path for the endpoint (e.g., "/messages")
172
+ * @param lambdaFunction - The Lambda function to integrate
173
+ * @param api - The HTTP API Gateway to add the endpoint to
174
+ * @returns The HTTP API Gateway Lambda endpoint
175
+ */
165
176
  const createHttpApiGatewayLambdaEndpoint = (method, path, lambdaFunction, api) => {
177
+ // Create a unique ID by combining path and method to avoid construct ID conflicts
178
+ // when the same Lambda function is used for multiple routes
179
+ // Path and method are concrete strings (not tokens), so this is safe
180
+ // Handle path parameters like {userId} by removing curly braces
181
+ const sanitizedPath = path
182
+ .replace(/\{([^}]+)\}/g, "$1")
183
+ .replace(/\//g, "-")
184
+ .replace(/^-/, "")
185
+ .replace(/-$/, "") || "root";
166
186
  return api.addRoutes({
167
187
  path: path,
168
188
  methods: [getHttpMethod(method)],
169
- integration: new apigatewayv2_integrations.HttpLambdaIntegration(lambdaFunction.functionName, lambdaFunction),
189
+ integration: new apigatewayv2_integrations.HttpLambdaIntegration(`${method}-${sanitizedPath}`, lambdaFunction),
170
190
  });
171
191
  };
172
192
  exports.createHttpApiGatewayLambdaEndpoint = createHttpApiGatewayLambdaEndpoint;
@@ -176,18 +196,32 @@ exports.createHttpApiGatewayLambdaEndpoint = createHttpApiGatewayLambdaEndpoint;
176
196
  * @param path - The path for the endpoint (e.g., "/messages")
177
197
  * @param queue - The SQS queue to integrate with
178
198
  * @param api - The HTTP API Gateway to add the endpoint to
179
- * @returns The route configuration
199
+ * @returns The HTTP API Gateway SQS endpoint
180
200
  */
181
201
  const createHttpApiGatewaySQSEndpoint = (method, path, queue, api) => {
182
202
  // Grant API Gateway service permission to send messages to SQS
183
203
  // This matches the behavior of createSQSApiGatewayIntegration
184
204
  // For HTTP API Gateway v2, we grant permissions directly to the service principal
185
205
  queue.grantSendMessages(new iam.ServicePrincipal("apigateway.amazonaws.com"));
206
+ // Create a unique ID by combining path and method to avoid construct ID conflicts
207
+ // when the same queue is used for multiple routes
208
+ // Path and method are concrete strings (not tokens), so this is safe
209
+ // Handle path parameters like {userId} by removing curly braces
210
+ const sanitizedPath = path
211
+ .replace(/\{([^}]+)\}/g, "$1")
212
+ .replace(/\//g, "-")
213
+ .replace(/^-/, "")
214
+ .replace(/-$/, "") || "root";
186
215
  return api.addRoutes({
187
216
  path: path,
188
217
  methods: [getHttpMethod(method)],
189
- integration: new apigatewayv2_integrations.HttpSqsIntegration(queue.queueName, {
218
+ integration: new apigatewayv2_integrations.HttpSqsIntegration(`${method}-${sanitizedPath}`, {
190
219
  queue: queue,
220
+ // Configure parameter mapping to use the entire request body as the message body
221
+ // By default, it expects $request.body.MessageBody, but we want to send the whole body
222
+ parameterMapping: apigatewayv2.ParameterMapping.fromObject({
223
+ MessageBody: apigatewayv2.MappingValue.custom("$request.body"),
224
+ }),
191
225
  }),
192
226
  });
193
227
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certenza/aws-cdk-infrastructure-commons",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Common infrastructure reusable utilities and resources for Certenza projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",