Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use CreateDeployment with a CLI - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use CreateDeployment with a CLI

The following code examples show how to use CreateDeployment.

CLI
AWS CLI

Example 1: To deploy apps and run stack commands

The following examples show how to use the create-deployment command to deploy apps and run stack commands. Notice that the quote (") characters in the JSON object that specifies the command are all preceded by escape characters (\). Without the escape characters, the command might return an invalid JSON error.

The following create-deployment example deploys an app to a specified stack.

aws opsworks create-deployment \ --stack-id cfb7e082-ad1d-4599-8e81-de1c39ab45bf \ --app-id 307be5c8-d55d-47b5-bd6e-7bd417c6c7eb --command "{\"Name\":\"deploy\"}"

Output:

{ "DeploymentId": "5746c781-df7f-4c87-84a7-65a119880560" }

Example 2: To deploy a Rails App and Migrate the Database

The following create-deployment command deploys a Ruby on Rails app to a specified stack and migrates the database.

aws opsworks create-deployment \ --stack-id cfb7e082-ad1d-4599-8e81-de1c39ab45bf \ --app-id 307be5c8-d55d-47b5-bd6e-7bd417c6c7eb \ --command "{\"Name\":\"deploy\", \"Args\":{\"migrate\":[\"true\"]}}"

Output:

{ "DeploymentId": "5746c781-df7f-4c87-84a7-65a119880560" }

For more information on deployment, see Deploying Apps in the AWS OpsWorks User Guide.

Example 3: Run a Recipe

The following create-deployment command runs a custom recipe, phpapp::appsetup, on the instances in a specified stack.

aws opsworks create-deployment \ --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb \ --command "{\"Name\":\"execute_recipes\", \"Args\":{\"recipes\":[\"phpapp::appsetup\"]}}"

Output:

{ "DeploymentId": "5cbaa7b9-4e09-4e53-aa1b-314fbd106038" }

For more information, see Run Stack Commands in the AWS OpsWorks User Guide.

Example 4: Install Dependencies

The following create-deployment command installs dependencies, such as packages or Ruby gems, on the instances in a specified stack.

aws opsworks create-deployment \ --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb \ --command "{\"Name\":\"install_dependencies\"}"

Output:

{ "DeploymentId": "aef5b255-8604-4928-81b3-9b0187f962ff" }

For more information, see Run Stack Commands in the AWS OpsWorks User Guide.

PowerShell
Tools for PowerShell

Example 1: This command creates a new app deployment on all of the Linux-based instances in a layer in AWS OpsWorks Stacks. Even if you specify a layer ID, you must specify a stack ID, too. The command lets the deployment restart the instances if required.

New-OPSDeployment -StackID "724z93zz-zz78-4zzz-8z9z-1290123zzz1z" -LayerId "511b99c5-ec78-4caa-8a9d-1440116ffd1b" -AppId "0f7a109c-bf68-4336-8cb9-d37fe0b8c61d" -Command_Name deploy -Command_Arg @{Name="allow_reboot";Value="true"}

Example 2: This command deploys the appsetup recipe from the phpapp cookbook, and the secbaseline recipe from the testcookbook cookbook. The deployment target is one instance, but the stack ID and layer ID are also required. The Command_Arg parameter allow_reboot attribute is set to true, which lets the deployment restart the instances if required.

$commandArgs = '{ "Name":"execute_recipes", "Args"{ "recipes":["phpapp::appsetup","testcookbook::secbaseline"] } }' New-OPSDeployment -StackID "724z93zz-zz78-4zzz-8z9z-1290123zzz1z" -LayerId "511b99c5-ec78-4caa-8a9d-1440116ffd1b" -InstanceId "d89a6118-0007-4ccf-a51e-59f844127021" -Command_Name $commandArgs -Command_Arg @{Name="allow_reboot";Value="true
  • For API details, see CreateDeployment in AWS Tools for PowerShell Cmdlet Reference.

AWS CLI

Example 1: To deploy apps and run stack commands

The following examples show how to use the create-deployment command to deploy apps and run stack commands. Notice that the quote (") characters in the JSON object that specifies the command are all preceded by escape characters (\). Without the escape characters, the command might return an invalid JSON error.

The following create-deployment example deploys an app to a specified stack.

aws opsworks create-deployment \ --stack-id cfb7e082-ad1d-4599-8e81-de1c39ab45bf \ --app-id 307be5c8-d55d-47b5-bd6e-7bd417c6c7eb --command "{\"Name\":\"deploy\"}"

Output:

{ "DeploymentId": "5746c781-df7f-4c87-84a7-65a119880560" }

Example 2: To deploy a Rails App and Migrate the Database

The following create-deployment command deploys a Ruby on Rails app to a specified stack and migrates the database.

aws opsworks create-deployment \ --stack-id cfb7e082-ad1d-4599-8e81-de1c39ab45bf \ --app-id 307be5c8-d55d-47b5-bd6e-7bd417c6c7eb \ --command "{\"Name\":\"deploy\", \"Args\":{\"migrate\":[\"true\"]}}"

Output:

{ "DeploymentId": "5746c781-df7f-4c87-84a7-65a119880560" }

For more information on deployment, see Deploying Apps in the AWS OpsWorks User Guide.

Example 3: Run a Recipe

The following create-deployment command runs a custom recipe, phpapp::appsetup, on the instances in a specified stack.

aws opsworks create-deployment \ --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb \ --command "{\"Name\":\"execute_recipes\", \"Args\":{\"recipes\":[\"phpapp::appsetup\"]}}"

Output:

{ "DeploymentId": "5cbaa7b9-4e09-4e53-aa1b-314fbd106038" }

For more information, see Run Stack Commands in the AWS OpsWorks User Guide.

Example 4: Install Dependencies

The following create-deployment command installs dependencies, such as packages or Ruby gems, on the instances in a specified stack.

aws opsworks create-deployment \ --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb \ --command "{\"Name\":\"install_dependencies\"}"

Output:

{ "DeploymentId": "aef5b255-8604-4928-81b3-9b0187f962ff" }

For more information, see Run Stack Commands in the AWS OpsWorks User Guide.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.