@@ -18,6 +18,12 @@ export interface IHttpApi extends IResource {
1818 */
1919 readonly httpApiId : string ;
2020
21+ /**
22+ * The default endpoint for an API
23+ * @attribute
24+ */
25+ readonly apiEndpoint : string ;
26+
2127 /**
2228 * The default stage
2329 */
@@ -184,6 +190,7 @@ export interface AddRoutesOptions extends BatchHttpRouteOptions {
184190abstract class HttpApiBase extends Resource implements IHttpApi { // note that this is not exported
185191
186192 public abstract readonly httpApiId : string ;
193+ public abstract readonly apiEndpoint : string ;
187194 private vpcLinks : Record < string , VpcLink > = { } ;
188195
189196 public metric ( metricName : string , props ?: cloudwatch . MetricOptions ) : cloudwatch . Metric {
@@ -233,6 +240,21 @@ abstract class HttpApiBase extends Resource implements IHttpApi { // note that t
233240 }
234241}
235242
243+ /**
244+ * Attributes for importing an HttpApi into the CDK
245+ */
246+ export interface HttpApiAttributes {
247+ /**
248+ * The identifier of the HttpApi
249+ */
250+ readonly httpApiId : string ;
251+ /**
252+ * The endpoint URL of the HttpApi
253+ * @default - throws an error if apiEndpoint is accessed.
254+ */
255+ readonly apiEndpoint ?: string ;
256+ }
257+
236258/**
237259 * Create a new API Gateway HTTP API endpoint.
238260 * @resource AWS::ApiGatewayV2::Api
@@ -241,9 +263,17 @@ export class HttpApi extends HttpApiBase {
241263 /**
242264 * Import an existing HTTP API into this CDK app.
243265 */
244- public static fromApiId ( scope : Construct , id : string , httpApiId : string ) : IHttpApi {
266+ public static fromHttpApiAttributes ( scope : Construct , id : string , attrs : HttpApiAttributes ) : IHttpApi {
245267 class Import extends HttpApiBase {
246- public readonly httpApiId = httpApiId ;
268+ public readonly httpApiId = attrs . httpApiId ;
269+ private readonly _apiEndpoint = attrs . apiEndpoint ;
270+
271+ public get apiEndpoint ( ) : string {
272+ if ( ! this . _apiEndpoint ) {
273+ throw new Error ( 'apiEndpoint is not configured on the imported HttpApi.' ) ;
274+ }
275+ return this . _apiEndpoint ;
276+ }
247277 }
248278 return new Import ( scope , id ) ;
249279 }
@@ -252,13 +282,7 @@ export class HttpApi extends HttpApiBase {
252282 * A human friendly name for this HTTP API. Note that this is different from `httpApiId`.
253283 */
254284 public readonly httpApiName ?: string ;
255-
256285 public readonly httpApiId : string ;
257-
258- /**
259- * The default endpoint for an API
260- * @attribute
261- */
262286 public readonly apiEndpoint : string ;
263287
264288 /**
0 commit comments