I’m relatively new to the serverless framework. I want to grant access to my endpoints via a cognito user pool. I’ve created the user pool in the AWS console directly. I then deployed my function for the corresponding end point and added the authorizer in the console too.
Afterwards I’ve added the following authorizer snippet to my serverless.yml file:
functions:
test1:
handler: handler.test1
events:
- http:
path: /test1
method: post
integration: lambda
request:
template:
application/json: "$input.json('$')"
response:
headers:
Content-Type: "'application/json'"
authorizer:
arn: arn:YYYYYYYYYY:XXXXXXXXXXXXXXXX
It looks like my end point is still working correctly, using the cognito pool for access. I then added a second endpoint where I wanted to define everything in the serverless.yml in the first place. So I’ve added this snippet to the function section
test2:
handler: handler.test2
events:
- http:
path: /test2
method: post
integration: lambda
request:
template:
application/json: "$input.json('$')"
response:
headers:
Content-Type: "'application/json'"
authorizer:
arn: arn:YYYYYYYYYY:XXXXXXXXXXXXXXXX
Using the same user pool arn as for method test1
. However, this result in an error when I try to deploy:
An error occurred: ApiGatewayMethodTest2Post - Invalid authorizer ID specified. Setting the authorization type to CUSTOM or COGNIT_USER_POOLS requires a valid authorizer.
Now I’m asking myself two questions:
-
Why isn’t it working for
test2
-
How to use existing user pool for granting access to gateway endpoints?