Question about Authorizers…. I have an existing SL...
# sst
a
Question about Authorizers…. I have an existing SLS project which creates my
custom authorizer
, now I want to reference it from my SST stack, is there any example on how to do that?
Copy code
const authorizer = new HttpLambdaAuthorizer({
      authorizerName: "LambdaAuthorizer",
      handler: new Function(this, "Authorizer", {
        handler: "src/authorizer.main",
      }),
    });
Maybe I can specify the ARN somehow?
j
Hey Adrián, I have done this through using the CDK constructs within SST. Using a fromFunctionArn. This was for an apiGatewayV1Api.
Copy code
import * as iam from '@aws-cdk/aws-iam'
import * as lambda from '@aws-cdk/aws-lambda'
import { Duration } from '@aws-cdk/core'

const importedAuthLambda = lambda.Function.fromFunctionArn(this, "importedAuthLambda",
`arn:aws:lambda:${this.region}:${this.account}:function:project-${this.stage}-Authorizer`
)

const authorizer = new apigateway.TokenAuthorizer(this, 'Authorizer', {
  handler: importedAuthLambda,
  authorizerName: 'Authorizer',
  resultsCacheTtl: Duration.seconds(0),
  identitySource: apigateway.IdentitySource.header('Authorization'),
})
f
@Adrián Mouly Would it be easier to create a new authorizer in SST with the same code?
a
@Frank yeah will be better for sure.