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
demandé il y a un an363 vues
1 réponse
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
répondu il y a un an

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions