---
title: "Ruby on Rails Server Using Amazon EC2"
description: "A Ruby on Rails stack using a single EC2 instance with a local MySQL database for storage"
url: "https://www.pulumi.com/dev/examples/aws-ts-ruby-on-rails/"
image: "https://www.pulumi.com/assets/og/dev/examples/aws-ts-ruby-on-rails.png"
---

# Ruby on Rails Server Using Amazon EC2

A Ruby on Rails stack using a single EC2 instance with a local MySQL database for storage

- Source on GitHub: https://github.com/pulumi/examples/tree/master/aws-ts-ruby-on-rails
- Deploy with Pulumi: https://app.pulumi.com/new?template=https%3A%2F%2Fgithub.com%2Fpulumi%2Fexamples%2Ftree%2Fmaster%2Faws-ts-ruby-on-rails

## Get started with this example

This example lives in the [pulumi/examples](https://github.com/pulumi/examples/tree/master/aws-ts-ruby-on-rails) repo. Pull down just this directory to follow along:

```bash
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-ruby-on-rails
cd pulumi-examples/aws-ts-ruby-on-rails
```

This is a conversion of the AWS CloudFormation Application Framework template for a basic Ruby on Rails server.
It creates a single EC2 virtual machine instance and uses a local MySQL database for storage. Sourced from
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/sample-templates-appframeworks-us-west-2.html.

## Deploying the App

To deploy your Ruby on Rails application, follow the below steps.

### Prerequisites

1. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
2. [Configure AWS Credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)

### Steps

After cloning this repo, from this working directory, run these commands:

1. Create a new stack, which is an isolated deployment target for this example:

    ```bash
    $ pulumi stack init
    ```

2. Set the required configuration variables for this program:

    ```bash
    $ pulumi config set aws:region us-east-1
    $ pulumi config set dbUser [your-mysql-user-here]
    $ pulumi config set dbPassword [your-mysql-password-here] --secret
    $ pulumi config set dbRootPassword [your-mysql-root-password-here] --secret
    ```

3. Stand up the VM, which will also install and configure Ruby on Rails and MySQL:

    ```bash
    $ pulumi up
    ```

4. After several minutes, your VM will be ready, and two stack outputs are printed:

    ```bash
    $ pulumi stack output
    Current stack outputs (2):
    OUTPUT          VALUE
    vmIP            53.40.227.82
    websiteURL      http://ec2-53-40-227-82.us-west-2.compute.amazonaws.com/notes
    ```

5. Visit your new website by entering the websiteURL into your browser, or running:

    ```bash
    $ curl $(pulumi stack output websiteURL)
    ```

6. From there, feel free to experiment. Simply making edits and running `pulumi up` will incrementally update your VM.

7. Afterwards, destroy your stack and remove it:

    ```bash
    $ pulumi destroy --yes
    $ pulumi stack rm --yes
    ```
