OpsWorks Stacks

Lets build a photo sharing application using OpsWorks Stacks. It will look like this (without the motorbike)

In the Advanced Architecting course there is a module on Deployment Management which compares several deployment options including OpsWorks, CloudFormation, Elastic Beanstalk, Code Deploy and Elastic Container Service. There are about 15 slides on OpsWorks, mainly OpsWorks Stacks.

Here is a small lab to build a photo-sharing app, using an aws-labs github repo which contains the Chef Recipes for the app.

Navigate to:

Service>Opsworks>Stacks>Add you first stack>Chef 11 stack

Name: photo-app

Leave all the defaults, it will use your default VPC.

Add Stack. It takes a few seconds.

Add a Layer

The layer type defaults to Rails App Server, which is what this app requires.

Leave all the defaults and click Add Layer

Now we add another Opsworks layer.

Add Layer

Layer type: MySQL.

For each of the 2 layers:

Add instance

The size defaults to C3.large. I changed to t2.micro to save costs and left everything else as default.

For each layer, start the instance.

Wait until they are online. That takes a few minutes like any EC2 instance

While waiting, navigate to:

Layers> Recipes below Rails App Server to see the built in Chef recipes for each lifecycle event.

There are 5 lifecycle events:

  • Setup – triggered on every instance launch, so this will be happening right now.
  • Configure –triggered after the setup event
  • Deploy – triggered when we deploy an app a bit later on
  • Undeploy –triggered when we delete an app
  • Shutdown –triggered when we stop an instance

The recipes are fetched from an AWS github repo which contains cookbooks used by OpsWorks for Chef 11. The deploy recipes are fetched from another repo which we will specify.

We will do the deploy next. Check if the Instances are in the online state.

Apps>Add app

Name: photo-app

Repository URL: https://github.com/awslabs/opsworks-demo-rails-photo-share-app.git

Branch/Revision: version2.

The above are important – No space between version and the number 2.  It references a branch in the Github repo for the sample application.  If we left at the default we would get version1, which isn’t a fully functional version of the photo-app


Choose Migrate database: Yes. This sets up the database structure.

Takes a few minutes.

To test the app, go to Instances>Rails App Server and click on the public IP.

Upload a photo or two.

Go to Monitoring to see the average CPU and Memory for each layer.

To clean up:

Apps>rail-app>delete. This triggers an undeploy event.

Instances>stop both instances. This triggers a shutdown event.

Instances>delete both instances.

Layers. Delete the 2 layers

Stacks. Delete the photo-app stack