Multiple Authorizers issue in apigateway.RestAPI: ...
# aws
p
Multiple Authorizers issue in apigateway.RestAPI: I'm trying to create an API Gateway using "@pulumi/aws-apigateway" with the following code:
Copy code
import { AuthorizerArgs } from "@pulumi/aws-apigateway/types/input";
import * as apigateway from "@pulumi/aws-apigateway";

// Define the common authorizer
const commonAuthorizer: AuthorizerArgs = {
    parameterName: "Authorization",
    parameterLocation: "header",
    identityValidationExpression: "^Bearer [-0-9a-zA-Z._]*$",
    authType: "custom",
    type: "token",
    identitySource: ["method.request.header.Authorization"],
    handler: authorizerLambda,
    authorizerResultTtlInSeconds: 600,
};

// Create the API Gateway with routes
const api = new apigateway.RestAPI("test-api", {
    stageName: "v1",
    routes: [
        {
            path: "/route1",
            method: "PUT",
            eventHandler: route1PutLambdaFunction,
            authorizers: [commonAuthorizer],
        },
        {
            path: "/route1",
            method: "DELETE",
            eventHandler: route1DeleteLambdaFunction,
            authorizers: [commonAuthorizer],
        },
        {
            path: "/route2",
            method: "PUT",
            eventHandler: route2PutLambdaFunction,
            authorizers: [commonAuthorizer],
        },
        {
            path: "/route3",
            method: "PUT",
            eventHandler: route3PutLambdaFunction,
            authorizers: [commonAuthorizer],
        },
        // Add more routes as needed
    ],
});
Issue: Even though I define a single
commonAuthorizer
,
pulumi up
creates a separate authorizer for each route. If there are 10 routes, it generates 10 different authorizers, roles, and permissions. This duplication causes exceed the default api gateway authorizers limit of 10. Expected Behavior: I want to reuse the same authorizer across all multiple routes. Actual Behavior: Each route creates its own authorizer, resulting in unnecessary duplication and deployment hangs with more than 10 routes. Question: How can I ensure a single custom authorizer is reused across all routes? Adding the
authorizerName
field into the authorizer is throwing
unique name requiring error
attempting to create two authorizers with same name. Issue is reported, follow it from the thread!
The issue is reported and can be tracked from here.