Skip to main content

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.

Python License Version


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)
  • .env files (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

  1. Scans all AWS regions to find your Lambda functions
  2. Checks Function URL configuration to see if CORS is enabled
  3. Scans API Gateway (HTTP and REST APIs) to find connected Lambdas
  4. Reports CORS status for each access method

CORS Fixing

  1. Detects or prompts for allowed origins from your project files
  2. Applies CORS configuration via AWS API:
    • AllowOrigins: Your specified origins
    • AllowMethods: All HTTP methods
    • AllowHeaders: All headers
    • MaxAge: 24 hours
  3. 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:

  1. Use AWS Console → API Gateway → Your API → CORS
  2. Enable CORS manually
  3. 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:

  1. Is your origin URL correct? (https vs http, www vs non-www)
  2. Did you clear browser cache?
  3. Is your Lambda behind a proxy integration? (Check AWS Console)
  4. 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

  • Built with Click (CLI framework)
  • Styled with Rich (terminal formatting)
  • Powered by boto3 (AWS SDK)

Support


Star History

If this tool saved you time, please ⭐ star the repo!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_integration_assistant-1.0.0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_integration_assistant-1.0.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file aws_integration_assistant-1.0.0.tar.gz.

File metadata

File hashes

Hashes for aws_integration_assistant-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a1accd2a2ce9f6baaa68ac0677ce4c0a43cb24445d47831c961b79e007fd7c76
MD5 978d924ce35515f49b91a49d0587c315
BLAKE2b-256 739be91f7d3241e46a08e47aadfbfba6f0d139448600c92aed4960a508990258

See more details on using hashes here.

File details

Details for the file aws_integration_assistant-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_integration_assistant-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05d31bf7dd8c7f0d832473c5604b7c85a68d9003019def2e6ea080dd4dbba457
MD5 597d6d2e9561ab5d0e2e2812a8ebcdd2
BLAKE2b-256 e25dda6e96dd85b821bd7adc9f5f5a825bbcb48a0605713068f5388f1e6a10bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page