Learning More: Explore the Cookbook Used in This Walkthrough
This topic describes the cookbook that AWS OpsWorks Stacks used for the walkthrough.
A cookbook is a Chef concept. Cookbooks are archive files that contain configuration information, such as recipes, attribute values, files, templates, libraries, definitions, and custom resources. A recipe is also a Chef concept. Recipes are instructions, written with Ruby language syntax, that specify the resources to use and the order in which those resources are applied. For more information, go to About Cookbooks and About Recipes on the Learn Chef website.
To see the contents of the cookbook used in this walkthrough, extract the contents of the
opsworks-linux-demo-cookbooks-nodejs.tar.gz file to an empty directory on your
local workstation. (You can also log in to the instance that you deployed the cookbook to and
explore the contents of the
default.rb file in the
cookbooks/nodejs_demo/recipes directory is where the cookbook start
running its code:
Here's what the file does:
search(:aws_opsworks_app).firstuses Chef search to look up information about the app that will eventually be deployed to the instance. This information includes settings such as the app's short name and its source repository details. Because only one app was deployed in this walkthrough, Chef search gets these settings from the first item of information within the
aws_opsworks_appsearch index on the instance. Whenever an instance is launched, AWS OpsWorks Stacks stores this and other related information as a set of data bags on the instance itself, and you get the data bag contents through Chef search. Although you can hard code these settings into this recipe, using data bags and Chef search is a more robust approach. For more information about data bags, see the AWS OpsWorks Stacks Data Bag Reference. See also About Data Bags on the Learn Chef website. For more information about Chef search, go to About Search on the Learn Chef website.
packageresource installs Git on the instance.
applicationresource describes and deploys web applications:
environmentsets an environment variable.
gitgets the source code from the specified repository and branch.
app_pathis the path to clone the repository to. If the path doesn't exist on the instance, AWS OpsWorks Stacks creates it.
linkcreates a symbolic link.
npm_installinstalls Node Package Manager, the default package manager for Node.js.
Although AWS OpsWorks Stacks created the cookbook used for this walkthrough, you can create your own cookbooks. To learn how, see Getting Started: Cookbooks. Also, go to About Cookbooks, About Recipes, and Learn the Chef Basics on Ubuntu on the Learn Chef website, and the "Our first Chef cookbook" section in First steps with Chef on the Getting started with Chef website.