Having reviewed the docs and this channel I am loo...
# sst
j
Having reviewed the docs and this channel I am looking for a way to do custom logic for the
authorizationType
using a custom function? Similar to Serverless framework can have custom function for the
authorizer
. The reason for this is both for authorisation and to load in extra data onto the
event.requestContext.authorizer
r
For one of our apps (the first I’m migrating) we use Firebase Auth via a custom lambda authorizer. You need to use ApiGatewayV1 for this
f
@Jack Fraser which construct r u using?
Api
or
ApiGatewayV1Api
?
j
Api
f
You can either wait for CDK to support it and we can add support for it right after.
Or you can write some CloudFormation level construct to do it.
j
would ApiGatewayV1Api support it? @Frank or is that legacy?
f
ApiGatewayV1Api
does support it. But imo it’s not worth switching to
ApiGatewayV1Api
just for this.
R u blocked by this?
I can help u put something together for now using the CfnAuthorizer construct until CDK supports it.
j
Hi @Frank to adopt it easier it would great if we did not have to change how we currently do it
f
By “did not have to change how we currently do it”, do you mean you want to keep using the
Api
construct?
j
thanks @Frank - not worth using older ApiGatewayV1Api for this. Will work round it for now. Do you know when the CDK/SST will support custom auths?
f
Hey Jack, we are watching this PR on the CDK side https://github.com/aws/aws-cdk/pull/13181
It seems the initial implementation has been submitted, and it’s going through the review process.
But if u need to get this to work before CDK supports it, u can write some CloudFormation code in your CDK app to do this (custom authorizer is supported by CF, just not CDK) . If you plan to do that, let me know, I can help you on that. 🙂
j
@Frank seems like the CDK now supports this
f
Nice! Once they cut a release with it, we can add the support to SST.
Hey @Jack Fraser, just aded Lambda authorizer to v0.20.0:
Copy code
new Api(this, "Api", {
  defaultAuthorizationType: ApiAuthorizationType.CUSTOM,
  defaultAuthorizer: new HttpLambdaAuthorizer({
    authorizerName: "LambdaAuthorizer",
    handler: new Function(this, "Authorizer", {
      handler: "src/authorizer.main",
    }),
  }),
  routes: {
    "GET /notes": "src/list.main",
  },
});
j
@Frank - great work adding this. What is the best way to have a single authorizer handler function for multiple stacks in the same app?
is it possible to use
getFunction
etc but a path of another stack?
f
Hey @Jack Fraser, you just need to set the defaultAuthorizer on the Api, and it applies to all routes across stacks. I just added a section in the doc on this topic https://docs.serverless-stack.com/constructs/Api#sharing-an-api-authorizer
You should be able to call
getFunction
across stacks. Give it a try. Let me know if it doesn’t work for you.