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

Step 4: Assign the Recipes to LifeCycle Events

You can run custom recipes manually, but the best approach is usually to have AWS OpsWorks Stacks run them automatically. Every layer has a set of built-in recipes assigned to each of five lifecycle events—Setup, Configure, Deploy, Undeploy, and Shutdown—. Each time an event occurs on an instance, AWS OpsWorks Stacks runs the associated recipes for each of the instance's layers, which handle the required tasks. For example, when an instance finishes booting, AWS OpsWorks Stacks triggers a Setup event to run the Setup recipes, which typically handle tasks such as installing and configuring packages .

You can have AWS OpsWorks Stacks run custom recipes on a layer's instances by assigning each recipe to the appropriate lifecycle event. AWS OpsWorks Stacks will run any custom recipes after the layer's built-in recipes have finished. For this example, assign appsetup.rb to the PHP App Server layer's Deploy event and dbsetup.rb to the MySQL layer's Deploy event. AWS OpsWorks Stacks will then run the recipes on the associated layer's instances during startup, after the built-in Setup recipes have finished, and every time you deploy an app, after the built Deploy recipes have finished. For more information, see Automatically Running Recipes.

To assign custom recipes to the layer's Deploy event

  1. On the AWS OpsWorks Stacks Layers page, for the PHP App Server click Recipes and then click Edit.

  2. Under Custom Chef Recipes, add the recipe name to the deploy event and click +. The name must be in the Chef cookbookname::recipename format, where recipename does not include the .rb extension. For this example, you enter photoapp::appsetup. Then click Save to update the layer configuration.

  3. On the Layers page, click edit in the MySQL layer's Actions column.

  4. Add photoapp::dbsetup to the layer's Deploy event and save the new configuration.