-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Cannot reference an authorizer already created within services that shares the same API GW #4711
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
Comments
This could be solved if it was possible to simply reference an Authorizer by its ID: (AWS::ApiGateway::Method -> AuthorizerId) I cannot find a way to do that. Is there any plugin or something that does that? Because from a code perspective this should be relatively easy. |
I hit the same problem - first thought was to use restApiResources but I couldn't (quickly) work out how to with an authorizer however if you give the authorizer in service B a name as well as an arn then it will at least deploy.
|
Same problem here. Anyone with a solution ? |
Same problem here too. |
I'm searching for any solution for this problem, anyone could give me some help? |
Has anybody tested this PR to solve this issue? #4197 I know it only references COGNITO_USER_POOLS but perhaps it might work as well with Custom authorizers... |
@jacintoArias I have tested #4197 with custom authorizer and works with multiple services. |
I hit the same problem, I just gave a name to my authorizer like @idwright Suggested, and it seems to be working. Anyone have any idea if this is the correct way (at least until a fix is released?) Or if we can have any caveats? |
Adding name, creates different authorizer in the api gateway for each lambda. |
This is Jack from the API Gateway team. Please merge #4197 as a fix. This is painful for customers because there is a limit of 10 authorizers per RestApi, and they are forced to contact AWS to request a limit increase to unblock development. Thank you! |
@jackrk Hey Jack, thanks for the slight "push" and information 👍 |
Thank you @jackrk and @HyperBrain I am one of the customers Jack mentioned above. I am glad to hear this will be available in 1.27.3! Thank you for your efforts. |
I still have this issue with custom authorizers in v1.35.0... any idea? |
@fedebalderas Can you share more details? |
@rohitshetty never mind, i didn't see this approach https://serverless.com/framework/docs/providers/aws/events/apigateway#share-authorizer |
So, to work around the issue I'll need to implement the shared authorizer approach. |
Hi @roni-frantchi, were you able to achieve this with auth0 ? |
Hi @erksdee . Not yet. Had to park it for a few days unfortunately as priorities have shifted. |
For what it's worth, commenting what I've done. I already have an authorizer function deployed in a different region which I would just like to add to a new serverless project:
Tested and this works |
Hi @pscadiz , i am also facing the same problem. Can you help me understand, what does 'RestApiId' and 'DependsOn' keys mean in the resources object. I am tring to use a lambda authorizer in a different region. My serverless.yml looks like: provider: functions: But whenever is deploy this, I get the following error : An error occurred: AuthorizerWithEnvApiGatewayAuthorizer - Invalid lambda function (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: bd1622de-8da7-11e9-a20b-4b63dfdcb095). Do you have any suggestions ? |
So what happened was I created an authorizer and placed it in the API that sls generated, the As per the documentation, we can't use the So the workaround is:
I hope i made sense. |
Hi @pscadiz , thanks for the prompt reply. I added the Lambda authorizer in the same region and it worked. The serverless.yml files is like: custom: provider: functions: This works, but this is not what i want. I want that lambda authorizer from any account/any region can be made accessible. An error occurred: AuthorizerWithEnvLambdaPermissionApiGateway - Functions from 'us-east-2' are not reachable in this region ('us-east-1') (Service: AWSLambda; Status Code: 404; Error Code: ResourceNotFoundException; Request ID: 4f668318-8dc6-11e9-ac56-b900da7dc499). I hope you are able to understand that I dont want it to access in the same region, but I am unable to access other region authorizer. Do you have any suggestions regarding the same ? |
hi, Guys: I am quite new to serverless, just wondering if we can deploy a customer authoriser an individual lambda instead of having to deploy with a service in api gateway? Thanks |
@cameljava The gateway is the AWS layer that has knowledge of both lambdas and authorizers. A lambda in isolation, afaict, does not have the ability to describe a prerequisite (authorizer, validator, etc.). This difference is evident in the respective API Gateway and Lambda consoles. |
…mation now authorizers will get auth lambda name that usually includes service/stage name or customized instead of property name
I know this is closed but thought I'd chip in for anybody stuck on this issue using a Cognito authorizer. All you need to do is replace serverless.yml:service: SHARED_SERVICE_NAME
...
resources:
Resources:
SharedApiGatewayAuthorizer:
Type: AWS::ApiGateway::Authorizer
Properties:
Name: cognito-${opt:stage, self:provider.stage}
Type: COGNITO_USER_POOLS
IdentitySource: method.request.header.Authorization
ProviderARNs:
- arn:aws:cognito-idp:REGION:ACCOUNT_ID:userpool/USER_POOL_ID
RestApiId:
Ref: ApiGatewayRestApi
Outputs:
apiGatewayAuthorizerId:
Value:
Ref: SharedApiGatewayAuthorizer
Export:
Name: apiGateway-authorizerId-${opt:stage, self:provider.stage} Lambda function reference to shared authorizer: events:
- http:
...
authorizer:
type: COGNITO_USER_POOLS
authorizerId: '${cf:SHARED_SERVICE_NAME-${opt:stage, self:provider.stage}.apiGatewayAuthorizerId}' |
same as above but a bit less verbose. I hit an issue trying to use !Ref & the like under the function declaration. Turns out all I needed was to define functions:
routes:
handler: handler.stuff
events:
- http:
method: get
path: stuff
authorizer:
type: COGNITO_USER_POOLS
authorizerId:
Ref: UserPoolAuthorizer <-- <CREATED RESOURCE> ( with the Resource creation looking like ) Resources:
UserPoolAuthorizer: <-- <CREATED RESOURCE>
Type: AWS::ApiGateway::Authorizer
Properties:
Name: UserPoolAuthorizer
ProviderARNs:
- ${self:custom.UserPoolArn}
Type: COGNITO_USER_POOLS
IdentitySource: method.request.header.Authorization
RestApiId: !Ref ApiGatewayRestApi |
I seem to still be running into this issue with the new HTTPApi authorizers. For me, I have a shared service that defines a common API with:
Then, in my other service, I'm attempting to reference it (after successfully deploying the above) with:
But no luck. I get the error: I've tried everything suggested above with no luck :-( I've just spotted #7598 which seems to describe this issue too. |
This worked for me. Thank you! |
This is a (Bug Report)
Description
I have two services (e.g. Service-A and Service-B) that shares the same API Gateway. Service-A has some public/private endpoints and defines an API GW authorizer. This works fine.
Service-B has some private endpoints that need to use the authorizer defined in Service-A. I tried to reference the authorizer by ARN with no success. I think the problem is that serverless tries to create another authorizer in the same API GW, and throws error because an authorizer with the same name already exists. The thing is that I dont want to create another API GW authorizer, I just want to reference an authorizer that belongs to the API GW.
Output relevant to Service-A
Output relevant to Service-B
Having Service-A and Service-B within the same API GW, I expect to be able to reference the authorizer already defined by Service-A.
I have tried this alternatives in Service-B
An error occurred: AuthorizerApiGatewayAuthorizer - Authorizer name must be unique. Authorizer authorizer already exists in this RestApi..
Additional Data
The text was updated successfully, but these errors were encountered: