Important
The AWS OpsWorks Stacks service reached end of life on May 26, 2024 and has been disabled for both new and existing customers.
We strongly recommend customers migrate their workloads to other solutions as soon as possible. If you have questions about migration, reach out to the AWS Support Team on AWS re:Post
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
-
On the AWS OpsWorks Stacks Layers page, for the PHP App Server choose Recipes and then choose Edit.
-
Under Custom Chef Recipes, add the recipe name to the deploy event and choose +. The name must be in the Chef
format, wherecookbookname
::recipename
does not include therecipename
.rb
extension. For this example, you enterphotoapp::appsetup
. Then choose Save to update the layer configuration. -
On the Layers page, choose edit in the MySQL layer's Actions column.
-
Add
photoapp::dbsetup
to the layer's Deploy event and save the new configuration.