https://serverless-stack.com/ logo
#sst
Title
# sst
r

Ross Coundon

04/19/2021, 8:08 PM
I’m trying to define an ApiGatewayV1Api which has two routes, one route which requires authentication via a custom lambda authorizer and a route that requires no authorization. When I deploy I get the error for the route without auth:
Copy code
Authorization type is set to NONE which is different from what is required by the authorizer [CUSTOM]
My definition looks like this:
Copy code
const api = new ApiGatewayV1Api(this, 'CustFeedbackApi', {
      defaultAuthorizer: authorizer,
      routes: {
        'POST /save': {
          function: 'src/handler/saveFeedbackHandler.handleSaveFeedback',
          methodOptions: {
            authorizationType: AuthorizationType.NONE,
          },
        },
        'GET /retrieve': {
          function:
            'src/handler/retrieveFeedbackHandler.handleRetrieveFeedback',
          methodOptions: {
            authorizationType: AuthorizationType.CUSTOM,
          },
        },
      },
    });
So, how do I set auth for one route but not another?
f

Frank

04/19/2021, 8:09 PM
Hey @Ross Coundon, let me give that a try.
r

Ross Coundon

04/19/2021, 8:10 PM
Thanks Frank, I’m just in the process of testing the opposite - setting default to NONE and setting the authoriser in methodOptions for the route with auth
f

Frank

04/19/2021, 8:15 PM
got the same error on my side as well
taking a look at it
r

Ross Coundon

04/19/2021, 8:15 PM
That’s reassuring 😄
thank you
f

Frank

04/19/2021, 8:17 PM
Copy code
const api = new ApiGatewayV1Api(this, 'CustFeedbackApi', {
      routes: {
        'POST /save': {
          function: 'src/handler/saveFeedbackHandler.handleSaveFeedback',
          methodOptions: {
            authorizationType: AuthorizationType.NONE,
          },
        },
        'GET /retrieve': {
          function:
            'src/handler/retrieveFeedbackHandler.handleRetrieveFeedback',
          methodOptions: {
            authorizer: authorizer,
            authorizationType: AuthorizationType.CUSTOM,
          },
        },
      },
    });
If u move the
defaultAuthorizer
into the
methodOptions
of the route that needs it, u can workaround it for now
I’m going to push out a fix for this in a bit
r

Ross Coundon

04/19/2021, 8:19 PM
Thanks - I now get
Copy code
Error: There is already a Construct with name 'GET' in Resource [retrieve]
sorry, my bad
mistake elsewhere
f

Frank

04/19/2021, 9:16 PM
2 Views