Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Ruby on Rails server using Amazon EC2

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

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
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.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

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

    Terminal window
    pulumi stack init
  2. Set the required configuration variables for this program:

    Terminal window
    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. Install dependencies:

    Terminal window
    npm install
  4. Stand up the VM, which will also install and configure Ruby on Rails and MySQL:

    Terminal window
    pulumi up
  5. After several minutes, your VM will be ready, and two stack outputs are printed:

    Terminal window
    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
  6. Visit your new website by entering the websiteURL into your browser, or running:

    Terminal window
    curl $(pulumi stack output websiteURL)
  7. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your VM.

Cleaning up#

Once you’re finished, destroy your stack and remove it:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.