|
| 1 | +# Computer Use AWS Infrastructure |
| 2 | + |
| 3 | +This project contains the AWS CDK infrastructure code for deploying the Computer Use AWS application in the us-west-2 (Oregon) region. The infrastructure includes ECS Fargate services, ECR repositories, and all necessary networking components. |
| 4 | + |
| 5 | +## Project Structure |
| 6 | + |
| 7 | +``` |
| 8 | +ComputerUseAWS/ |
| 9 | +├── README.md |
| 10 | +├── app.py |
| 11 | +├── cdk.json |
| 12 | +├── computer_use_aws_stack.py |
| 13 | +├── requirements.txt |
| 14 | +├── scripts/ |
| 15 | +│ └── get_urls.sh |
| 16 | +├── computer_use_aws/ |
| 17 | +│ ├── environment_image/ |
| 18 | +│ │ ├── computer_use_demo/ |
| 19 | +│ │ ├── image/ |
| 20 | +│ │ ├── Dockerfile |
| 21 | +│ │ └── requirements.txt |
| 22 | +│ └── orchestration_image/ |
| 23 | +│ ├── computer_use_demo/ |
| 24 | +│ ├── Dockerfile |
| 25 | +│ └── requirements.txt |
| 26 | +└── tests/ |
| 27 | + ├── integration/ |
| 28 | + └── unit/ |
| 29 | +``` |
| 30 | + |
| 31 | +## Prerequisites |
| 32 | + |
| 33 | +1. AWS CLI installed and configured with us-west-2 region |
| 34 | +2. Python 3.7 or later |
| 35 | +3. Node.js 14.x or later (required for CDK) |
| 36 | +4. Docker installed and running |
| 37 | +5. AWS CDK CLI installed (`npm install -g aws-cdk`) |
| 38 | + |
| 39 | +## Quick Start |
| 40 | +1. Clone the repository: |
| 41 | +```bash |
| 42 | +git clone git@ssh.gitlab.aws.dev:jonaevau/ComputerUseAWS.git |
| 43 | +cd ComputerUseAWS |
| 44 | +``` |
| 45 | + |
| 46 | +2. Make the gets_urls.sh cript executable: |
| 47 | +```bash |
| 48 | +chmod +x scripts/gets_urls.sh |
| 49 | +``` |
| 50 | + |
| 51 | +3. Configure AWS CLI for us-west-2 (if not already configured): |
| 52 | +```bash |
| 53 | +aws configure set default.region us-west-2 |
| 54 | +``` |
| 55 | + |
| 56 | +4. Create virtual environment: |
| 57 | +```bash |
| 58 | +python -m venv .venv |
| 59 | +source .venv/bin/activate # On Windows use: .venv\Scripts\activate |
| 60 | +``` |
| 61 | + |
| 62 | +5. Install the required dependencies: |
| 63 | +```bash |
| 64 | +pip install -r requirements.txt |
| 65 | +``` |
| 66 | + |
| 67 | +6. Bootstrap CDK in us-west-2 (if you haven't already): |
| 68 | +```bash |
| 69 | +cdk bootstrap aws://ACCOUNT-NUMBER/us-west-2 |
| 70 | +``` |
| 71 | + |
| 72 | +7. Deploy the solution in **Fail-Secure Mode** (Default). In this mode, if no IP address is provided, the security groups will default to a highly restrictive setting (255.255.255.255/32) that effectively blocks all access. This is the recommended setting for the sandbox environment. |
| 73 | + |
| 74 | +```bash |
| 75 | +# Deploy with your current IP (Fail-Secure) |
| 76 | +cdk deploy --context deployer_ip=$(curl -s https://api.ipify.org) |
| 77 | + |
| 78 | +# Deploy with manual IP (Fail-Secure) |
| 79 | +cdk deploy --context deployer_ip=203.0.113.1 |
| 80 | +# This will automatically be converted to 203.0.113.1/32 |
| 81 | + |
| 82 | +# Deploy with IP address range (Fail-Secure) |
| 83 | +cdk deploy --context deployer_ip=203.0.113.0/24 |
| 84 | +# Allows 203.0.113.0 through 203.0.113.255 |
| 85 | +``` |
| 86 | + |
| 87 | +**Note**: This stack takes ~10-15 minutes to deploy. After the deployment it may take a few additional minutes for the Environment/Virtual Machine to come online |
| 88 | + |
| 89 | +8. After the deploy has completed, you can cet the URLs of the services: |
| 90 | +```bash |
| 91 | +./scripts/get_urls.sh |
| 92 | +``` |
| 93 | + |
| 94 | +**Note**:If you are using aws profiles append --profile <profile name> to the command line if not provided "default" is assumed |
| 95 | +```bash |
| 96 | +./scripts/get_urls.sh --profile <your profile name> |
| 97 | +``` |
| 98 | + |
| 99 | + |
| 100 | +## Usage |
| 101 | + |
| 102 | +Navigate to the links provided in the output of the `get_urls.sh` script to access the services, the Orchestration Service URL and Environment Service URL. |
| 103 | + |
| 104 | +The DCV **username** is `computeruse` and the **password** is `admin`. DCV is used to connect to the environment container for remote desktop access, for activities such as resetting the state of the environment, or elliciting the state of the environment prior to a new task. |
| 105 | + |
| 106 | +The Streamlit interface is used to configure the API provider, model, and other parameters for the environment container. Then ultimately instruct the model via a chat interface to perform tasks. |
| 107 | + |
| 108 | +## GUI Access |
| 109 | + |
| 110 | +After navigating to the Orchestration Service URL (Streamlit interface), you'll need to log in: |
| 111 | + |
| 112 | +1. Default credentials: |
| 113 | + - **Username:** `admin` |
| 114 | + - **Password:** `computeruse` |
| 115 | + |
| 116 | +2. After successful login, you'll see: |
| 117 | + - Configuration panel in the sidebar |
| 118 | + - Chat interface in the main area |
| 119 | + - HTTP Exchange Logs tab for debugging |
| 120 | + |
| 121 | +Note: The session will timeout after 60 minutes of inactivity, requiring you to log in again. |
| 122 | + |
| 123 | +## Infrastructure Components |
| 124 | + |
| 125 | +- **VPC**: Configured with public and private subnets across 2 AZs in us-west-2 |
| 126 | +- **ECR Repository**: Single repository for both environment and orchestration images |
| 127 | +- **ECS Cluster**: Fargate cluster for running containers |
| 128 | +- **Task Definition**: Includes both containers with appropriate port mappings |
| 129 | +- **Security Groups**: |
| 130 | + - Environment container: Accepts traffic only from orchestration container |
| 131 | + - Orchestration container: Accepts public traffic on port 8501 |
| 132 | +- **IAM Roles**: Task execution role with minimal permissions |
| 133 | +- **CloudWatch Logs**: Configured for container logging |
| 134 | +- **KMS**: Encryption key for secure storage |
| 135 | + |
| 136 | +## Container Ports |
| 137 | + |
| 138 | +- **Environment Container**: |
| 139 | + - 8443: DCV |
| 140 | + - 5000: Flask Control API |
| 141 | +- **Orchestration Container**: |
| 142 | + - 8501: Streamlit interface |
| 143 | + |
| 144 | +## Monitoring |
| 145 | + |
| 146 | +- Container insights enabled for the ECS cluster |
| 147 | +- CloudWatch logs configured with KMS encryption |
| 148 | +- VPC flow logs enabled for network monitoring |
| 149 | +- All logs retained for one month |
| 150 | + |
| 151 | +## Troubleshooting |
| 152 | + |
| 153 | +1. If deployment fails: |
| 154 | +```bash |
| 155 | +# Check AWS credentials |
| 156 | +aws sts get-caller-identity |
| 157 | + |
| 158 | +# Check CloudFormation events |
| 159 | +aws cloudformation describe-stack-events --stack-name ComputerUseAwsStack |
| 160 | +``` |
| 161 | + |
| 162 | +2. If containers fail to start: |
| 163 | +```bash |
| 164 | +# Check ECS service events |
| 165 | +aws ecs describe-services --cluster computer-use-aws-cluster --services computer-use-aws-service-computeruseawsstack |
| 166 | + |
| 167 | +# Check container logs |
| 168 | +aws logs get-log-events --log-group-name /ecs/computer-use-aws-computeruseawsstack |
| 169 | +``` |
| 170 | + |
| 171 | +## Clean Up |
| 172 | + |
| 173 | +To destroy the infrastructure: |
| 174 | +```bash |
| 175 | +cdk destroy |
| 176 | +``` |
0 commit comments