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
質問済み 1年前363ビュー
1回答
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
回答済み 1年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ