Install Sourcegraph on Amazon Web Services (AWS)
This guide provides an overview of deploying Sourcegraph with Docker Compose to a single EC2 instance on Amazon Web Services (AWS). For detailed instructions or any assistance, please reach out to your account team.
Architecture
Our recommended architecture for deploying Sourcegraph with Docker Compose on AWS consists of a single EC2 instance with an attached EBS volume and an RDS for PostgreSQL instance for data storage. The EC2 instance runs the Sourcegraph application, while the EBS volume provides persistent storage for repositories and other data, and the RDS instance provides storage for user data and application metadata.
See Architecture: AWS (Docker Compose) for diagrams.
Before you start
Before deploying the Sourcegraph application, we require familiarity with the following AWS (e.g., EC2, EBS, RDS, IAM) and Docker concepts. Then, ensure you have the following prerequisites in place:
Amazon Web Services account
You should have the permissions necessary to create and manage EC2 instances, EBS volumes, and RDS instances in your AWS account. It's not recommended to use your root account for this purpose. Instead, create a new IAM user with the necessary permissions and use that account for deployment.
Amazon EC2
Follow the instructions in the AWS documentation to set up an EC2 instance with an EBS volume mounted. Ensure that you select an appropriate instance type based on your expected workload and resource requirements. You may use one of the x86 Linux AMIs as machine image. Also, configure inbound rules to allow HTTP/HTTPS (ports 80 and 443) only from the networks that should be able to reach the application (public internet for external deployments, or corporate/private ranges for internal deployments). Ensure you also have administrative access (SSH or Session Manager) for ongoing management of the application.
You should also set up automatic snapshots for the EBS volume following AWS documentation to ensure that your data is backed up regularly.
Docker & Docker Compose
Install Docker and Docker Compose on your EC2 instance. You can follow the instructions in the Docker documentation to install Docker on Linux, and then install Docker Compose using the instructions provided in the Docker Compose documentation. Ensure you set up the EBS volume as the Docker daemon data directory following Docker documentation.
Amazon RDS for PostgreSQL
Set up an RDS instance for PostgreSQL in your AWS account. You can follow the instructions in the AWS documentation to create a new RDS instance. Ensure that the RDS instance is accessible from your EC2 instance and that you have the necessary credentials to connect to it.
IAM
It is recommended to create an IAM role with the necessary permissions to allow your EC2 instance to access the RDS instance. This will help ensure that your application can access the required resources securely with minimal permissions.
Deploying Sourcegraph
Follow the installation steps for Docker Compose to complete the deployment of Sourcegraph on your AWS EC2 instance. During the configuration step, ensure to provide the necessary connection details for your RDS instance.