Automate AWS Lambda CORS configuration in seconds
Project description
AWS Integration Assistant
Automate AWS Lambda CORS configuration in seconds.
Stop wasting hours debugging CORS errors. This CLI tool scans your AWS account, detects CORS issues, and fixes them automatically.
The Problem
You're building a web app with AWS Lambda. Your frontend can't connect to your backend:
Access to fetch at 'https://xxx.lambda-url.us-west-2.on.aws/'
from origin 'https://myapp.com' has been blocked by CORS policy
You spend hours:
- Googling CORS documentation
- Clicking through AWS Console
- Testing different configurations
- Still getting errors
There has to be a better way.
The Solution
# Scan your AWS account
aws-assistant scan
# Fix CORS issues automatically
aws-assistant fix-cors MyFunction --origin https://myapp.com
# Done! Your app works now.
That's it. 30 seconds instead of 30 minutes.
Features
v1.0 (Current)
Lambda Function URL CORS
- Automatic detection across all AWS regions
- One-command fix with proper configuration
- Smart origin detection from your project files
API Gateway HTTP API CORS
- Detects Lambda functions behind HTTP APIs
- Configures CORS automatically
- Supports multiple origins
Smart Origin Detection
- Reads from package.json
- Reads from .env files
- Supports Vercel, React, Next.js, Vite, Vue
Multi-Region Support
- Scans all AWS regions automatically
- Finds functions wherever they are
- No manual region specification needed
Developer-Friendly
- Clear, colorful output
- Helpful error messages
- Example code generation
Installation
Requirements
- Python 3.8 or higher
- AWS credentials configured
Install
# Clone the repository
git clone https://github.com/yourusername/AWS_assistance.git
cd AWS_assistance
# Install in development mode
pip install -e .
Quick Start
1. Configure AWS Credentials
Make sure you have AWS credentials set up:
# Option 1: AWS CLI
aws configure
# Option 2: Environment variables
export AWS_ACCESS_KEY_ID=your_key
export AWS_SECRET_ACCESS_KEY=your_secret
export AWS_DEFAULT_REGION=us-west-2
2. Scan Your Account
aws-assistant scan
You'll see a table showing all your Lambda functions and their CORS status:
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ Function Name ┃ Region ┃ Runtime ┃ Access Type ┃ CORS Status ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ myFunction │ us-west-2 │ nodejs20.x │ Function URL │ NOT CONFIGURED │
│ apiFunction │ us-west-2 │ python3.12 │ HTTP API │ CONFIGURED │
└────────────────────┴───────────┴────────────┴───────────────┴────────────────┘
3. Fix CORS Issues
Automatic origin detection:
aws-assistant fix-cors myFunction
The tool will detect your app's origin from:
package.json(homepage field).envfiles (REACT_APP_URL, NEXT_PUBLIC_URL, etc.)vercel.json
Manual origin specification:
aws-assistant fix-cors myFunction --origin https://myapp.com
Multiple origins:
aws-assistant fix-cors myFunction --origin http://localhost:3000 --origin https://myapp.com
🤝 Contributing
This is an early beta. Feedback and contributions welcome!
📄 License
MIT
Usage Examples
Scenario 1: React App in Development
# Your React app runs on localhost:3000
# Fix CORS for local development
aws-assistant fix-cors myBackendFunction --origin http://localhost:3000
Scenario 2: Production Deployment
# Your production app is at https://myapp.com
# Fix CORS for production
aws-assistant fix-cors myBackendFunction --origin https://myapp.com
Scenario 3: Multiple Environments
# Support both local development and production
aws-assistant fix-cors myFunction \
--origin http://localhost:3000 \
--origin https://staging.myapp.com \
--origin https://myapp.com
Scenario 4: Function Behind API Gateway
# Your function is behind API Gateway HTTP API
# Tool detects this automatically and fixes both
aws-assistant fix-cors myFunction --target all --origin https://myapp.com
Advanced Usage
Target Specific Access Methods
If your Lambda has both Function URL and API Gateway:
# Fix only Function URL CORS
aws-assistant fix-cors myFunction --target url --origin https://myapp.com
# Fix only API Gateway CORS
aws-assistant fix-cors myFunction --target api --origin https://myapp.com
# Fix both
aws-assistant fix-cors myFunction --target all --origin https://myapp.com
Specify Region
# If you know which region your function is in
aws-assistant fix-cors myFunction --region us-west-2 --origin https://myapp.com
Required AWS Permissions
Your AWS credentials need these permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:ListFunctions",
"lambda:GetFunction",
"lambda:GetFunctionUrlConfig",
"lambda:UpdateFunctionUrlConfig",
"apigatewayv2:GetApis",
"apigatewayv2:GetIntegrations",
"apigatewayv2:UpdateApi",
"ec2:DescribeRegions"
],
"Resource": "*"
}
]
}
How It Works
CORS Detection
- Scans all AWS regions to find your Lambda functions
- Checks Function URL configuration to see if CORS is enabled
- Scans API Gateway (HTTP and REST APIs) to find connected Lambdas
- Reports CORS status for each access method
CORS Fixing
- Detects or prompts for allowed origins from your project files
- Applies CORS configuration via AWS API:
- AllowOrigins: Your specified origins
- AllowMethods: All HTTP methods
- AllowHeaders: All headers
- MaxAge: 24 hours
- Verifies the fix and shows example code
Smart Origin Detection
The tool automatically detects your app's URL from:
package.json:
{
"homepage": "https://myapp.com"
}
.env files:
REACT_APP_URL=https://myapp.com
NEXT_PUBLIC_URL=https://myapp.com
VITE_URL=https://myapp.com
vercel.json:
{
"env": {
"NEXT_PUBLIC_URL": "https://myapp.com"
}
}
Known Limitations
v1.0 Does NOT Support:
❌ REST API CORS - Manual configuration required (coming in v2.0) ❌ Proxy Integration Detection - Cannot detect if backend must return CORS headers ❌ IAM Permission Fixing - Only handles CORS (other features planned) ❌ CloudFormation Integration - Manual resource management only
Current Workarounds:
For REST APIs:
- Use AWS Console → API Gateway → Your API → CORS
- Enable CORS manually
- Deploy to stage
For Proxy Integrations: If using Lambda proxy integration, your function must return CORS headers:
# Python example
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Origin': 'https://myapp.com',
'Content-Type': 'application/json'
},
'body': json.dumps(your_data)
}
Roadmap
v2.0 (Planned)
- Full REST API CORS support with automatic deployment
- Proxy integration detection and guidance
- Credential testing (verify permissions before scanning)
v3.0 (Planned)
- IAM permission detection and fixing
- CloudFormation error diagnosis
- AWS resource cost optimization suggestions
Future Considerations
- CloudWatch log analysis
- API rate limiting detection
- Security best practices scanner
Troubleshooting
"No AWS credentials found"
Solution: Configure AWS credentials:
aws configure
"Function not found"
Solution: Make sure the function name is correct and you have permissions:
aws lambda list-functions --region us-west-2
"CORS still not working"
Check:
- Is your origin URL correct? (https vs http, www vs non-www)
- Did you clear browser cache?
- Is your Lambda behind a proxy integration? (Check AWS Console)
- Are you testing from the correct origin?
"Access Denied" errors
Solution: Add required permissions to your IAM user/role. See Required AWS Permissions.
Contributing
Contributions are welcome!
How to Contribute
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Setup
# Clone your fork
git clone https://github.com/yourusername/AWS_assistance.git
cd AWS_assistance
# Install in development mode
pip install -e .
# Run tests
python -m pytest tests/
License
MIT License - see LICENSE file for details.
Author
Tinsae Built because I was tired of debugging CORS errors on my project.
Acknowledgments
Support
- 🐛 Bug reports: GitHub Issues
- 💬 Questions: GitHub Discussions
Star History
If this tool saved you time, please ⭐ star the repo!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aws_integration_assistant-1.0.0.tar.gz.
File metadata
- Download URL: aws_integration_assistant-1.0.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1accd2a2ce9f6baaa68ac0677ce4c0a43cb24445d47831c961b79e007fd7c76
|
|
| MD5 |
978d924ce35515f49b91a49d0587c315
|
|
| BLAKE2b-256 |
739be91f7d3241e46a08e47aadfbfba6f0d139448600c92aed4960a508990258
|
File details
Details for the file aws_integration_assistant-1.0.0-py3-none-any.whl.
File metadata
- Download URL: aws_integration_assistant-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05d31bf7dd8c7f0d832473c5604b7c85a68d9003019def2e6ea080dd4dbba457
|
|
| MD5 |
597d6d2e9561ab5d0e2e2812a8ebcdd2
|
|
| BLAKE2b-256 |
e25dda6e96dd85b821bd7adc9f5f5a825bbcb48a0605713068f5388f1e6a10bf
|