Skip to main content
Unlisted page
This page is unlisted. Search engines will not index it, and only users having a direct link can access it.

Deploy Retool on Amazon ECS with Amazon EC2

Retool provides an AWS CloudFormation template, retool-r2.ec2.yaml, that deploys a complete self-hosted instance of Retool on Amazon ECS, using Amazon EC2 instances in your AWS account. The stack includes the Retool app builder, Workflows, and optionally Agents. It creates its own Amazon ECS cluster, database, storage buckets, and load balancer, so it can't deploy into an existing cluster.

Budget roughly 1-3 hours from creating the stack to a working login page, though actual time varies depending on your cloud environment and account configuration. Stack creation, DNS propagation, and certificate issuance can each take longer than expected.

Kubernetes is the recommended production platform

Retool recommends deploying production instances on Kubernetes using the Terraform blueprints. If you can't deploy a Kubernetes cluster, use this template to run Retool on Amazon ECS until you're able to migrate to Kubernetes.

Unlike a single-VM Docker instance, the stack runs across pools of instances and provisions a managed PostgreSQL database (Amazon RDS) and Amazon S3 buckets for you, so you don't need to externalize either. Retool doesn't guarantee that you can upgrade an existing stack from earlier CloudFormation templates in place.

Deployment architecture​

The stack provisions the following AWS infrastructure and Retool services.

These components support the instance but don't run Retool containers directly.

ComponentPurpose
Amazon ECS clusterNamed after the stack. Runs every Retool service as Amazon ECS tasks.
Platform poolAn Auto Scaling group of Amazon EC2 instances that runs the core Retool services.
Sandbox poolAn Auto Scaling group of Amazon EC2 instances that runs the js-executor and agent sandboxes with hardened Docker settings.
Amazon RDS for PostgreSQLStores Retool data such as apps, users, and workflow runs. Retool Database also uses this instance. Deletion protection is on by default.
Amazon Aurora PostgreSQLA dedicated database for Temporal. Created only when you choose the stack-hosted Temporal option.
Amazon S3 bucketsThree encrypted buckets for app snapshots, Git repository storage, and organization packages.
Application Load BalancerThe entry point to your instance. Internal by default.
AWS Secrets Manager secretsStores the database password, the Retool encryption key, and the sandbox keys that you supply.
Amazon CloudWatch Logs log groupCollects container logs.
AWS Cloud Map private DNS namespaceLets services find each other inside your VPC.
Note

The code-executor, js-executor, and agent sandbox run untrusted code inside isolated sandboxes. Much of this code is generated by AI, so Retool doesn't assume it's safe. The sandboxes need privileged containers, custom seccomp profiles, and access to host devices. AWS Fargate doesn't support any of these, so the services must run on Amazon EC2.

The other Retool services can run on either EC2 or Fargate, so you can run the instance as a mixed workload: sandboxed services on EC2, everything else on Fargate, in the same Amazon ECS cluster. The template deploys every service on EC2, so a mixed workload requires editing the template, such as adding the Fargate capacity provider and moving the non-sandbox services onto it.

Refer to Untrusted code sandboxing to learn more about how Retool isolates untrusted code.

Requirements​

Collect the following before you create the stack.

Instance sizing​

The stack launches two pools of Amazon EC2 instances. Both scale automatically between their minimum and maximum sizes.

PoolDefault instance typeMinimumDefaultMaximum
Platformm5.xlarge236
Sandboxm5.2xlarge1210

In the default configuration, the platform pool needs more than its default three instances to place every service. Refer to create the stack to size the pool before you deploy.

Temporal​

Temporal is a distributed system used to schedule and run asynchronous tasks for Retool Workflows and Retool Agents. You choose how your instance uses Temporal in step 1. Refer to the Temporal conceptual guide to learn more.

Network requirements​

Caution

pypi.org is served from a third-party CDN with no fixed IP range, so it isn't included in the CIDR blocks. If your firewall rules require IP-based allowlisting, allow pypi.org by hostname instead. This domain is required for installing Python packages in Workflows Python code blocks.

Self-hosted Retool instances must allow access to Retool's IP addresses or domains. If you make use of outbound firewall rules, include the following IP addresses or domains in the allowlist. These allow your instance to connect to Retool's license check, user authentication, and usage reporting services.

CIDR IP addresses
35.92.202.168/29
44.211.178.248/29
Individual IP addresses
35.92.202.168
35.92.202.169
35.92.202.170
35.92.202.171
35.92.202.172
35.92.202.173
35.92.202.174
35.92.202.175
44.211.178.248
44.211.178.249
44.211.178.250
44.211.178.251
44.211.178.252
44.211.178.253
44.211.178.254
44.211.178.255
Domains
licensing.tryretool.com
invites.tryretool.com
email-service.retool.com
p.tryretool.com
specs.tryretool.com
pypi.org

By default, the stack pulls container images from Docker Hub. Your private subnets need outbound internet access to reach it, or you can use a private image registry.

Note

Egress is required when using Retool-managed Temporal. Refer to the Egress section of the Temporal conceptual guide for more information.

1. Prepare the stack inputs​

Gather the template, the sandbox keys, and your Temporal choice. You use all three as inputs when you create the stack in step 2.

Download the template​

Download the template from the retool-onpremise GitHub repository.

Download with curl
curl -L -O https://raw.githubusercontent.com/tryretool/retool-onpremise/refs/heads/master/cloudformation/retool-r2.ec2.yaml

Generate the sandbox keys​

The sandbox services need a public and private key pair and an encryption key. CloudFormation can't generate these, so you generate them now and enter the values as stack parameters in step 2.

Generate a private key and its matching public key
openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out ae.key
openssl ec -in ae.key -pubout -out ae.pub
Generate the encryption key
openssl rand -hex 32

You enter the contents of ae.key as AgentSandboxJwtPrivateKey, the contents of ae.pub as AgentSandboxJwtPublicKey, and the hex string as AgentSandboxEncryptionKey. Save all three values in a secure location outside of AWS and don't commit them to source control. You must provide the same values each time you update the stack from the AWS CLI.

Don't change the sandbox encryption key

Changing AgentSandboxEncryptionKey after deployment makes credentials encrypted with the original key inaccessible.

Choose a Temporal option​

Retool Workflows and Agents require Temporal. Choose how your instance uses Temporal, and then set the matching parameters in step 2. In most cases, a Retool-managed cluster is the lowest-friction, lowest-cost, and most reliable option, and is recommended unless you have a specific reason to self-manage.

Note

The template deploys a Temporal cluster in your AWS account by default (TemporalBackend is self-hosted). To use a Retool-managed cluster, set TemporalBackend to retool-managed explicitly. The template doesn't include a parameter for connecting to an existing Temporal cluster.

Recommended

Retool hosts and manages a Temporal Cloud cluster for you. The stack deploys no Temporal services or database. Set TemporalBackend to retool-managed.

After you sign in to Retool for the first time, you complete a one-time enrollment in the Retool UI. Refer to complete setup in Retool.

Your instance needs outbound egress on ports 443 and 7233 to *.retool.com, *.tryretool.com, *.temporal.io, and *.tmprl.cloud.

Choose features​

Two parameters control which Temporal-based features the stack deploys.

ParameterDefaultDescription
EnableWorkflowstrueDeploys the Workflows backend and worker. Requires a Temporal backend.
EnableAgentsfalseDeploys the Agents workers. Requires a Temporal backend. You must also turn on the AI Agents toggle in the Retool UI after sign-in.

The template rejects combinations that conflict with your Temporal choice. For example, TemporalBackend set to none requires EnableWorkflows set to false.

2. Create the stack​

Create a CloudFormation stack from the template. You enter the parameters in the AWS Console or pass them with the AWS CLI. Gather the values from the following tables first.

Set the required parameters​

These parameters have no default, or must be set for the stack to work.

ParameterWhat to enter
EnvironmentA short label for this instance, such as production. It appears in logs.
VpcIdThe VPC to deploy into.
SubnetIdAt least two private subnets in the VPC. The services, Amazon EC2 instances, and databases run here.
ALBSubnetIdThe subnets for the load balancer.
RetoolVersionThe Retool version to deploy. Use the current stable release, 4.86.2-stable. The version must be 4.34.10-stable, 4.78-edge, or later. If you set TemporalBackend to none, use 4.78-edge or later.
LicenseKeyYour Retool license key.
AgentSandboxJwtPrivateKeyThe full contents of ae.key.
AgentSandboxJwtPublicKeyThe full contents of ae.pub.
AgentSandboxEncryptionKeyThe hex string from openssl rand -hex 32.
TemporalBackendYour Temporal choice: retool-managed, self-hosted, or none.
EnableWorkflows and EnableAgentsYour feature choices.

These parameters have working defaults, but production instances typically change them.

ParameterWhat to enter
RdsStorageEncryptedtrue. Encrypts the databases at rest. You can't enable encryption on an existing database without migrating it with pg_dump.
RdsDeletionProtectionLeave as true, the default. Deletion protection prevents accidental deletion of the databases, but blocks any update that replaces them.
CertificateArnThe ARN of your ACM certificate. When set, the load balancer serves HTTPS and redirects HTTP to HTTPS.
AlbSchemeinternal (default) or internet-facing. An internet-facing load balancer requires a CertificateArn.
BaseDomainThe URL users open, such as https://retool.example.com. If empty, Retool uses the load balancer's DNS name.
PlatformAsgDesiredCapacity5, or 6 if you set EnableAgents to true. Refer to the following section.
CloudMapNamespaceNameSet only if the VPC already hosts another Retool instance. Namespace names are unique within a VPC, so use a different name, such as retoolsvc-2.

Size the platform pool​

Every task on the platform pool gets its own network interface (ENI), and an m5.xlarge instance supports only three ENIs for Amazon ECS tasks. The default stack runs more than a dozen platform tasks, so it needs about five instances before every service can be placed (six with Agents). The pool scales out on its own, but starting at the default of three leaves some services pending until the new instances launch. Setting PlatformAsgDesiredCapacity to 5 avoids the wait.

Enable awsvpc trunking to run more tasks on each instance

awsvpc trunking raises the number of task ENIs each instance supports. Trunking is free, but the stack can't enable it, so you turn it on manually, once. CPU and memory then become the limit on how many tasks each instance runs.

Trunking requires that the instance has resource-based IPv4 DNS records turned off, which is the AWS default. Instances in shared subnets aren't supported. Trunking applies as instances start, so instances that are already running don't use it until they're replaced.

To enable trunking for every instance in your AWS account, run the following before you create the stack:

Enable trunking for the AWS account
aws ecs put-account-setting-default --name awsvpcTrunking --value enabled

To enable trunking only for this stack, run the following after you create the stack. The first command finds the instance role the stack uses, and the second enables trunking for it.

Find the instance role name
aws cloudformation describe-stack-resource \
--stack-name <stack-name> \
--logical-resource-id EcsInstanceRole \
--query 'StackResourceDetail.PhysicalResourceId' \
--output text
Enable trunking for the instance role
aws ecs put-account-setting \
--name awsvpcTrunking \
--value enabled \
--principal-arn arn:aws:iam::<aws-account-id>:role/<role-name>

Then replace the platform instances so they start with trunking enabled. The refresh replaces instances gradually and keeps most services running.

Replace the platform instances
ASG=$(aws cloudformation describe-stack-resource \
--stack-name <stack-name> \
--logical-resource-id PlatformAutoScalingGroup \
--query 'StackResourceDetail.PhysicalResourceId' \
--output text)

aws autoscaling start-instance-refresh \
--auto-scaling-group-name "$ASG" \
--preferences '{"MinHealthyPercent": 90, "InstanceWarmup": 300}'

Refer to the Amazon ECS documentation for more information about awsvpc trunking.

Deploy the stack​

  1. In the AWS Management Console, go to CloudFormation and select Create stack > With new resources (standard).
  2. Under Specify template, select Upload a template file, choose retool-r2.ec2.yaml, and select Next. CloudFormation uploads the template to a bucket it manages and validates it.
  3. Enter a stack name, such as retool. The stack name becomes the name of the Amazon ECS cluster and the prefix for the load balancer's name, which AWS limits to 32 characters, so keep it short.
  4. Enter the parameters from the previous tables, and then select Next.
  5. On Configure stack options, keep the defaults and select Next.
  6. On the review page, under Capabilities, acknowledge that CloudFormation can create IAM resources, and then select Submit.

CloudFormation creates the database, load balancer, and Amazon EC2 capacity first, and then launches the Retool services that depend on them. Follow progress on the stack's Events tab. The stack is ready when its status is CREATE_COMPLETE.

The database and Amazon EC2 instances typically take the longest to create. If the stack rolls back, refer to Troubleshooting.

3. Secure your credentials​

After the stack is created, save the encryption key it generated and confirm that its generated database password works with the sandbox services.

Back up encryption keys​

The stack generates the value of ENCRYPTION_KEY and stores it in Secrets Manager. This key encrypts secrets for your Retool resources. Retrieve it and save it in a secure location outside of AWS.

Retrieve the Retool encryption key
KEY_SECRET=$(aws cloudformation describe-stack-resource \
--stack-name <stack-name> \
--logical-resource-id RetoolEncryptionKeySecret \
--query 'StackResourceDetail.PhysicalResourceId' \
--output text)

aws secretsmanager get-secret-value \
--secret-id "$KEY_SECRET" \
--query SecretString \
--output text

The command returns a JSON object. The encryption key is the value of its password field.

Encryption key cannot be recovered

You will need to reconfigure all resources if the encryption key is lost. Deleting the stack also deletes its Secrets Manager secrets, though it retains the databases.

Check the database password​

The stack generates the database password and can include characters that are reserved in URLs, such as :, ?, #, [, ], and %. The agent sandbox controller and proxy embed the password in a connection URL, so these characters prevent them from starting.

Retrieve the password and check whether it contains any of these characters:

Retrieve the database credentials
DB_SECRET=$(aws cloudformation describe-stack-resource \
--stack-name <stack-name> \
--logical-resource-id RetoolRDSSecret \
--query 'StackResourceDetail.PhysicalResourceId' \
--output text)

aws secretsmanager get-secret-value \
--secret-id "$DB_SECRET" \
--query SecretString \
--output text

If the password contains none of these characters, continue to the next step. If it does, rotate it.

Rotate the database password

Generate a new password without reserved characters, apply it to the database, and store it in the secret.

Set a new database password
NEWPASS=$(openssl rand -base64 24 | tr -d '"@/\\:?#[]% ')

DB_ID=$(aws cloudformation describe-stack-resource \
--stack-name <stack-name> \
--logical-resource-id RetoolRDSInstance \
--query 'StackResourceDetail.PhysicalResourceId' \
--output text)

aws rds modify-db-instance \
--db-instance-identifier "$DB_ID" \
--master-user-password "$NEWPASS" \
--apply-immediately

aws secretsmanager put-secret-value \
--secret-id "$DB_SECRET" \
--secret-string "{\"username\":\"retool\",\"password\":\"$NEWPASS\"}"

The agent sandbox controller and proxy read the password from their task definitions, and CloudFormation doesn't detect a changed secret value. Update the stack and change the Force parameter to any new value, such as a timestamp, and leave every other parameter unchanged. The update redeploys most services.

The agent worker and MCP server services don't pick up the change from the Force update. Find their names with aws ecs list-services --cluster <stack-name> and restart each one:

Restart a service
aws ecs update-service \
--cluster <stack-name> \
--service <service-name> \
--force-new-deployment
Caution

Don't change the GenerateSecretString settings of the RetoolRDSSecret resource in the template. CloudFormation regenerates the secret but leaves the database password as is, and every service then fails to sign in to the database.

4. Connect to your instance​

Point your domain at the load balancer, and then confirm that every service is running.

Configure DNS and HTTPS​

Find the load balancer's address, and then point your domain at it. Go to your stack in CloudFormation, open the Outputs tab, and copy the value of ECSALB. This is the load balancer's DNS name.

If you set a CertificateArn and BaseDomain, create a DNS record, such as a CNAME or an Amazon Route 53 alias, that points your domain at the load balancer's DNS name. Don't open the load balancer's DNS name directly over HTTPS. The certificate matches your domain, not that address, so the browser shows a certificate error.

If you left CertificateArn empty, open http:// followed by the load balancer's DNS name. The stack then serves HTTP only, which isn't suitable for production use. To add HTTPS later, update the stack with a CertificateArn and a BaseDomain.

Note

An internal load balancer, the default, is reachable only from inside your VPC and networks connected to it, such as through a VPN. To make your instance reachable from the internet, set AlbScheme to internet-facing, which also requires a CertificateArn.

Verify the instance​

Before you set up Retool, confirm that every service is running. In the AWS Management Console, go to Elastic Container Service, open the cluster named after your stack, and check the Services tab. Each service shows its running tasks compared to its desired tasks.

You can also check from the AWS CLI. The following command lists each service with its desired and running counts:

Check service counts
for s in $(aws ecs list-services --cluster <stack-name> --query 'serviceArns[]' --output text); do
aws ecs describe-services --cluster <stack-name> --services "$s" \
--query 'services[0].[serviceName,desiredCount,runningCount]' --output text
done

All services should reach a running count equal to their desired count. Services can take several minutes to stabilize while the platform pool scales out. If a service stays pending, refer to Troubleshooting.

5. Complete setup in Retool​

Once the services are healthy, navigate to the Signup and create your user account. The first user account of the organization is automatically the default admin.

note

After you sign up, the instance performs some one-time setup steps in the background. If a feature doesn't seem to work right away, wait a few minutes before troubleshooting further.

Enroll in Retool-managed Temporal​

If you chose a Retool-managed cluster, enroll your instance. Go to Settings → Workflows and click Enroll now. Once your namespace initializes, return to the page and click Complete setup.

Configure and enable AI functionality​

Retool's AI features are not enabled by default. You must first create an AI resource using an API key from your AI provider, then enable the features to use.

Create an AI resource​

This tutorial uses a bring-your-own-key (BYOK) credential for AI features. Navigate to the Resources page and create an AI resource using a supported AI provider. You can also configure Retool-managed keys.

Enable features​

Navigate to the AI settings page and enable the features you plan to use. Retool AI Access is the main control for all AI features and must be enabled first.

FeatureDescription
Retool AI AccessMain control for all AI features. Must be enabled before any other feature below.
AI App BuilderRequired to build and edit apps in the app builder. Disabling this setting restricts users to the classic app builder.
AI resource queriesUse AI to power workflows and apps, from summarization and classification to query generation, within the classic app builder. Refer to AI resource queries.
AI AgentsBuild and deploy autonomous Agents that can reason over data, docs, and actions. Requires EnableAgents to be true.
Vector StorageStore text embeddings in a Retool-managed vector store to provide context to AI models.
Ask AIEnable prompt-based code assistance in the query editor to generate, edit, or troubleshoot queries.
Agent SharingAllow users to share public chat threads with an AI Agent.
Function Generation for AgentsFunction generation within AI agents.
note

After enabling AI App Builder, log out and log back in for the change to take effect.

Verify your setup​

After completing the configuration in Retool, confirm everything functions correctly end to end.

Confirm that your stack parameters include the settings that this guide recommends:

Additional configuration​

Note

The use of environment variables is often necessary to configure SSO, source control, and other self-hosted features. The stack sets the environment variables for each service, so changes to them require editing the template.

Restrict access to the load balancer​

By default, AlbIngressCidr is 0.0.0.0/0, which allows any address that can route to the load balancer to connect on ports 80 and 443. Set AlbIngressCidr to the IP range of your network or VPN. Alternatively, set AlbIngressSourceSecurityGroupId to a security group ID, which takes precedence over AlbIngressCidr when both are set.

Use a private image registry​

By default, the stack pulls images from the tryretool repositories on Docker Hub. To pull from a private registry, such as an Amazon ECR mirror, set BackendImageRepository, CodeExecutorImageRepository, JsExecutorImageRepository, and AgentSandboxImageRepository. The image tag is always the value of RetoolVersion, so that version must exist in every repository you use.

Scale services​

Each service runs one task by default. Set the DesiredCount, DesiredWorkflowsCount, DesiredCodeExecutorCount, DesiredJsExecutorCount, and DesiredAgentsCount parameters to run more copies. To scale the code-executor and js-executor automatically on CPU utilization, set EnableCodeExecutorAutoscaling or EnableJsExecutorAutoscaling to true and set the matching *MaxCount parameter above the desired count.

Scaling services adds tasks, and each pool must have room for them. Adjust PlatformAsgMaxSize and SandboxAsgMaxSize to match. Set SandboxAsgMinSize to your steady-state sandbox pool size, and SandboxPrewarmPoolSize to the number of agent sandboxes to keep ready. A higher value starts sessions faster but costs more.

Restrict sandbox egress​

By default, agent sandboxes can reach any domain that Retool doesn't block. To restrict them, set AllowedDomains to a comma-separated list of domains, such as api.openai.com,api.anthropic.com.

Use a custom AMI​

By default, the pools use the Amazon Linux 2023 ECS-optimized AMI that is current when the instance launches. If you set EcsAmiId to an Ubuntu AMI, you must also install the patched docker-default AppArmor profile from the retool-onpremise repository. Without it, agent sandboxes fail to start.

Single sign-on (SSO)​

Retool supports OpenID Connect (OIDC) and Security Assertion Markup Language (SAML) identity providers. Refer to the SSO quickstart for information on configuring IdP providers.

Source Control​

Source Control allows organizations to manage changes to apps, workflows, resources, and themes using pull requests on remote source control management (SCM) providers, such as GitHub and GitLab.

Update your instance​

Follow these instructions to update your Retool instance to a newer release version.

Back up the instance before performing an update

Retool strongly recommends that you back up the instance before performing an update. At a minimum, you should:

  • Create a snapshot of your Amazon RDS database.
  • Save the Retool encryption key and your stack parameters, including the sandbox keys, in a secure location outside of AWS.

To update your instance to a newer version of self-hosted Retool:

  1. In CloudFormation, select your stack, and then select Update stack > Make a direct update.
  2. Select Use existing template, and then select Next.
  3. Change RetoolVersion to the new version. Leave every other parameter unchanged, including the sandbox keys.
  4. Review the settings and submit the update.

CloudFormation replaces the tasks in each service gradually. If you use the AWS CLI, pass UsePreviousValue=true for every parameter you don't change.

If the version and all parameters are unchanged, CloudFormation doesn't restart the services. To force a redeploy anyway, update the stack and change the Force parameter to any new value.

If you update to a newer version of the template itself, create a change set first and inspect it. Don't execute it if it replaces the Amazon RDS instance, the Aurora cluster, or any Secrets Manager secret.

Troubleshooting​

Use these sections to diagnose and resolve common issues with the stack.

Why did stack creation fail with "Cannot find version"?​

AWS periodically removes old minor versions of PostgreSQL. Run aws rds describe-db-engine-versions --engine postgres to list available versions, and then set PostgresEngineVersion (or TemporalPostgresEngineVersion for the Temporal database) to an available version.

Why are services stuck in a pending state?​

The pool might not have room for the tasks. A host runs out of network interfaces before it runs out of CPU or memory, and a new instance can fail to launch if your account is at its Amazon EC2 vCPU quota. Increase PlatformAsgDesiredCapacity, enable awsvpc trunking, or request a vCPU quota increase.

Why do the agent sandbox controller and proxy fail to start?​

The database password probably contains characters that are reserved in URLs. Refer to check the database password.

Why does the browser show a certificate error?​

You probably opened the load balancer's DNS name over HTTPS. The certificate matches your own domain. Create a DNS record that points your domain at the load balancer, and open your domain instead.

Why can't I reach the instance?​

The load balancer is internal by default, so it's reachable only from inside your VPC. Connect through a VPN or bastion host, or set AlbScheme to internet-facing with a CertificateArn. Also check that AlbIngressCidr or AlbIngressSourceSecurityGroupId allows your network.

Why is an update stuck?​

On a pool with no spare capacity, a replacement task stays pending because the old task is still running. Add capacity before you update, or set MinimumHealthyPercent to 0 to stop each task before its replacement starts. Don't lower MaximumPercent below 200, because a single-task service then can't start its replacement.

Why are Workflows or Agents unavailable?​

Both require Temporal. Confirm that TemporalBackend isn't none and that EnableWorkflows or EnableAgents is true. For a Retool-managed cluster, confirm that you completed the enrollment under Settings → Workflows. For Agents, also turn on AI Agents under Settings → AI.