Custom Authorizer configuration for multiple endpoints in the same API

Is there any way i can use the same custom authorizer lambda function configured differently for each endpoint in my API.
I have multiple endpoints in my API . I want to set TTL to 0 for DELETE/PUT/POST operations and cache the policy for GET operations.
However when i configure the authorizer for each of the endpoints as below i see the same behavior for all the endpoints. i.e. caching is set on all the endpoints.
For GET request
authorizer:
name:
arn: arn:aws:lambda:${self:custom.pRegion}:${self:custom.pAccountId}:function:${self:custom.pOwner}-${self:custom.pEnvironment}-lf-custom-authorizer-authorize
resultTtlInSeconds: 300
identitySource: method.request.header.Authorization
type: token
For DELETE request
authorizer:
name:
arn: arn:aws:lambda:${self:custom.pRegion}:${self:custom.pAccountId}:function:${self:custom.pOwner}-${self:custom.pEnvironment}-lf-custom-authorizer-authorize
resultTtlInSeconds: 0
identitySource: method.request.header.Authorization
type: token

1 Like

In API Gateway, custom authorizer settings are attached to the custom authorizer, not the individual resources/methods. However, authorizer settings are defined at the event level in serverless.yml.
So, it looks serverless doesn’t translate this configuration into an appropriate number of custom authorizers in API Gateway.

As a workaround, you might need to deploy two instances of the same function, and then reference each one individually (with the separate settings).