This documentation is for Version 1 of the Amazon CLI only. For documentation related to Version 2 of the Amazon CLI, see the Version 2 User Guide.
Amazon OpsWorks CM examples using Amazon CLI
The following code examples show you how to perform actions and implement common scenarios by using the Amazon Command Line Interface with Amazon OpsWorks CM.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Actions
The following code example shows how to use associate-node
.
- Amazon CLI
-
To associate nodes
The following
associate-node
command associates a node namedi-44de882p
with a Chef Automate server namedautomate-06
, meaning that theautomate-06
server manages the node, and communicates recipe commands to the node throughchef-client
agent software that is installed on the node by the associate-node command. Valid node names are EC2 instance IDs.:aws opsworks-cm associate-node --server-name
"automate-06"
--node-name"i-43de882p"
--engine-attributes"Name=CHEF_ORGANIZATION,Value='MyOrganization' Name=CHEF_NODE_PUBLIC_KEY,Value='Public_key_contents'"
The output returned by the command resembles the following. Output:
{ "NodeAssociationStatusToken": "AHUY8wFe4pdXtZC5DiJa5SOLp5o14DH//rHRqHDWXxwVoNBxcEy4V7R0NOFymh7E/1HumOBPsemPQFE6dcGaiFk" }
More Information
For more information, see Adding Nodes Automatically in Amazon OpsWorks for Chef Automate in the Amazon OpsWorks User Guide.
-
For API details, see AssociateNode
in Amazon CLI Command Reference.
-
The following code example shows how to use create-backup
.
- Amazon CLI
-
To create backups
The following
create-backup
command starts a manual backup of a Chef Automate server namedautomate-06
in theus-east-1
region. The command adds a descriptive message to the backup in the--description
parameter.aws opsworks-cm create-backup \ --server-name '
automate-06
' \ --description"state of my infrastructure at launch"
The output shows you information similar to the following about the new backup.
Output:
{ "Backups": [ { "BackupArn": "string", "BackupId": "automate-06-20160729133847520", "BackupType": "MANUAL", "CreatedAt": 2016-07-29T13:38:47.520Z, "Description": "state of my infrastructure at launch", "Engine": "Chef", "EngineModel": "Single", "EngineVersion": "12", "InstanceProfileArn": "arn:aws:iam::1019881987024:instance-profile/automate-06-1010V4UU2WRM2", "InstanceType": "m4.large", "KeyPair": "", "PreferredBackupWindow": "", "PreferredMaintenanceWindow": "", "S3LogUrl": "https://s3.amazonaws.com/<bucket-name>/automate-06-20160729133847520", "SecurityGroupIds": [ "sg-1a24c270" ], "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::1019881987024:role/aws-opsworks-cm-service-role.1114810729735", "Status": "OK", "StatusDescription": "", "SubnetIds": [ "subnet-49436a18" ], "ToolsVersion": "string", "UserArn": "arn:aws:iam::1019881987024:user/opsworks-user" } ], }
For more information, see Back Up and Restore an Amazon OpsWorks for Chef Automate Server in the Amazon OpsWorks User Guide.
-
For API details, see CreateBackup
in Amazon CLI Command Reference.
-
The following code example shows how to use create-server
.
- Amazon CLI
-
To create a server
The following
create-server
example creates a new Chef Automate server namedautomate-06
in your default region. Note that defaults are used for most other settings, such as number of backups to retain, and maintenance and backup start times. Before you run acreate-server
command, complete prerequisites in Getting Started with Amazon OpsWorks for Chef Automatein the Amazon Opsworks for Chef Automate User Guide. aws opsworks-cm create-server \ --engine
"Chef"
\ --engine-model"Single"
\ --engine-version"12"
\ --server-name"automate-06"
\ --instance-profile-arn"arn:aws:iam::1019881987024:instance-profile/aws-opsworks-cm-ec2-role"
\ --instance-type"t2.medium"
\ --key-pair"amazon-test"
\ --service-role-arn"arn:aws:iam::044726508045:role/aws-opsworks-cm-service-role"
The output shows you information similar to the following about the new server:
{ "Server": { "BackupRetentionCount": 10, "CreatedAt": 2016-07-29T13:38:47.520Z, "DisableAutomatedBackup": FALSE, "Endpoint": "https://opsworks-cm.us-east-1.amazonaws.com", "Engine": "Chef", "EngineAttributes": [ { "Name": "CHEF_DELIVERY_ADMIN_PASSWORD", "Value": "1Password1" } ], "EngineModel": "Single", "EngineVersion": "12", "InstanceProfileArn": "arn:aws:iam::1019881987024:instance-profile/aws-opsworks-cm-ec2-role", "InstanceType": "t2.medium", "KeyPair": "amazon-test", "MaintenanceStatus": "", "PreferredBackupWindow": "Sun:02:00", "PreferredMaintenanceWindow": "00:00", "SecurityGroupIds": [ "sg-1a24c270" ], "ServerArn": "arn:aws:iam::1019881987024:instance/automate-06-1010V4UU2WRM2", "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::1019881987024:role/aws-opsworks-cm-service-role", "Status": "CREATING", "StatusReason": "", "SubnetIds": [ "subnet-49436a18" ] } }
For more information, see UpdateServer
in the Amazon OpsWorks for Chef Automate API Reference. -
For API details, see CreateServer
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-backup
.
- Amazon CLI
-
To delete backups
The following
delete-backup
command deletes a manual or automated backup of a Chef Automate server, identified by the backup ID. This command is useful when you are approaching the maximum number of backups that you can save, or you want to minimize your Amazon S3 storage costs.:aws opsworks-cm delete-backup --backup-id
"automate-06-2016-11-19T23:42:40.240Z"
The output shows whether the backup deletion succeeded.
More Information
For more information, see Back Up and Restore an Amazon OpsWorks for Chef Automate Server in the Amazon OpsWorks User Guide.
-
For API details, see DeleteBackup
in Amazon CLI Command Reference.
-
The following code example shows how to use delete-server
.
- Amazon CLI
-
To delete servers
The following
delete-server
command deletes a Chef Automate server, identified by the server's name. After the server is deleted, it is no longer returned byDescribeServer
requests.:aws opsworks-cm delete-server --server-name
"automate-06"
The output shows whether the server deletion succeeded.
More Information
For more information, see Delete an Amazon OpsWorks for Chef Automate Server in the Amazon OpsWorks User Guide.
-
For API details, see DeleteServer
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-account-attributes
.
- Amazon CLI
-
To describe account attributes
The following
describe-account-attributes
command returns information about your account's usage of Amazon OpsWorks for Chef Automate resources.:aws opsworks-cm describe-account-attributes
The output for each account attribute entry returned by the command resembles the following. Output:
{ "Attributes": [ { "Maximum": 5, "Name": "ServerLimit", "Used": 2 } ] }
More Information
For more information, see DescribeAccountAttributes in the Amazon OpsWorks for Chef Automate API Reference.
-
For API details, see DescribeAccountAttributes
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-backups
.
- Amazon CLI
-
To describe backups
The following
describe-backups
command returns information about all backups associated with your account in your default region.aws opsworks-cm describe-backups
The output for each backup entry returned by the command resembles the following.
Output:
{ "Backups": [ { "BackupArn": "string", "BackupId": "automate-06-20160729133847520", "BackupType": "MANUAL", "CreatedAt": 2016-07-29T13:38:47.520Z, "Description": "state of my infrastructure at launch", "Engine": "Chef", "EngineModel": "Single", "EngineVersion": "12", "InstanceProfileArn": "arn:aws:iam::1019881987024:instance-profile/automate-06-1010V4UU2WRM2", "InstanceType": "m4.large", "KeyPair": "", "PreferredBackupWindow": "", "PreferredMaintenanceWindow": "", "S3LogUrl": "https://s3.amazonaws.com/<bucket-name>/automate-06-20160729133847520", "SecurityGroupIds": [ "sg-1a24c270" ], "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::1019881987024:role/aws-opsworks-cm-service-role.1114810729735", "Status": "Successful", "StatusDescription": "", "SubnetIds": [ "subnet-49436a18" ], "ToolsVersion": "string", "UserArn": "arn:aws:iam::1019881987024:user/opsworks-user" } ], }
For more information, see Back Up and Restore an Amazon OpsWorks for Chef Automate Server in the Amazon OpsWorks User Guide.
-
For API details, see DescribeBackups
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-events
.
- Amazon CLI
-
To describe events
The following
describe-events
example returns information about all events that are associated with the specified Chef Automate server.aws opsworks-cm describe-events \ --server-name '
automate-06
'The output for each event entry returned by the command resembles the following example:
{ "ServerEvents": [ { "CreatedAt": 2016-07-29T13:38:47.520Z, "LogUrl": "https://s3.amazonaws.com/<bucket-name>/automate-06-20160729133847520", "Message": "Updates successfully installed.", "ServerName": "automate-06" } ] }
For more information, see General Troubleshooting Tips
in the Amazon OpsWorks User Guide. -
For API details, see DescribeEvents
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-node-association-status
.
- Amazon CLI
-
To describe node association status
The following
describe-node-association-status
command returns the status of a request to associate a node with a Chef Automate server namedautomate-06
.:aws opsworks-cm describe-node-association-status --server-name
"automate-06"
--node-association-status-token"AflJKl+/GoKLZJBdDQEx0O65CDi57blQe9nKM8joSok0pQ9xr8DqApBN9/1O6sLdSvlfDEKkEx+eoCHvjoWHaOs="
The output for each account attribute entry returned by the command resembles the following. Output:
{ "NodeAssociationStatus": "IN_PROGRESS" }
More Information
For more information, see DescribeNodeAssociationStatus in the Amazon OpsWorks for Chef Automate API Reference.
-
For API details, see DescribeNodeAssociationStatus
in Amazon CLI Command Reference.
-
The following code example shows how to use describe-servers
.
- Amazon CLI
-
To describe servers
The following
describe-servers
command returns information about all servers that are associated with your account, and in your default region.:aws opsworks-cm describe-servers
The output for each server entry returned by the command resembles the following. Output:
{ "Servers": [ { "BackupRetentionCount": 8, "CreatedAt": 2016-07-29T13:38:47.520Z, "DisableAutomatedBackup": FALSE, "Endpoint": "https://opsworks-cm.us-east-1.amazonaws.com", "Engine": "Chef", "EngineAttributes": [ { "Name": "CHEF_DELIVERY_ADMIN_PASSWORD", "Value": "1Password1" } ], "EngineModel": "Single", "EngineVersion": "12", "InstanceProfileArn": "arn:aws:iam::1019881987024:instance-profile/automate-06-1010V4UU2WRM2", "InstanceType": "m4.large", "KeyPair": "", "MaintenanceStatus": "SUCCESS", "PreferredBackupWindow": "03:00", "PreferredMaintenanceWindow": "Mon:09:00", "SecurityGroupIds": [ "sg-1a24c270" ], "ServerArn": "arn:aws:iam::1019881987024:instance/automate-06-1010V4UU2WRM2", "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::1019881987024:role/aws-opsworks-cm-service-role.1114810729735", "Status": "HEALTHY", "StatusReason": "", "SubnetIds": [ "subnet-49436a18" ] } ] }
More Information
For more information, see DescribeServers in the Amazon OpsWorks for Chef Automate API Guide.
-
For API details, see DescribeServers
in Amazon CLI Command Reference.
-
The following code example shows how to use disassociate-node
.
- Amazon CLI
-
To disassociate nodes
The following
disassociate-node
command disassociates a node namedi-44de882p
, removing the node from management by a Chef Automate server namedautomate-06
. Valid node names are EC2 instance IDs.:aws opsworks-cm disassociate-node --server-name
"automate-06"
--node-name"i-43de882p"
--engine-attributes"Name=CHEF_ORGANIZATION,Value='MyOrganization' Name=CHEF_NODE_PUBLIC_KEY,Value='Public_key_contents'"
The output returned by the command resembles the following. Output:
{ "NodeAssociationStatusToken": "AHUY8wFe4pdXtZC5DiJa5SOLp5o14DH//rHRqHDWXxwVoNBxcEy4V7R0NOFymh7E/1HumOBPsemPQFE6dcGaiFk" }
More Information
For more information, see Delete an Amazon OpsWorks for Chef Automate Server in the Amazon OpsWorks User Guide.
-
For API details, see DisassociateNode
in Amazon CLI Command Reference.
-
The following code example shows how to use restore-server
.
- Amazon CLI
-
To restore a server
The following
restore-server
command performs an in-place restoration of a Chef Automate server namedautomate-06
in your default region from a backup with an ID ofautomate-06-2016-11-22T16:13:27.998Z
. Restoring a server restores connections to the nodes that the Chef Automate server was managing at the time that the specified backup was performed.aws opsworks-cm restore-server --backup-id "automate-06-2016-11-22T16:13:27.998Z" --server-name "automate-06"
The output is the command ID only. Output:
(None)
More Information
For more information, see Restore a Failed Amazon OpsWorks for Chef Automate Server in the Amazon OpsWorks User Guide.
-
For API details, see RestoreServer
in Amazon CLI Command Reference.
-
The following code example shows how to use start-maintenance
.
- Amazon CLI
-
To start maintenance
The following
start-maintenance
example manually starts maintenance on the specified Chef Automate or Puppet Enterprise server in your default region. This command is useful if an earlier, automated maintenance attempt failed, and the underlying cause of maintenance failure has been resolved.aws opsworks-cm start-maintenance \ --server-name '
automate-06
'Output:
{ "Server": { "AssociatePublicIpAddress": true, "BackupRetentionCount": 10, "ServerName": "automate-06", "CreatedAt": 1569229584.842, "CloudFormationStackArn": "arn:aws:cloudformation:us-west-2:123456789012:stack/aws-opsworks-cm-instance-automate-06-1606611794746/EXAMPLE0-31de-11eb-bdb0-0a5b0a1353b8", "DisableAutomatedBackup": false, "Endpoint": "automate-06-EXAMPLEvr8gjfk5f.us-west-2.opsworks-cm.io", "Engine": "ChefAutomate", "EngineModel": "Single", "EngineAttributes": [], "EngineVersion": "2020-07", "InstanceProfileArn": "arn:aws:iam::123456789012:instance-profile/aws-opsworks-cm-ec2-role", "InstanceType": "m5.large", "PreferredMaintenanceWindow": "Sun:01:00", "PreferredBackupWindow": "Sun:15:00", "SecurityGroupIds": [ "sg-EXAMPLE" ], "ServiceRoleArn": "arn:aws:iam::123456789012:role/service-role/aws-opsworks-cm-service-role", "Status": "UNDER_MAINTENANCE", "SubnetIds": [ "subnet-EXAMPLE" ], "ServerArn": "arn:aws:opsworks-cm:us-west-2:123456789012:server/automate-06/0148382d-66b0-4196-8274-d1a2b6dff8d1" } }
For more information, see System Maintenance (Puppet Enterprise servers)
or System Maintenance (Chef Automate servers) in the Amazon OpsWorks User Guide. -
For API details, see StartMaintenance
in Amazon CLI Command Reference.
-
The following code example shows how to use update-server-engine-attributes
.
- Amazon CLI
-
To update server engine attributes
The following
update-server-engine-attributes
command updates the value of theCHEF_PIVOTAL_KEY
engine attribute for a Chef Automate server namedautomate-06
. It is currently not possible to change the value of other engine attributes.aws opsworks-cm update-server-engine-attributes \ --attribute-name
CHEF_PIVOTAL_KEY
\ --attribute-value"new key value"
\ --server-name"automate-06"
The output shows you information similar to the following about the updated server.
{ "Server": { "BackupRetentionCount": 2, "CreatedAt": 2016-07-29T13:38:47.520Z, "DisableAutomatedBackup": FALSE, "Endpoint": "https://opsworks-cm.us-east-1.amazonaws.com", "Engine": "Chef", "EngineAttributes": [ { "Name": "CHEF_PIVOTAL_KEY", "Value": "new key value" } ], "EngineModel": "Single", "EngineVersion": "12", "InstanceProfileArn": "arn:aws:iam::1019881987024:instance-profile/automate-06-1010V4UU2WRM2", "InstanceType": "m4.large", "KeyPair": "", "MaintenanceStatus": "SUCCESS", "PreferredBackupWindow": "Mon:09:15", "PreferredMaintenanceWindow": "03:00", "SecurityGroupIds": [ "sg-1a24c270" ], "ServerArn": "arn:aws:iam::1019881987024:instance/automate-06-1010V4UU2WRM2", "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::1019881987024:role/aws-opsworks-cm-service-role.1114810729735", "Status": "HEALTHY", "StatusReason": "", "SubnetIds": [ "subnet-49436a18" ] } }
For more information, see UpdateServerEngineAttributes
in the Amazon OpsWorks for Chef Automate API Reference. -
For API details, see UpdateServerEngineAttributes
in Amazon CLI Command Reference.
-
The following code example shows how to use update-server
.
- Amazon CLI
-
To update a server
The following
update-server
command updates the maintenance start time of the specified Chef Automate server in your default region. The--preferred-maintenance-window
parameter is added to change the start day and time of server maintenance to Mondays at 9:15 a.m. UTC.:aws opsworks-cm update-server \ --server-name
"automate-06"
\ --preferred-maintenance-window"Mon:09:15"
The output shows you information similar to the following about the updated server.
{ "Server": { "BackupRetentionCount": 8, "CreatedAt": 2016-07-29T13:38:47.520Z, "DisableAutomatedBackup": TRUE, "Endpoint": "https://opsworks-cm.us-east-1.amazonaws.com", "Engine": "Chef", "EngineAttributes": [ { "Name": "CHEF_DELIVERY_ADMIN_PASSWORD", "Value": "1Password1" } ], "EngineModel": "Single", "EngineVersion": "12", "InstanceProfileArn": "arn:aws:iam::1019881987024:instance-profile/automate-06-1010V4UU2WRM2", "InstanceType": "m4.large", "KeyPair": "", "MaintenanceStatus": "OK", "PreferredBackupWindow": "Mon:09:15", "PreferredMaintenanceWindow": "03:00", "SecurityGroupIds": [ "sg-1a24c270" ], "ServerArn": "arn:aws:iam::1019881987024:instance/automate-06-1010V4UU2WRM2", "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::1019881987024:role/aws-opsworks-cm-service-role.1114810729735", "Status": "HEALTHY", "StatusReason": "", "SubnetIds": [ "subnet-49436a18" ] } }
For more information, see UpdateServer
in the Amazon OpsWorks for Chef Automate API Reference. -
For API details, see UpdateServer
in Amazon CLI Command Reference.
-