Deploy Redash to AWS with Terraform (Self-hosted analytics and graphing for your database)
Redash is a popular open-source graphing dashboard that can be used to monitor sales, databases, data and more. In this post we will deploy it to AWS using an EC2 instance and Terraform. At MailSlurp we use Redash to monitor the flow of emails in and out of our servers. You can use MailSlurp to create unlimited test email accounts then send and receive email from code or tests!
What is Redash?
Redash is an open-source data visualization tool used by companies as diverse as Soundcloud, Mozilla, and Waze. It allows developers and analyts to query data, graph results, and share insights with others. The best thing about Redash is that it is completely free to self-host (minus your own infrastructure costs).
Why deploy self-hosted Redash?
Redash.io offers a super simple one-click start for hmanaged Redash instances. These are great for companies that want data insights fast but for companies with smaller budgets or developers who want extra control over data and security self-hosting Redash is a valuable endeavour.
What is terraform?
Terraform is an "infrastructure-as-code" framework that lets you create servers, load-balancers, databases and more in a number of cloud providers using a special HCL syntax.
You define resources in Terraform code then apply the code and Terraform will compare the current state of your cloud resources with the code you have written. If something is new or missing it will be created in the cloud for you.
How does Redash work?
Redash is not a trivial application (hence the hosted solutions). It has several databases, worker threads, and a web interface. Setting all that up could be difficult. Fortunately, Redash.io provides a set of prebuilt and self-contained images for a number of platforms including AWS.
Redash on AWS
The recommended way to deploy Redash on an AWS account is to use a region-appropriate AMI image (listed here) and an EC2 instance. This can be done manually using the AWS console but a more maintainable approach would be to use Terraform.
What is Terraform?
Terraform is a declarative infrastructure system that let’s you define your cloud stacks in a text-based versionable way. If you haven’t used it before take a look at the [getting started guide] first.
Deploying with Terraform
Spinning up an EC2 machine with a Redash AMI is really straight forward withe Terraform. Assuming you have already set up a Terraform project with an AWS provider
resource we can use Terraform to define an EC2 instance and security group required for redash. Here is what that looks like:
locals {
# Redash recommend AMI for us-west-2
# https://redash.io/help/open-source/setup#aws
ami = "ami-0c457f229774da543"
instance_type = "t2.small"
}
# security group to allow ingress/egress
resource "aws_security_group" "redash" {
name = "redash_sg"
ingress {
from_port = 22
to_port = 22
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = ["0.0.0.0/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# ec2 instance running redash image
resource "aws_instance" "redash" {
ami = local.ami
instance_type = local.instance_type
security_groups = [aws_security_group.redash.name]
tags = {
Name = "Redash"
}
}
Notice the AMI used is specific for my region: us-west-2. Alter the AMI to suit your region requirements.
Applying Terraform changes
To apply your Terraform file run
terraform init
terraform apply --auto-approve
The output should indicate the creation of a new EC2 instance using the Redash AMI.
Connecting to your Redash instance
Once the EC2 machine has started you can connect to the public DNS address listed in the AWS EC2 console. If everything worked you should now be greeted with a setup screen. Create your admin account to continue.
Voila
You are now ready to connect datasources and begin visualizing your data. See the Redash open source setup for more configuration options.
Why though?
MailSlurp uses Redash as an alternative to Grafana to graph user metrics and prioritise product features. MailSlurp is a free email testing API that let’s you create real email addresses on demand. You can send and receive email via HTTP, SDK, or a hosted web dashboard. Check it out!
Top comments (0)