{"id":20434975,"url":"https://github.com/peter-oroszvari/aws_websocket_authorizer","last_synced_at":"2026-06-10T14:31:12.553Z","repository":{"id":153074045,"uuid":"623281763","full_name":"peter-oroszvari/aws_websocket_authorizer","owner":"peter-oroszvari","description":"Cognito Auth Lambda: A custom python authorizer for API Gateway that authenticates users with Amazon Cognito User Pools. This AWS Lambda function verifies access tokens and generates IAM policies for secure API access control.","archived":false,"fork":false,"pushed_at":"2023-04-04T04:25:31.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-05T06:34:11.987Z","etag":null,"topics":["aws-api-gateway","aws-lambda","python","websocket"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peter-oroszvari.png","metadata":{"files":{"readme":"Readme.MD","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-04T04:00:39.000Z","updated_at":"2023-04-04T04:30:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"5001f3c6-6495-47e3-9e42-bcffdd93e110","html_url":"https://github.com/peter-oroszvari/aws_websocket_authorizer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peter-oroszvari/aws_websocket_authorizer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-oroszvari%2Faws_websocket_authorizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-oroszvari%2Faws_websocket_authorizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-oroszvari%2Faws_websocket_authorizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-oroszvari%2Faws_websocket_authorizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter-oroszvari","download_url":"https://codeload.github.com/peter-oroszvari/aws_websocket_authorizer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter-oroszvari%2Faws_websocket_authorizer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34157453,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-api-gateway","aws-lambda","python","websocket"],"created_at":"2024-11-15T08:29:53.099Z","updated_at":"2026-06-10T14:31:12.535Z","avatar_url":"https://github.com/peter-oroszvari.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cognito Auth Lambda\n\nThis AWS Lambda function is a custom authorizer for API Gateway that authenticates users using Amazon Cognito User Pools. When a request is made to the API Gateway, this Lambda function will be invoked to verify the user's access token and generate an IAM policy based on the provided token.\nNote: In React.js with react-use-websocket, passing tokens through headers may not work (or at least it was not achievable in this implementation), so this solution utilizes query strings for token passing as a reliable alternative.\n## Requirements\n\n- Python 3.9\n- AWS Lambda\n- Amazon API Gateway\n- Amazon Cognito User Pool\n- Boto3 library\n\n## Environment Variables\n\n- `COGNITO_REGION`: The AWS region where your Cognito User Pool is located.\n- `COGNITO_USER_POOL_ID`: The ID of your Cognito User Pool.\n- `COGNITO_APP_CLIENT_ID`: The App Client ID of your Cognito User Pool.\n\n## Deployment\n\n1. Create a virtual environment and install the required packages:\n\n```bash\npython3 -m venv venv\nsource venv/bin/activate\npip install -r requirements.txt\n```\n\n2. Package the Lambda function and dependencies:\n\n```bash\ncd $PROJECT_DIR\nmkdir package\ncp -r venv/lib/python3.9/site-packages/* package/\ncp lambda_function.py package/\ncd package\nzip -r ../lambda_function.zip .\ncd ..\n```\n\n3. Create the Lambda function in AWS Management Console, and upload the lambda_function.zip file.\n\n4. Set the required environment variables in the AWS Lambda function configuration.\n\n5. In the API Gateway, create a custom authorizer and select the Lambda function you created.\n\n6. Attach the custom authorizer to the desired API routes.\n\n## Usage \n\nhttps://your-api-id.execute-api.your-region.amazonaws.com/your-stage/your-resource?token=YOUR_ACCESS_TOKEN\n\n\nIf the access token is valid, the Lambda function will return a generated IAM policy to grant access to the requested API route. If the token is invalid or missing, the request will be denied.\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-oroszvari%2Faws_websocket_authorizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter-oroszvari%2Faws_websocket_authorizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter-oroszvari%2Faws_websocket_authorizer/lists"}