Self-Hosting Appwrite on AWS

Deploy your Appwrite Docker image in easy steps on AWS

Self-Hosting Appwrite on AWS

Appwrite is a backend platform for developing Web, Mobile, and Flutter applications. Built with the open source community and optimized for developer experience in the coding languages you love. Appwrite offers different services that you need to build your application like Authentication, Databases, Storage, and Functions also providing you with a set of REST APIs, GraphQL APIs, and Real-time APIs to cover all your needs.

One of its major advantages is that it can be self-hosted on any cloud provider of your choice. Appwrite recently launched Appwrite Cloud in Beta, you can check it out here.

You might think when we have solutions like Appwrite Cloud and One-Click hosting, why to even get into the hassle of Self-Hosting Appwrite on different cloud providers like AWS, well these are some points that you should consider while choosing self-hosting solutions.

  1. Customization and Control: Self-hosting offers complete control to customize Appwrite's environment and settings based on specific needs, providing a level of control unavailable in managed solutions.

  2. Data Privacy and Security: Self-hosting enables users to implement robust security measures and encryption protocols aligned with their data privacy requirements and compliance standards.

  3. Scalability: Users can optimize their self-hosted deployment for varying levels of traffic, ensuring seamless scalability and performance.

  4. Cost Efficiency: Self-hosting allows for cost optimization as users manage infrastructure themselves, avoiding potential cost escalations in managed solutions.

  5. Integration with Existing Infrastructure: Self-hosting on platforms like AWS facilitates smooth integration with existing services, enhancing efficiency and workflow alignment.

  6. Geographic Location: Users can choose server locations for compliance and low-latency access, meeting data residency needs and improving user experience.

  7. High Availability and Redundancy: Self-hosting empowers users to design highly available deployments by utilizing multiple availability zones or regions within the chosen cloud provider.

  8. Long-Term Viability: Users can adapt and evolve their self-hosted setup over time, ensuring the longevity and adaptability of their application.

  9. Reduced Vendor Lock-In: Self-hosting minimizes reliance on specific providers, offering flexibility to switch cloud platforms or hosting solutions if required.

AWS is one of the most popular cloud providers by Amazon that is designed to allow application providers, ISVs, and vendors to quickly and securely host your applications. Let's see how you can self-host Appwrite on AWS.

Steps to follow

Appwrite installs as a Docker image whether you are installing it on your local machine for development or cloud servers for production. So let's see the quick steps that we would follow to host Appwrite on AWS. The only prerequisite is to have an AWS account.

  • Create an EC2 instance with Ubuntu OS (Linux because these steps can be followed for different cloud providers.)

  • Install Docker & Docker Compose (Appwrite requires Docker Compose)

  • Install Appwrite as a Docker Image.

  • Test it out

Creating an EC2 Instance

  1. Go to your AWS console

  2. Click on Services -> Compute -> EC2

  3. Click on the orange color Launch instance button.

  4. Launch an instance Dashboard will be displayed. Here you need to select the configurations for your machine.

    Let's quickly do our configuration for the machine

  5. Give it a name, I would name this instance Appwrite Server and select Ubuntu as my OS which is also eligible for the free tier.

    Appwrite recommends using a minimum of 1 CPU core and 2GB of RAM so in the 'Instance type' option select t2.small which offers 1vCPU and 2 GiB Memory

  6. Next, you need to create a Key Pair so that you can securely connect to your instance via OpenSSH or PuTTY. Just click Create a new key pair.

    Create Key Pair Dialog will appear. Enter the Key pair name, Key pair type, and Private key file format as .pem and click Create key Pair

  7. In the Network settings, leave everything to default options just select Allow HTTPS traffic from the internet & Allow HTTP traffic from the internet options.

Leave everything else to default and click on Launch instance, wait for a few minutes and your instance would be created successfully.

Your Instance is created successfully. Let's install Docker on this instance.

Connecting to your Instance.

We need to connect to our recently created instance so that we can run Linux commands to install Docker.

  1. Click on your Instance Id -> Connect, You will see various options to connect to your instance, just to keep things simple we will connect to the web interface. Under EC2 Instance Connect, click Connect.

  2. Wait for a few seconds and you will get a terminal where now you can run commands in your instance.

Installing Docker

Let's install Docker using the terminal by running the following commands.

  1. Run these two commands to make sure everything is up-to-date

     sudo apt-get update
     sudo apt-get upgrade
    
  2. Next, install a few prerequisite packages which let apt use packages over HTTPS:

     sudo apt install apt-transport-https ca-certificates curl software-properties-common
    
  3. Then add the GPG key for the official Docker repository to your system:

     curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  4. Add the Docker repository to APT sources:

     sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
    
  5. Finally, install Docker

     sudo apt install docker-ce
    

You will get this output as soon as you run this command

Once this command is completed run this command to check if Docker is running.

sudo systemctl status docker

You will get this output and the Docker installation is complete.

Installing Docker Compose

One of the requirements to install Appwrite is to have Docker Compose. Let's see how we can install it.

Check the official GitHub Repository of Docker Compose to make sure you install the latest version but I will be installing the v1.29.2.

  1. Run this command to download and save the executable file.

     sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
    
  2. Next, set the correct permissions so that the docker-compose command is executable:

     sudo chmod +x /usr/local/bin/docker-compose
    
  3. Verify that the installation was successful.

     docker-compose --version
    

    You will get this output once your installation is complete and successful.

Installing Appwrite

Now it's time to finally install Appwrite. Run the command to pull the Appwrite image through Docker from the official Appwrite Docs.

sudo docker run -it --rm \
    --volume /var/run/docker.sock:/var/run/docker.sock \
    --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \
    --entrypoint="install" \
    appwrite/appwrite:1.3.8

Leave all the configuration options to default or you can change them according to your needs. Once done you will get the message Appwrite installed successfully.

Testing

Go to your instances page and in the details of that instance, you will find a Public IPv4 DNS URL. Open this and you will get a brand new shining Appwrite console page.

Conclusion

Well now your Appwrite image is hosted on AWS, you can go ahead building your awesome project. Need some help with getting started with Appwrite? Check out these resources.

So that's it, in just a few easy steps you have easily hosted your Appwrite image on AWS. Drop your doubts in the comments if you have any.