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
asked a year ago311 views
1 Answer
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
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions