This directory contains the necessary files to run Inspect Evals on AWS Batch.
- AWS CLI configured with appropriate credentials
- Docker installed locally
# Define the bucket name or create one
export S3_BUCKET_NAME="your-bucket-name"
# Or use a test bucket
# export S3_BUCKET_NAME="inspect-evals-test-$(aws sts get-caller-identity --query Account --output text)"
# Deploy the S3 bucket stack
aws cloudformation deploy \
--template-file cloudformation/s3_bucket.cfn.yaml \
--stack-name inspect-evals-s3 \
--parameter-overrides \
BucketName="$S3_BUCKET_NAME" \
Environment=dev \
EnableVersioning=trueaws cloudformation deploy \
--template-file cloudformation/iam_role.cfn.yaml \
--stack-name inspect-evals-iam \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides Environment=devaws cloudformation deploy \
--template-file cloudformation/secrets.cfn.yaml \
--stack-name inspect-evals-secrets \
--capabilities CAPABILITY_NAMED_IAM \
--parameter-overrides Environment=dev# Get default VPC subnets (or use your preferred VPC/subnets)
vpc_id=$(aws ec2 describe-vpcs --filters "Name=isDefault,Values=true" --query "Vpcs[0].VpcId" --output text)
subnet_ids=$(aws ec2 describe-subnets --filters "Name=vpc-id,Values=$vpc_id" --query "Subnets[*].SubnetId" --output text | tr ' ' ',')
# Deploy the AWS Batch stack
aws cloudformation deploy \
--template-file cloudformation/batch.cfn.yaml \
--stack-name inspect-evals-batch \
--capabilities CAPABILITY_IAM \
--parameter-overrides \
Environment=dev \
VpcId=$vpc_id \
SubnetIds=$subnet_idsThe secrets_manager.py script provides commands for managing the required API keys. See
the .env.template file and secrets_manager.py for more details:
# Source the environment
. ./.env
# Store or update the API key
python secrets_manager.py --env-var OPENAI_API_KEY --value "$OPENAI_API_KEY" --environment dev
# Verify the API key is stored correctly
python secrets_manager.py --env-var OPENAI_API_KEY --get --environment devDo this for all the keys in .env that you need to use in the batch jobs.
Use the provided script to build and push the Docker-in-Docker image to ECR:
./build_and_push_dind.shThis script will:
- Build the Docker image using the
dind.Dockerfilein the parent directory - Create an ECR repository if it doesn't exist
- Log in to ECR
- Tag and push the image to ECR
This will create a Docker image with:
- Ubuntu 24.04 (Noble Numbat) base image
- Python 3.12
- All required dependencies
- Docker-in-Docker capabilities using the internal Docker daemon
Note that Docker-in-Docker is not compatible with AWS Fargate, so the job definition exclusively supports EC2 compute environments.
# Activate the virtual environment
source ../.venv/bin/activate
# Register the job definition
./register_job_definition.pyThe Python script will:
- Automatically retrieve AWS account info and role ARNs from CloudFormation
- Create a job definition with the correct configuration for EC2 compute environments
- Register it with AWS Batch
- Output the job definition ARN and revision number
The job definition includes:
- Docker-in-Docker support for container isolation
- IAM roles configured via CloudFormation
- CloudWatch logging configuration
- Access to all necessary API keys from AWS Secrets Manager
- Automatic upload of evaluation logs to S3
- Environment-specific configuration
At this point you should have everything set up to run evaluations.