@certenza/aws-cdk-infrastructure-commons 2.2.3 → 2.3.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.
@@ -17,4 +17,11 @@ 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 apiName - The name of the API Gateway to import
24
+ * @returns The imported API Gateway
25
+ */
26
+ declare const importApiGateway: (scope: Construct, apiName: string) => apigateway.IRestApi;
27
+ 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,36 @@ 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 apiName - The name of the API Gateway to import
120
+ * @returns The imported API Gateway
121
+ */
122
+ const importApiGateway = (scope, apiName) => {
123
+ return apigateway.RestApi.fromRestApiAttributes(scope, `Imported-${apiName}-Api`, {
124
+ restApiId: aws_cdk_lib_1.Fn.importValue(`CertenzaInfrastructureApiGatewayStack-${apiName}Id`),
125
+ rootResourceId: aws_cdk_lib_1.Fn.importValue(`CertenzaInfrastructureApiGatewayStack-${apiName}RootResourceId`),
126
+ });
127
+ };
128
+ 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.3",
3
+ "version": "2.3.1",
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",