Deploy Moyai on AWS
This Terraform deployment runs Moyai, Temporal, and a LiteLLM gateway on one private EC2 host. The worker calls Bedrock through LiteLLM using the host's IAM role. It sends shell and file operations to Lambda MicroVMs. This is a single-host installation with no automatic application failover.
Infrastructure
Open the full-size infrastructure diagram
The browser reaches EC2 through an HTTPS load balancer. Operators reach the host through Systems Manager. RDS PostgreSQL stores application records. S3 stores saved files and workspace checkpoints. Encrypted EBS holds installation keys and Temporal's database. The MicroVM guest has no IAM execution role or model credentials.
Before you start
Use an AWS region where your account can build images and launch Lambda MicroVMs. You also need an enabled Bedrock model or inference profile, an existing public Route 53 hosted zone, an unused hostname, and permission to provision the stack and run SSM commands. The stack incurs charges for the host, networking, and storage even when no task is running.
Install Git, the AWS CLI, Terraform 1.9 or newer but below 2.0, Docker with an AMD64 Buildx builder, and uv. The source build requires Python 3.13, Node.js 22 or newer, and Rust 1.88 or newer.
1. Provision the infrastructure
git clone https://github.com/BerriAI/moyai.git
cd moyai
uv sync --frozen
aws sts get-caller-identity
cp deploy/aws/terraform.tfvars.example deploy/aws/terraform.tfvars
Confirm the intended AWS account. Set the resource name, region, hostname, Route 53 zone, Bedrock model ID, and allowed inference ARNs in deploy/aws/terraform.tfvars. A cross-region inference profile needs both its own ARN and the destination model ARNs. Leave moyai_image unset for the first apply. For a retained installation, configure encrypted remote Terraform state and locking first.
terraform -chdir=deploy/aws init
terraform -chdir=deploy/aws plan -out=installation.tfplan
terraform -chdir=deploy/aws apply installation.tfplan
2. Build and pin the application image
Use the same checkout for the image and deployment scripts. From the repository root, publish the image to the ECR repository that Terraform created.
MOYAI_REPOSITORY=$(terraform -chdir=deploy/aws output -raw application_repository)
MOYAI_REVISION=$(git rev-parse HEAD)
MOYAI_REGION=$(terraform -chdir=deploy/aws output -json quickstart | python3 -c 'import json,sys; print(json.load(sys.stdin)["region"])')
aws ecr get-login-password --region "$MOYAI_REGION" |
docker login --username AWS --password-stdin "${MOYAI_REPOSITORY%%/*}"
docker buildx build --platform linux/amd64 \
--build-arg MOYAI_BUILD_SHA="$MOYAI_REVISION" \
--tag "$MOYAI_REPOSITORY:$MOYAI_REVISION" --push .
docker logout "${MOYAI_REPOSITORY%%/*}"
aws ecr describe-images --region "$MOYAI_REGION" \
--repository-name "${MOYAI_REPOSITORY#*/}" \
--image-ids "imageTag=$MOYAI_REVISION" \
--query 'imageDetails[0].imageDigest' --output text
Set moyai_image in terraform.tfvars to the repository URL followed by @ and the returned sha256: digest. Apply the updated configuration.
terraform -chdir=deploy/aws plan -out=application.tfplan
terraform -chdir=deploy/aws apply application.tfplan
3. Install and sign in
Generate the installation credentials in Secrets Manager, build the ARM64 guest image, and install the services on EC2. The first command below sets up a browser-only installation. To enable Slack at installation, supply the Slack settings at this step.
uv run python deploy/aws/quickstart.py secrets
uv run python deploy/aws/quickstart.py image
uv run python deploy/aws/quickstart.py install
uv run python deploy/aws/quickstart.py status
terraform -chdir=deploy/aws output -raw app_url
Once status reports successful installation, open app_url. Sign in as admin using WORKSPACE_PASSWORD from the installation's runtime secret in Secrets Manager. To find the secret, run terraform -chdir=deploy/aws output -raw runtime_secret_arn.
4. Verify execution and recovery
Run the file task and download the result. After the session's VM becomes idle and suspends, ask Moyai to read the file in the same conversation. The same VM can resume with memory and processes intact until its lifetime expires.
After expiry, a replacement VM restores the last accepted S3 filesystem checkpoint. Keep the referenced guest image versions and use S3-managed encryption (SSE-S3) for checkpoints. To qualify a deployment, test both suspend/resume and recovery after expiry. MicroVM recovery checks
For changes to an existing installation, follow the maintenance procedure. To remove a trial, follow the AWS teardown guide for retained buckets, guest images, ECR images, and backups.