I always get 403
forbidden all the time. Here’s the github code
Serverless URL: https://hr4nwgnf96.execute-api.ap-southeast-2.amazonaws.com/dev/hello?auth=yes
Sam URL: https://7jjym0ms9g.execute-api.ap-southeast-2.amazonaws.com/dev/hello?auth=yes
You can test both URL's above in postman and clearly see that
- sam url is working fine
- serverless framework url always returning 403
Serverless template:
service: sls-api-gateway-request-auth
frameworkVersion: '3'
configValidationMode: error
provider:
name: aws
region: ap-southeast-2
runtime: nodejs14.x
timeout: 30
functions:
authFunction:
handler: ./auth.lambda_handler
backendFunction:
handler: ./backend.lambda_handler
runtime: nodejs14.x
events:
- http:
method: get
cors: true
path: /auth
authorizer:
name: authFunction
type: request
Outputs:
MyApiAuth:
Description: "API Gateway endpoint URL for dev stage for api key validation in query string"
Value: !Sub "https://{sls:instanceId}.execute-api.${AWS::Region}.amazonaws.com/dev/hello?auth=yes"
Here’s the SAM template which is working fine:
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
Auth:
DefaultAuthorizer: MyLambdaRequestAuthorizer
Authorizers:
MyLambdaRequestAuthorizer:
FunctionPayloadType: REQUEST
FunctionArn: !GetAtt authFunction.Arn
Identity:
QueryStrings:
- auth
ReauthorizeEvery: 100
backendFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: backend.lambda_handler
Runtime: nodejs10.x
CodeUri: .
Events:
HelloAPI:
Type: Api
Properties:
RestApiId: !Ref MyApi
Path: /hello
Method: GET
authFunction:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: .
Handler: auth.lambda_handler
Runtime: nodejs10.x
Outputs:
ApiUrl:
Description: "API endpoint URL"
Value: !Sub 'https://${MyApi}.execute-api.${AWS::Region}.amazonaws.com/dev/hello?auth=yes'
I want this to be implemented using serverless framework. I am not sure why it isn’t working. I followed what ever is mentioned in official docs. Did I miss anything?