Step 4: Update the Cookbook to Install a Package - AWS OpsWorks

Step 4: Update the Cookbook to Install a Package

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 installs on the instance a package that contains the popular text editor GNU Emacs.

Although you can just as easily log in to the instance and install the package once, writing a recipe enables you to run the recipe from AWS OpsWorks Stacks once to install multiple packages on multiple instances in a stack simultaneously.

To update the cookbook to install a package
  1. Back on your local workstation, in the recipes subdirectory in the opsworks_cookbook_demo directory, create a file named install_package.rb with the following code:

    package "Install Emacs" do package_name "emacs" end

    This recipe installs the emacs package on the instance. (For more information, go to package.)

    Note

    You can give a recipe any file name you want. Just be sure to specify the correct recipe name whenever you want AWS OpsWorks Stacks to run the recipe.

  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.

This new recipe runs when you update the cookbook on the instance and then run the new recipe from within the updated cookbook. The next step describes how to do this.

After you complete the next step, you will be able to log in to the instance and then type emacs from the command prompt to launch GNU Emacs. (For more information, see Connect to Your Linux Instance.) To exit GNU Emacs, press Ctrl+X, then Ctrl+C.

Important

To log in to the instance, you must first provide AWS OpsWorks Stacks with information about your public SSH key (which you can create with tools such as ssh-keygen or PuTTYgen), and then you must set permissions on the MyCookbooksDemoStack stack to enable your user to log in to the instance. For instructions, see Registering a User's Public SSH Key and Logging In with SSH.