@certenza/aws-cdk-infrastructure-commons 2.2.2 → 2.3.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.
@@ -17,4 +17,12 @@ declare const getApiGatewayDomainName: (service: string, domainName: string, env
17
17
  * @returns The API Gateway
18
18
  */
19
19
  declare const createApiGateway: (scope: Construct, apiName: string, domainName: string, hostedZoneId: string, zoneName: string) => apigateway.RestApi;
20
- export { createApiGateway, getApiGatewayDomainName };
20
+ /**
21
+ * Imports an API Gateway from the given stack name
22
+ * @param scope - The scope of the API Gateway
23
+ * @param stackName - The name of the stack to import the API Gateway from
24
+ * @param apiName - The name of the API Gateway to import
25
+ * @returns The imported API Gateway
26
+ */
27
+ declare const importApiGateway: (scope: Construct, stackName: string, apiName: string) => apigateway.IRestApi;
28
+ export { createApiGateway, getApiGatewayDomainName, importApiGateway };
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.getApiGatewayDomainName = exports.createApiGateway = void 0;
36
+ exports.importApiGateway = exports.getApiGatewayDomainName = exports.createApiGateway = void 0;
37
37
  const apigateway = __importStar(require("aws-cdk-lib/aws-apigateway"));
38
38
  const logs = __importStar(require("aws-cdk-lib/aws-logs"));
39
39
  const route53 = __importStar(require("aws-cdk-lib/aws-route53"));
@@ -41,6 +41,7 @@ const route53targets = __importStar(require("aws-cdk-lib/aws-route53-targets"));
41
41
  const cdk = __importStar(require("aws-cdk-lib"));
42
42
  const acm_1 = require("./acm");
43
43
  const route53_1 = require("./route53");
44
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
44
45
  /**
45
46
  * Gets the domain name for the API Gateway
46
47
  * @param environment - The environment to get the domain name for
@@ -92,7 +93,37 @@ const createApiGateway = (scope, apiName, domainName, hostedZoneId, zoneName) =>
92
93
  recordName: domainName.replace(`${hostedZone.zoneName}.`, ""),
93
94
  target: route53.RecordTarget.fromAlias(new route53targets.ApiGateway(api)),
94
95
  });
96
+ // Add a dummy endpoint to prevent API Gateway deployment errors
97
+ // when the API has only one endpoint. This ensures the API can be deployed
98
+ // even if no other methods are added yet.
99
+ api.root.addMethod("GET", new apigateway.MockIntegration({
100
+ requestTemplates: {
101
+ "application/json": '{"statusCode": 200}',
102
+ },
103
+ integrationResponses: [
104
+ {
105
+ statusCode: "200",
106
+ responseTemplates: {
107
+ "application/json": "",
108
+ },
109
+ },
110
+ ],
111
+ }));
95
112
  // Return the API Gateway
96
113
  return api;
97
114
  };
98
115
  exports.createApiGateway = createApiGateway;
116
+ /**
117
+ * Imports an API Gateway from the given stack name
118
+ * @param scope - The scope of the API Gateway
119
+ * @param stackName - The name of the stack to import the API Gateway from
120
+ * @param apiName - The name of the API Gateway to import
121
+ * @returns The imported API Gateway
122
+ */
123
+ const importApiGateway = (scope, stackName, apiName) => {
124
+ return apigateway.RestApi.fromRestApiAttributes(scope, `Imported-${apiName}-Api`, {
125
+ restApiId: aws_cdk_lib_1.Fn.importValue(`CertenzaInfrastructureApiGatewayStack-${apiName}-ApiId`),
126
+ rootResourceId: aws_cdk_lib_1.Fn.importValue(`CertenzaInfrastructureApiGatewayStack-${apiName}-RootResourceId`),
127
+ });
128
+ };
129
+ exports.importApiGateway = importApiGateway;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certenza/aws-cdk-infrastructure-commons",
3
- "version": "2.2.2",
3
+ "version": "2.3.0",
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",
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "homepage": "https://github.com/certenza/aws-cdk-infrastructure-commons#readme",
42
42
  "dependencies": {
43
- "aws-cdk-lib": "^2.232.1"
43
+ "aws-cdk-lib": "^2.233.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@types/node": "^24.0.0",