Hello. I follow documentation for adding lambda au...
# help
s
Hello. I follow documentation for adding lambda authorizer for specific routes.
Copy code
const api = new sst.Api(this, "Api", {
    // defaultAuthorizationType: ApiAuthorizationType.CUSTOM,
    defaultAuthorizer: new HttpLambdaAuthorizer({
        authorizerName: "LambdaAuthorizer",
        handler: new sst.Function(this, "Authorizer", {
            handler: "src/authorizer.handler"
        }),
    }),
    routes: {
        "GET /private": {
            authorizationType: ApiAuthorizationType.CUSTOM,
            handler: "src/private.handler"
        },
        "GET /authenticate/facebook": "src/auth-facebook.handler"
    }
[8:27 AM] I checked 0.40.1 and latest 0.40.2 -> in both cases produced Cloudformation template contains
Copy code
[8:27 AM] AuthorizationType: NONE
[8:28 AM] I can set defaultAuthorizationType to CUSTOM, however this apply for all routes and can’t be overwritten with authorizationType for specific routes
s
to override, this is the format:
Copy code
'GET /embeds/{embedId}': {
    function: 'get-embed.main',
    authorizationType: sst.ApiAuthorizationType.NONE,
  },
s
this didn't work for me
do you have defaultAuthorizationType. set to ApiAuthorizationType.CUSTOM ?
s
no, my default is set to JWT. but the same concept applies.. doesn’t matter what the authorization type is.
I have:
Copy code
const api = new sst.Api(this, 'RestAPI', {
      defaultAuthorizationType: sst.ApiAuthorizationType.JWT,
      defaultAuthorizer: new HttpUserPoolAuthorizer({
        userPool: props.cognitoAuth.cognitoUserPool!,
        userPoolClient: props.cognitoAuth.cognitoUserPoolClient!,
      }),
so all my API routes require JWT auth. but I can override with
NONE
in specific routes
s
hmm, must miss something else, I deploy following test stack:
and in result
/facebook route should have authorization NONE
s
oh.. if you changed the authorization, that won’t work. you have to comment out the route, deploy, then add the route back in, and deploy
it’s a limitation in CloudFormation
s
I deleted the stack and deployed in two separate regions, same issue. I think I have to create fresh project to test it in isolation from my other stacks…
f
@Slawomir Stec This is invalid:
Copy code
"GET /private": {
            authorizationType: ApiAuthorizationType.CUSTOM,
            handler: "src/private.handler"
        },
This is valid
Copy code
"GET /private": {
            authorizationType: ApiAuthorizationType.CUSTOM,
            function: "src/private.handler"
        },
This is also valid
Copy code
"GET /private": {
            authorizationType: ApiAuthorizationType.CUSTOM,
            function: {
              handler: "src/private.handler"
            }
        },
s
@Frank yes, it works now, thank you
f
Yeah, we will be adding some input validation, and that should catch invalid input format (cc @thdxr)
s
Oh wow, this proper caught me out. Even looking at @Frank's code above it took me a while to make the distinction between
function
vs
handler
. I need to do some more reading on the difference here.