Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to reference an existing authorizer function for ApiGatewayV1 #4058

Closed
srenault opened this issue Sep 25, 2024 · 4 comments · Fixed by sst/ion#1191
Closed

Unable to reference an existing authorizer function for ApiGatewayV1 #4058

srenault opened this issue Sep 25, 2024 · 4 comments · Fixed by sst/ion#1191
Assignees

Comments

@srenault
Copy link

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.

@fwang
Copy link
Contributor

fwang commented Sep 29, 2024

@srenault If u have an existing lambda authorizer with id ie. xxxx, u can use it directly:

const api = new sst.aws.ApiGatewayV1("MyApi");
api.route("GET /token", "index.handler", {
  auth: { custom: "xxxx" },
});

u don't need to call addAuthorizer to create a new authorizer.

lemme know if this works for u.

@srenault
Copy link
Author

srenault commented Oct 1, 2024

My understanding is I need to create for each ApiGateway a new authorizer that all point to the same lambda authoriser so I don't think it would work.

@greenlynx
Copy link
Contributor

Im also hitting this issue - when trying to create a Cognito authorizer I'm getting the Cannot read properties of undefined (reading 'nodes') error.

It appears to be caused by sst/ion@6d6a782 - it changes line 130 in platform/src/components/aws/apigatewayv1-authorizer.ts from:

authorizerUri: fn?.nodes.function.invokeArn,

to:

authorizerUri: fn!.nodes.function.invokeArn,

Note removal of the optional chaining operator. When creating a Cognito authorizer, no lambda is created, so fn is undefinedand this line errors. Manually reverting the change on this line appears to fix the issue for me.

@greenlynx
Copy link
Contributor

Has anyone from the project got time to look at my PR please? I've not contributed before so am not sure of the process, but it's a one-liner and should be quick to review 😄

@thdxr thdxr transferred this issue from sst/ion Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants