ion icon indicating copy to clipboard operation
ion copied to clipboard

Unable to reference an existing authorizer function for ApiGatewayV1

Open srenault opened this issue 5 months ago • 4 comments

Currently I don't see anyway to reference an existing function when adding a new authorizer to ApiGatewayV1. I tried to pass the arn instead of the handler path without any success. Another attempt I had was to use the userPools method (because I saw it's the only case where SST doesn't create a lambda) and use the transform function to update authorizerUri. But it ended up with the following error :

TypeError: Cannot read properties of undefined (reading 'nodes')
       at createAuthorizer (file:///Volumes/sredata/dev/prismicio/obelix/.sst/platform/src/components/aws/apigatewayv1-authorizer.ts:130:32)
       at new ApiGatewayV1Authorizer (file:///Volumes/sredata/dev/prismicio/obelix/.sst/platform/src/components/aws/apigatewayv1-authorizer.ts:64:24)
       at ApiGatewayV1.addAuthorizer (file:///Volumes/sredata/dev/prismicio/obelix/.sst/platform/src/components/aws/apigatewayv1.ts:1029:12)
       at services/document-search/infra/search.ts (file:///Volumes/sredata/dev/prismicio/obelix/services/document-search/infra/search.ts:26:24)
       at services/document-search/infra/mod.ts (file:///Volumes/sredata/dev/prismicio/obelix/services/document-search/infra/mod.ts:6:1)
       at run (file:///Volumes/sredata/dev/prismicio/obelix/sst.config.ts:33:31)
       at run (file:///Volumes/sredata/dev/prismicio/obelix/.sst/platform/src/auto/run.ts:32:20)
       at file:///Volumes/sredata/dev/prismicio/obelix/eval.ts:4:22

Finally I came up with following solution:

const authorizer = api.addAuthorizer({
	name: "custom-authorizer",
	ttl: 0,
	identitySource: "",
	requestFunction: {
		handler: "services/dummy-authorizer/src/index.handler",
	},
	transform: {
		authorizer: {
			authorizerUri: authorizerFunction.invokeArn,
		},
	},
})

In this solution I let SST creating the lambda even though I don't use it. Is there anything I'm missing here? Also I'm pretty sure I spot a bug with userPools as well.

srenault avatar Sep 25 '24 14:09 srenault