Getting started

Deploy MySQL and Redis on AWS in less than 10 lines of code

Follow this simple guide to deploy a MySQL and a Redis instance on your AWS account. By the end of this guide, you'll have a MySQL instance running on RDS and a Redis cluster on Elasticache.What you'll need:

Here's what you'll get after you've finished this guide:

  • A MySQL database instance on RDS, within the AWS free tier to help run in sane costs

  • A Redis instance on Elasticache, within the AWS free tier

  • A VPC and Internet Gateway to keep your database instances isolated and secure

  • Your credentials securely stored on AWS Secrets Manager

circle-info

This guide is meant for the Community Edition of Stackmate which is free and open-source. We also offer a Cloud editionarrow-up-right that sets up your AWS account for you and deploys every time you push a new commit. We offer a trial of 7 days and no credit card is required

1. Create a configuration file

First, we need to create a configuration file for stackmate, under its default location which is .stackmate/config.yml. You can start by copying the code specified in this example filearrow-up-right on the stackmate repositoryarrow-up-right. Our configuration file would then look something like this:

---
# Optional - by default stackmate uses AWS
# provider: aws

# Optional - by default stackmate deploys to eu-central-1
# region: eu-central-1

state:
  # 👇 This will store the state file in our local machine
  # and should be OUTSIDE your source code repository,
  # so that you make sure it NEVER GETS COMMITTED to git
  #
  # Alternatively, you can use an S3 bucket to store the state
  # you can find more information by the end of this guide
  workspaceDir: /Users/<myusername>/.stackmate-states/my-cool-project

environments:
  production:
    mysql-database:
      type: mysql
      # Note: Use the externalLinks attribute to allow a resource
      # that's not deployed by stackmate to access the database
      # externalLinks:
      #  - 1.2.3.4
    redis-cache:
      type: redis

Quick note: By default your resources are deployed in a VPC,arrow-up-right meaning that they're isolated from the outside world but all resources deployed by Stackmate, can connect with each other. If you need to allow connections from a resource that's not deployed by Stackmate, consider adding the externalLinks attribute to the service as documented in the common service options section for environments.

2. Create the directory to store the Terraform state in

Terraform requires a statearrow-up-right file to be present, so that it knows what the desired state of your infrastructure will be every time. For the sake of this guide, we will be storing our state files locally, but at the end of this guide, we'll see how we can use an AWS S3 bucket to securely store our states in.

Please note that as described in Should I commit the files that are generated by Stackmate?, we should NEVER commit our state to version control and this is why the directory is set outside our repository. Now let's go ahead and create the directory:

3. Pick an AWS profile to use

Use your favorite editor to view an existing, or add a new AWS profile on your AWS configuration. As an example, we'll be using an AWS profile named stackmate-user. More details on the official AWS documentationarrow-up-right.

4. Run the deployment!

Let's now prefix the AWS profile to the stackmate deploy command and we're ready to go!

This will do the following:

  • Install stackmate cli locally (if it's not available already)

  • Load the AWS profile specified

  • Set up our infrastructure on the AWS account specified.

You'll be getting output on your terminal regarding the progress and once it's done, you'll get the endpoints you can connect to. For example:

Your infrastructure is now deployed and ready to be used!

5. Bonus points: Use an S3 bucket to store the state

Deploying your state on an S3 bucket, allows your team to access it centrally, makes sure it's always available and handles versioning and locking. The benefits and the process Terraform uses is described in this documentation pagearrow-up-right.

To be able to use an S3 bucket in our stackmate configuration with locking, the following needs to exist in advance:

You can create these resources manually, as described in numerous tutorials (for example thisarrow-up-right one) but if you're already familiar with Terraform, we have prepared a terraform scriptarrow-up-right for you that you can use to create the resources described above. Here's how:

The directory we used and its contents should now be safe to delete

You can use the value in the "Outputs" sections above to configure stackmate:

Our next deployments will store the state in S3 and the state will be locked in DynamoDB

circle-info

Stackmate Cloudarrow-up-right creates the state bucket and lock table for you and handles AWS profiles automatically, once it securely access your AWS account. We offer a trial of 7 days and no credit card is required.

Next steps

Last updated