Step 1: Create the Cookbook
Important
AWS OpsWorks Stacks is no longer accepting new customers. Existing customers will be able to use the OpsWorks console, API, CLI, and CloudFormation resources as normal until May 26, 2024, at which time they will be discontinued. To prepare for this transition, we recommend you transition your stacks to AWS Systems Manager as soon as possible. For more information, see AWS OpsWorks Stacks End of Life FAQs and Migrating your AWS OpsWorks Stacks applications to AWS Systems Manager Application Manager.
Start by creating a cookbook. This cookbook won't do much to start, but it serves as a foundation for the rest of this walkthrough.
Note
This step demonstrates how to create a cookbook manually. You can create a cookbook in
less time with the Chef development kit (Chef DK
To create the cookbook
-
On your local workstation, create a directory named
opsworks_cookbook_demo
. You can use a different name, but be sure to substitute it foropsworks_cookbook_demo
throughout this walkthrough. -
In the
opsworks_cookbook_demo
directory, create a file namedmetadata.rb
using a text editor. Add the following code to specify the cookbook's name. For more information aboutmetadata.rb
, see metadata.rbon the Chef website. name "opsworks_cookbook_demo"
-
In the
opsworks_cookbook_demo
directory, create a subdirectory namedrecipes
. This subdirectory contains all of the recipes that you create for this walkthrough's cookbook. -
In the
recipes
directory, create a file nameddefault.rb
. This file contains a recipe with the same name as the file, but without the file extension:default
. Add the following single line of code to thedefault.rb
file. This code is a one-line recipe that displays a simple message in the log when the recipe runs:Chef::Log.info("********** Hello, World! **********")
-
At the terminal or command prompt, use the tar command to create a file named
opsworks_cookbook_demo.tar.gz
, which contains theopsworks_cookbook_demo
directory and its contents. For example:tar -czvf opsworks_cookbook_demo.tar.gz opsworks_cookbook_demo/
You can use a different file name, but be sure to substitute it for
opsworks_cookbook_demo.tar.gz
throughout this walkthrough.Note
When you create the
tar
file on Windows, the top directory must be the parent directory of the cookbook. This walkthrough has been tested on Linux with the tar command provided by thetar
package and on Windows with the tar command provided by Git Bash. Using other commands or programs to create a compressed TAR (.tar.gz) file may not work as expected. -
Create an S3 bucket, or use an existing bucket. For more information, see Create a Bucket.
-
Upload the
opsworks_cookbook_demo.tar.gz
file to the S3 bucket. For more information, see Add an Object to a Bucket.
You now have a cookbook that you will use throughout this walkthrough.
In the next step, you create an AWS OpsWorks Stacks stack that you will use later to upload your cookbook and to run the cookbook's recipes.