Step 4: Assign the Recipe to a LifeCycle Event
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.
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 each of five lifecycle events—Setup, Configure, Deploy, Undeploy, and Shutdown. Each time an event occurs for an instance, AWS OpsWorks Stacks runs the associated recipes for each of the instance's layers, which handle the corresponding tasks. For example, when an instance finishes booting, AWS OpsWorks Stacks triggers a Setup event. This event runs the associated layer's Setup recipes, which typically handle tasks such as installing and configuring packages.
You can have AWS OpsWorks Stacks run a custom recipe on a layer's instances by assigning the recipe
to the appropriate lifecycle event. For this example, you should assign the
generate.rb
recipe to the Rails App Server layer's Deploy event. AWS OpsWorks Stacks
will then run it on the layer's instances during startup, after the Setup recipes have
finished, and every time you deploy an app. For more information, see Automatically Running Recipes.
To assign a recipe to the Rails App Server layer's Deploy event
-
On the AWS OpsWorks Stacks Layers page, for Rails App Server, click Recipes and then click Edit..
-
Under Custom Chef Recipes, add the fully qualified recipe name to the deploy event and click +. A fully qualified recipe name uses the
format, wherecookbookname
::recipename
does not include therecipename
.rb
extension. For this example, the fully qualified name isredis-config::generate
. Then click Save to update the layer configuration.