Fazi
02/10/2022, 11:41 AMconst authorizer = new HttpLambdaAuthorizer({
authorizerName: 'authorizer',
handler: new Function(this, 'Authorizer', {
functionName: 'AuthorizerFn',
srcPath: "src",
handler: 'authorizer.main',
tracing: lambda.Tracing.DISABLED,
timeout: 30,
permissions: ['ssm'],
}),
resultsCacheTtl: Duration.seconds(0),
responseTypes: [HttpLambdaResponseType.SIMPLE],
});
I then want to apply it to a specific route as follows:
const api = new Api(this, "Api", {
// defaultAuthorizationType: ApiAuthorizationType.JWT,
// defaultAuthorizer: new HttpUserPoolAuthorizer({
// userPool,
// userPoolClient,
// }),
// defaultAuthorizationType: ApiAuthorizationType.CUSTOM,
defaultAuthorizer: authorizer,
routes: {
// some other routes go here
"GET /v1/tasks/alt": {
function: getTasksAltFunction,
authorizationType: ApiAuthorizationType.CUSTOM,
},
// some other routes go here
},
});
However, when I make a call to GET /v1/tasks/alt
I get a unauthorized error.
Can someone please explain what is going wrong? I used the docs here: https://docs.serverless-stack.com/constructs/Api#adding-lambda-authorization-to-a-specific-routeRoss Coundon
02/10/2022, 11:46 AMconst basicAuthHandler = new sst.Function(this, 'basicAuthHandler', {
handler: 'src/main/handlers/auth/basicAuthHandler.handler',
});
Then defined the HttpLambdaAuthorizer like this - with the function being passed as the 2nd parameter
const basicAuthoriser = new apigAuthorizers.HttpLambdaAuthorizer('basic-authorizer', basicAuthHandler, {
authorizerName: 'lambdaBasicAuthoriser',
});
Then on the API like this:
const api = new sst.Api(this, 'Api', {
defaultAuthorizer: basicAuthoriser,
defaultAuthorizationType: sst.ApiAuthorizationType.CUSTOM,
Fazi
02/10/2022, 11:57 AMapigAuthorizers
from?
For the bit where you write:
const basicAuthoriser = new apigAuthorizers.HttpLambdaAuthorizer('basic-authorizer', basicAuthHandler, {
authorizerName: 'lambdaBasicAuthoriser',
});
Ross Coundon
02/10/2022, 11:58 AMimport * as apigAuthorizers from '@aws-cdk/aws-apigatewayv2-authorizers-alpha';
Fazi
02/10/2022, 12:02 PMRoss Coundon
02/10/2022, 12:03 PMFazi
02/10/2022, 12:07 PMRoss Coundon
02/10/2022, 12:09 PM