Step 7: Update the Cookbook to Create a Directory - AWS OpsWorks

Step 7: Update the Cookbook to Create a Directory

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.

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:

    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:

    ls -la /tmp/create-directory-demo

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

    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.