Menu
AWS OpsWorks
User Guide (API Version 2013-02-18)

Packaging Cookbook Dependencies Locally

You can use Berkshelf to package your cookbook dependencies locally, upload the package to Amazon S3, and modify your stack to use the package on Amazon S3 as a cookbook source.

The following walkthroughs describe how to pre-package your cookbooks and their dependencies into a .zip file, and then use the .zip file as your cookbook source for Linux instances in AWS OpsWorks Stacks. The first walkthrough describes how to package one cookbook. The second walkthrough describes how to package multiple cookbooks.

Before you begin, install the Chef Development Kit (also known as Chef DK), which is an assortment of tools built by the Chef community. You will need this to use the chef command-line tool.

Packaging Dependencies Locally for One Cookbook

  1. On the local computer, create a cookbook by using the chef command line tool:

    Copy to clipboard
    chef generate cookbook "server-app"

    This command creates a cookbook and a Berksfile, and places them in a folder that has the same name as the cookbook.

  2. Change to the cookbook directory that Chef created for you, and then package everything by running the following command:

    Copy to clipboard
    berks package cookbooks.tar.gz

    The output looks like this:

    Copy to clipboard
    Cookbook(s) packaged to /Users/username/tmp/berks/cookbooks.tar.gz
  3. In the AWS CLI, upload the package you just created to Amazon S3:

    Copy to clipboard
    aws s3 cp cookbooks.tar.gz s3://bucket-name/

    The output looks like this:

    Copy to clipboard
    upload: ./cookbooks.tar.gz to s3://bucket-name/cookbooks.tar.gz
  4. In AWS OpsWorks Stacks, modify your stack to use the package that you uploaded as the cookbook source.

Packaging Dependencies Locally for Multiple Cookbooks

This example creates two cookbooks and packages the dependencies for them.

  1. On the local computer, run the following chef commands to generate two cookbooks:

    Copy to clipboard
    chef generate cookbook "server-app" chef generate cookbook "server-utils"

    In this example, the server-app cookbook performs Java configurations, so we need to add a dependency on Java.

  2. Edit server-app/metadata to add a dependency on the community Java cookbook:

    Copy to clipboard
    maintainer "The Authors" maintainer_email "you@example.com" license "all_rights" description "Installs/Configures server-app" long_description "Installs/Configures server-app" version "0.1.0" depends "java"
  3. Tell Berkshelf what to package by editing the Berksfile file in the cookbook root directory as follows:

    Copy to clipboard
    source "https://supermarket.chef.io" cookbook "server-app", path: "./server-app" cookbook "server-utils", path: "./server-utils"

    Your file structure now looks like this:

    . ├── Berksfile ├── server-app └── server-utils

  4. Finally, create a zip package, upload it to Amazon S3, and modify your AWS OpsWorks Stacks stack to use the new cookbook source. To do this, follow steps 2 through 4 in Packaging Dependencies Locally for One Cookbook.