AWS ECS on EC2
This document guides you through installing Appsmith using AWS ECS on EC2
Prerequisites
1: Register with Amazon Web Services
If you already have an Amazon Web Services account, you may skip this step.
Please follow the steps detailed here to create an account on AWS.
2: Generate an SSH key pair
If you already have an SSH key pair for the AWS region you are operating in, you can skip this step.
Please follow the steps detailed here to generate a new key pair. You need this key to SSH into your AWS EC2 instance.
3: Create an AWS security group
If you already have an existing security group with ports 80, 443, 22, and 9001 open, you can skip this step.
Appsmith is a web application that requires ports 80 and 443 for HTTP access, port 22 to be accessible for SSH access, it also requires port 9001 to be accessible for the supervisord UI. Please follow the steps detailed here to create a new security group.
While creating the new security group, please follow the steps detailed here to edit the "Inbound Rules" and make ports 80, 443, 22 and 9001 accessible from anywhere.
ECS overview
Deploy Appsmith (using EC2 launch type):
Switch to the old AWS console UI to follow the steps in this tutorial.
Step 1: Create an ECS Cluster
- Navigate to Amazon ECS and choose clusters on the side bar and select
Create Cluster
.
Choose EC2 Linux + Networking, and select the next step.
Enter your cluster name
Instance configuration:
- Select the provisioning model as On-Demand Instance.
- Select the server size you wish to use, and set the Number of instances as 1.
- Select the Amazon Linux2 AMI for the EC2 AMI ID dropdown, and enter the required EBS volume size.
- Select a Key pair. Please refer to Prerequisite 2, if you haven't already created one.
Networking Section
- Select the default VPC followed by selecting the first subnet from the drop-down.
- Select the security group that you created in [Create an AWS security group] (#3-create-an-aws-security-group) section.
Enable container insights (this gives CloudWatch monitoring and helps to debug).
Leave the Container instance IAM role as default (ecsInstanceRole), if you don't have one AWS creates it for you.
Hit the Create button. It may take a minute for your cluster to be ready.
Step 2: Create task and container definitions
Once the cluster is created, you need to create a task that runs on the cluster created in Step 1.
On the sidebar, choose Task Definitions and select Create new Task Definition.
Choose EC2 as the launch type, and proceed to the next step.
Configure task and definition
Enter the task definition name.
Leave the Task role blank.
Select the default Network mode
Select the default Task execution IAM role (ecsTaskExecutionRole). AWS creates one for you if you don't have one.
Set the required task size (memory & CPU)
Go to the Volumes section and add a new volume. To persist data on the Appsmith installation you have two options.
Bind mount directory on the host ec2 instance. The data is tied to the lifecycle of the host ec2 instance/ecs cluster. Enter the Name as
appsmith_stack
, set Volume type as Bind Mount, and set the Source path to/Appsmith/stacks
.Amazon EFS volumes- The data is independent of the lifecycle of the host ec2 instance/ecs cluster.
Create an EFS filesystem by following the steps below:
- Navigate to AWS EFS on the console and hit the Create button.
- Set the parameters like VPC (should be the same as the ECS cluster) and storage class as suiting your requirement.
- Click on the EFS created and navigate to the Network tab to ensure mount-target is created in the same availability-zone as that of the ECS cluster.
- Create a new security group to allow inbound and outbound NFS traffic.
- Attach the security group to the ECS cluster and the EFS mount-target.
Enter the Name as
appsmith_stack
, set Volume type as EFS and set the File System ID to the EFS filesystem created in the prequisite step. Leave the remaining fields with the default values.
Configure Appsmith container.
Click the Add container button.
Enter the container name, and set the Image to
appsmith/appsmith-ce
Add port mappings for the ports 80->80,443->443
Set the Mount points Source volume to
appsmith_stack
and set the Container path to/appsmith-stacks
Enable auto-configure CloudWatch Logs for log configuration.
Hit Add.
Finally, hit the Create button.
Step 3: Create and run an ECS service
- Navigate to the clusters dashboard and click the ECS cluster created in [Step 1]/(aws-ecs#step-1-create-an-ecs-cluster).
- On the cluster details, under the Services tab hit the create button.
Configure Service
Select EC2 as Launch Type.
Select the Task Definition created in Step 2 with the latest revision.
Select the Cluster created in Step 1.
Enter the service name.
Select the Daemon Service type.
Set the Minimum Healthy Percent to 40.
Leave the remaining fields and sections with the default values, and proceed to the next step.
Configure network - Proceed to the next step with the default configurations.
- Set Auto Scaling - Proceed to the next step with the default configuration.
- Review the Service configurations and hit the Create Service button.
- The following screen is shown with the launch status, click the View Service button.
- You are directed to the service detail page. Your task is listed under the Tasks tab on the cluster. refresh the table until the status is RUNNING.
- Click on the task to get the details of your running service.
- Finally, click the EC2 instance id to navigate to the EC2 console with your ECS instance (which is basically an EC2 instance running the container service) listed.
- Find the public IP address or DNS name and enter it on your browser to see Appsmith's welcome page.
In this guide, If you are using the embedded MongoDB, the container persistence is tied up with the EC2 instance lifecycle.
Update Appsmith
It's recommended to backup the Appsmith instance before performing an update. For more information, see How to create a backup.
- Navigate to the ECS cluster from the ECS dashboard.
- In the Tasks Tab, click the respective task.
- On the Task Page, hit the stop button.
- Wait until the new task is deployed automatically.
If you have updated your Appsmith instance and face any issues. You can rollback the changes and restore the Appsmith instance from a backup archive.
Troubleshooting
If you encounter any errors during this process, check out the debugging deployment errors, if you are still facing an issue please reach out to support@appsmith.com or join the Discord Server to directly speak to the Appsmith team.