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

Step 7: Update the Cookbook to Create a Directory

Update your cookbook by adding a recipe that adds a directory to the instance. This is similar to running the Linux mkdir command or the Windows md or mkdir commands.

To update the cookbook on the instance and to run the new recipe

  1. On your local workstation, in the recipes subdirectory in the opsworks_cookbook_demo directory, create a file named create_directory.rb with the following code. For more information, go to directory:

    Copy
    directory "Create a directory" do group "root" mode "0755" owner "ec2-user" path "/tmp/create-directory-demo" end
  2. At the terminal or command prompt, use the tar command create a new version of the opsworks_cookbook_demo.tar.gz file, which contains the opsworks_cookbook_demo directory and its updated contents.

  3. Upload the updated opsworks_cookbook_demo.tar.gz file to your S3 bucket.

  4. Follow the procedures in Step 5: Update the Cookbook on the Instance and Run the Recipe to update the cookbook on the instance and to run the recipe. In the "To run the recipe" procedure, for Recipes to execute, type opsworks_cookbook_demo::create_directory.

To test the recipe

  1. Log in to the instance, if you have not done so already.

  2. From the command prompt, run the following command to confirm that the new directory was added:

    Copy
    ls -la /tmp/create-directory-demo

    Information about the newly-added directory is displayed, including information such as permissions, owner name, and group name:

    Copy
    drwxr-xr-x 2 ec2-user root 4096 Nov 18 00:35 . drwxrwxrwt 6 root root 4096 Nov 24 18:17 ..

In the next step, you will update the cookbook to create a file on the instance.