This is a simple yet powerful Python-based AI tool that generates code from text instructions using Anthropic Claude (via AWS Bedrock) and automatically saves the output to an Amazon S3 bucket.
Ideal for serverless deployment on AWS Lambda, but also adaptable for local use.
- Uses Claude v2 on AWS Bedrock for natural code generation
- Input prompt: "Write Python code for reversing a list"
- Output: Saved as
.pyfile in S3 - Fully serverless when deployed on Lambda
- Lightweight, fast, and scalable
| File | Purpose |
|---|---|
code_generation.py |
Main script: generates code and saves it to S3 |
boto3Layer.script |
Bash script: creates a boto3 Lambda layer |
boto3_layer.zip |
Pre-built layer to upload to AWS Lambda |
README.md |
Full setup and usage documentation |
requirements.txt |
Optional: Install locally for testing |
event_sample.json |
Sample event input for local testing |
- User sends a text prompt (e.g. “Build a login form in HTML”)
- Claude AI processes the prompt and returns code
- The code is stored as a
.pyfile in your specified S3 bucket
- An AWS account with access to:
- Bedrock
- S3
- Lambda
- An existing S3 bucket (or create one)
- Python 3.x environment (for local testing)
Run this command in your terminal (on Mac/Linux):
bash boto3Layer.scriptThis will:
- Create a virtual environment
- Install
boto3into apython/directory - Zip it into
boto3_layer.zip
- Go to AWS Console → Lambda → Layers → Create layer
- Name it
boto3-layer - Upload
boto3_layer.zip - Select your Python runtime (e.g., Python 3.9)
- After creating, go to your Lambda function → Add layer → select the one you just created
- Create a new Lambda function
- Paste the contents of
code_generation.pyinto the Lambda code editor - Set the handler to:
lambda_handler
- Set Python runtime (same as your layer, e.g. Python 3.9)
- Attach your
boto3layer to the function
s3_bucket = 'your-bucket-name' # Replace with your real bucketYou can also change:
- AWS region:
us-west-2→ your region - Model ID: e.g.,
anthropic.claude-v2→ another Bedrock model
Use the Lambda test tab or an API Gateway to send this payload:
{
"body": {
"message": "Write a Python class for a calculator",
"key": "Python"
}
}A new file appears in your S3 bucket under code-output/HHMMSS.py, containing Claude’s generated code.
You can adapt the script for local use. Just simulate the Lambda input like this:
event = {
"body": json.dumps({
"message": "Create a web server in Node.js",
"key": "JavaScript"
})
}
lambda_handler(event, None)Make sure your local machine has:
pip install boto3
aws configure # Add your credentials- Add HTML/React front-end to collect prompt + display code
- Add support for multiple AI models (Claude, Jurassic, Titan, etc.)
- Return generated code via API (instead of only saving to S3)
MIT License — Free to use and modify.