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

Installing a Package on a Windows Instance


This example assumes that you have already done the Running a Recipe on a Windows Instance example. If not, you should do that example first. In particular, it describes how to enable RDP access to your instances.

If your software comes in an installer package, such as an MSI, you must download the file to the instance and then run it. This example shows how to implement a cookbook to install an MSI package, the Python runtime, including how to define associated environment variables. For more information on how to install Windows features such as IIS, see Installing a Windows Feature: IIS.

To set up the cookbook

  1. Create a directory named installpython and navigate to it.

  2. Add a metadata.rb file to installpython with the following content.

    name "installpython" version "0.1.0"
  3. Add recipes and files directories to installpython and add a default directory to files.

  4. Download a Python package from Python Releases for Windows to the cookbook's files\default directory. This example installs the Windows x86-64 version of Python 3.5.0a3, which uses an MSI installer named python-3.4.3.amd64.msi.

  5. Add a file named default.rb to the recipes directory with the following recipe code.

    directory 'C:\tmp' do rights :full_control, 'Everyone' recursive true action :create end cookbook_file 'C:\tmp\python-3.4.3.amd64.msi' do source "python-3.4.3.amd64.msi" rights :full_control, 'Everyone' action :create end windows_package 'python' do source 'C:\tmp\python-3.4.3.amd64.msi' action :install end env "PATH" do value 'c:\python34' delim ";" action :modify end

    The recipe does the following:

    1. Uses a directory resource to create a C:\tmp directory.

      For more information on this resource, see Example 3: Creating Directories.

    2. Uses a cookbook_file resource to copy the installer from the cookbook's files\default directory to C:\tmp.

      For more information on this resource, see Installing a File from a Cookbook.

    3. Uses a windows_package resource to run the MSI installer, which installs Python to c:\python34.

      The installer creates the required directories and installs the files, but does not modify the system's PATH environment variable.

    4. Uses an env resource to add c:\python34 to the system path.

      You use the env resource to define environment variables. In this case, the recipe allows you to easily run Python scripts from the command line by adding c:\python34 to the path.

      • The resource name specifies the environment variable's name, PATH for this example.

      • The value attribute specifies the variable's value, c:\\python34 for this example (you need to escape the \ character).

      • The :modify action prepends the specified value to the variable's current value.

      • The delim attribute specifies a delimiter that separates the new value from the existing value, which is ; for this example.

  6. Create a .zip archive of installpython, upload the archive to an S3 bucket, and make it public. Record the archive's URL for later use. For more information, see Cookbook Repositories.

Create a stack for this example as follows. You also can use an existing Windows stack. Just update the cookbooks, as described later.

Create a stack

  1. Open the AWS OpsWorks Stacks console and choose Add Stack. Specify the following settings, accept the defaults for the other settings, and choose Add Stack.

    • Name – InstallPython

    • Region – US West (Oregon)

      This example will work in any region, but we recommend using US West (Oregon) for tutorials.

    • Default operating system – Microsoft Windows Server 2012 R2

  2. Choose Add a layer and add a custom layer to the stack with the following settings.

    • Name – Python

    • Short name – python

  3. Add a 24/7 instance with default settings to the Python layer and start it.

After the instance is online, you can install the cookbook and run the recipe

To install the cookbook and run the recipe

  1. Edit the stack to enable custom cookbooks, and specify the following settings.

    • Repository typeS3 Archive.

    • Repository URL – The cookbook's archive URL that you recorded earlier.

    Accept the default values for the other settings and choose Save to update the stack configuration.

  2. Run the Update Custom Cookbooks stack command, which installs the latest version of your custom cookbooks on the stack's online instances. If an earlier version of your cookbook is present, this command overwrites it.

  3. Execute the recipe by running the Execute Recipes stack command with Recipes to execute set to installpython::default. This command initiates a Chef run, with a run list that consists of installpython::default.


    This example uses Execute Recipes for convenience, but you typically have AWS OpsWorks Stacks run your recipes automatically by assigning them to the appropriate lifecycle event. You can run such recipes by manually triggering the event. You can use a stack command to trigger Setup and Configure events, and a deploy command to trigger Deploy and Undeploy events.

  4. To verify the installation, use RDP to connect to the instance and open Windows Explorer.

    • The file system should now have a C:\Python34 directory.

    • If you run path from the command line, it should look something like: PATH=c:\python34;C:\Windows\system32;...

    • If you run python --version from the command line, it should return Python 3.4.3.