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
feita há um ano394 visualizações
1 Resposta
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
respondido há um ano

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas