Skip to content
Grant Heffernan edited this page Jan 8, 2016 · 13 revisions

Who would want to use this?

If you use AWS Opsworks, and want a command line interface that allows you to:

  • manage stack json
  • manage cookbooks
  • generate ssh configurations

Getting Started

Initial Setup

gem install opzworks

edit your ~/.aws/config and add a section similar to the following:

[opzworks]
ssh-user-name         = grant
berks-github-org      = mapzen
berks-s3-bucket       = mapzen.opsworks
berks-repository-path = /Users/grant/repos/mapzen/projects-opsworks

ssh-user-name is your opsworks user name

berks-github-org is the Github org under which you'll have all the repos we'll be working with to manage your OpsWorks stacks

berks-s3-bucket is the S3 directory to which we'll push all cookbooks

berks-repository-path is the local directory under which we'll place all the repositories used to manage your stacks

Walkthrough With a Sample Stack

Create an OpsWorks stack: myapp::dev::us-east. Note that the naming convention here is important. To use this workflow, you need to adhere to the naming convention of app::env::region. If your app name will have multiple words, use underscores, e.g. my_app.

To go along with this new stack, we need a github repo called opsworks-myapp. Create a new branch in the repo called dev-us-east. This corresponds directly to the env::region portion of the stack name, so if we add another stack in the future called myapp::prod::us-west, we would create a new branch called prod-us-east. Clone the repo locally to <berks-repository-path>/opsworks-myapp. Create a new Berksfile in the repo with whatever contents you need to run your stack. I'm going to assume a working knowledge of Berkshelf.

Edit the stack settings for myapp::dev::us-east. Set Use Custom Chef Cookbooks to Yes. Set the repository URL to https://s3.amazonaws.com/<berks-s3-bucket>/myapp-dev-us-east/cookbooks.tgz. Replace <berks-s3-bucket> with the name of the S3 bucket you specified when we got started. Note that you'll need to create the bucket manually: aws s3 mb s3://<my_bucket>. You'll want to create an IAM user as well, the credentials for which you can specify in the fields provided. The user only needs s3:Get and s3:List permissions.

Now we're ready to create a new cookbook repository for our stack. The default opzworks behavior for the berks command is to build the berkshelf, bundle it as cookbooks.tgz, and upload it to <berks-s3-bucket>/project-env-region/cookbooks.tgz. It will then execute update_custom_cookbooks on the stack so that the stack instances retrieve our updated cookbooks.

opzworks berks myapp will work in our case if the only stack we have created is myapp. If you have any other stacks that match myapp, the code will exit with a message that it detected more than one matching stack, in which case you need to be more explicit: opzworks berks myapp::dev::us-east, for example.

If you want to skip the execution of update_custom_cookbooks on the remote stack, pass the --no-update flag.

Clone this wiki locally