Hey guys, super quick (probably stupid) question a...
# help
b
Hey guys, super quick (probably stupid) question about external lambda authorizer on an API. Using v1 it looks like this sort of thing has been affected and I'm trying to figure out the "correct" way to do this. This is what I have:
Copy code
new Api(this, "api", {
            authorizers: {
                "custom-auth": {
                    type: "lambda",
                    function: Function.fromFunctionArn(this, "custom-auth", "my-lambda-arn"),
                }
            }
        });
This gives me an error:
Copy code
Type 'IFunction' is missing the following properties from type 'Function': _isLiveDevEnabled, localId, attachPermissions, getConstructMetadata, and 33 more.
So I guess I should actually be using the
cdk.authorizer
with a
HttpLAmbdaAuthorizer
construct instead? (seem to have lost where to import that class from 😞)
Found the npm package for the authorizers. Implementation now looks like this:
Copy code
new Api(this, "api", {
            authorizers: {
                "custom-auth": {
                    type: "lambda",
                    cdk: {
                        authorizer: new HttpLambdaAuthorizer("authorizer", Function.fromFunctionArn(this, "custom-auth", "my-lambda-arn"))
                    }
                }
            }
        });
I thought I saw someone mentionthat we shouldn't need to import the authorizer package going forward? Or did make that up?
Seem to have stumbled on to a wider issue. My API will need to use a Lambda declared elsewhere as one of the route handlers; looks like in general trying to use
Function.fromFunctionArn
is incompatible with the SST properties. Is this an oversight, intended behaviour or a bug?
@Frank @thdxr any thoughts/guideance on this?
t
But is there a reason you're importing using
Function.fromFunctionArn
? This won't work since it's expecting an sst.Function
where is this function declared?
b
Yea, I looked through the docs earlier but looks like it's contingent on being in the same application. Referenced function lives in another application/repo so need to import it as its outside of the scope of the project.
I've done this previously using the
HttpLambdaAuthorizer
as mentioned above, but I'll definitely have this issue for getting my API to call a lambda declared elsewhere. Might just have to declare a function in the local project that has permissions to call the required external lambda.
t
ah I see you want to share the route handler from another project
b
Yea, preferably some of the route handlers and the authorizer would be external resources.
If this is out of the general design scope you guys are going for then I'll just roll on and shut up haha. I just wanted to check that this isn't something you guys had overlooked or if you had even thought about it.
f
Hey @Brinsley, definitely relevant. It’s one of the most requested feature to be able to use
lambda.Function
for API routes.
Are you blocked by this?
b
Not blocked :) have had a slight change in focus so won't need this immediately.