I am having trouble trying to set up a lambda authorizations for a WebSocket API.
Serverless.yml
functions:
sample-web-socket-authorizer:
iamRoleStatementsName: stack-${opt:stage}-web-socket-authorizer
iamRoleStatementsInherit: true
iamRoleStatements:
- Effect: "Allow"
Action:
- 'cognito-idp:*'
Resource: '*'
handler: sample-web-socket-authorizer/handler.handler
environment:
JWK_URL: ${self:custom.jwkUrl}
CLIENT_ID: ${self:custom.cognitoClientId}
...
connectionHandler:
handler: handler.connectionHandler
events:
- websocket:
route: $connect
authorizer:
name: sample-web-socket-authorizer
identitySource:
- 'route.request.querystring.Authorizer'
in frontend i want to send a tokenId or accessToken to use in authorizer
wss://abcd1234.execute-api.ap-region-1.amazonaws.com/pre?Authorizer=${token}
Can u guys please give me a sample code using python to create a lambda authorizer for my websocket api.
I am currently looking at these article: https://github.com/awslabs/aws-support-tools/blob/master/Cognito/decode-verify-jwt/decode-verify-jwt.py
So what i do is that i literally copy this code to my authorizer handler: https://github.com/awslabs/aws-apigateway-lambda-authorizer-blueprints/blob/master/blueprints/python/api-gateway-authorizer-python.py
and then base on this docs https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-lambda-auth.html
I changed the code
to
also you need to specify the methodArn in the AuthPolicy Class that look like this:
And then lastly upon creating the AuthPolicy add the methodArn Value comming from lambda event: