How to add routes to an Api Gateway in a different stack?

0

I split my stack into two pieces so I can have other developers work on the implementation of the apigatewayv2 routes, integrations, and lambdas. I am trying to figure out how to reference the API Gateway. I thought I had it figured out:

HttpApi.fromHttpApiAttributes(stack, "my-api-gateway-id",
            {
                httpApiId: "something"
            }
);

but that returns an IHttpApi which doesn't have .addRoutes(). I tried casting it to HttpApi but that didn't work - it really doesn't have .addRoutes(). Not sure what to do.

How do I get an HttpApi rather than an IHttpApi? Casting didn't work.

profile picture
wz2b
posta un anno fa363 visualizzazioni
1 Risposta
0

Figured it out. You have to use HttpRoute to do this as described here. You don't addRoutes() you just create it. The main difference is that you need to do this once for every method.

In my case, I pass in an array of methods, then add then one at a time:

       methods.forEach( (method) => {
            const routeId = id + "-" + method.toLowerCase();
            new HttpRoute(this.stack, routeId, {
                httpApi: this.api,
                routeKey: HttpRouteKey.with(props.path, method),
                integration: httpIntegration,
                authorizer: this.authorizer
            });
        });
profile picture
wz2b
con risposta un anno fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande