Amazon OpsWorks examples using Amazon CLI - Amazon Command Line Interface
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

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 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.

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 assign-instance.

Amazon CLI

To assign a registered instance to a layer

The following example assigns a registered instance to a custom layer.

aws opsworks --region us-east-1 assign-instance --instance-id 4d6d1710-ded9-42a1-b08e-b043ad7af1e2 --layer-ids 26cf1d32-6876-42fa-bbf1-9cadc0bff938

Output: None.

More Information

For more information, see Assigning a Registered Instance to a Layer in the Amazon OpsWorks User Guide.

  • For API details, see AssignInstance in Amazon CLI Command Reference.

The following code example shows how to use assign-volume.

Amazon CLI

To assign a registered volume to an instance

The following example assigns a registered Amazon Elastic Block Store (Amazon EBS) volume to an instance. The volume is identified by its volume ID, which is the GUID that Amazon OpsWorks assigns when you register the volume with a stack, not the Amazon Elastic Compute Cloud (Amazon EC2) volume ID. Before you run assign-volume, you must first run update-volume to assign a mount point to the volume.

aws opsworks --region us-east-1 assign-volume --instance-id 4d6d1710-ded9-42a1-b08e-b043ad7af1e2 --volume-id 26cf1d32-6876-42fa-bbf1-9cadc0bff938

Output: None.

More Information

For more information, see Assigning Amazon EBS Volumes to an Instance in the Amazon OpsWorks User Guide.

  • For API details, see AssignVolume in Amazon CLI Command Reference.

The following code example shows how to use associate-elastic-ip.

Amazon CLI

To associate an Elastic IP address with an instance

The following example associates an Elastic IP address with a specified instance.

aws opsworks --region us-east-1 associate-elastic-ip --instance-id dfe18b02-5327-493d-91a4-c5c0c448927f --elastic-ip 54.148.130.96

Output: None.

More Information

For more information, see Resource Management in the Amazon OpsWorks User Guide.

The following code example shows how to use attach-elastic-load-balancer.

Amazon CLI

To attach a load balancer to a layer

The following example attaches a load balancer, identified by its name, to a specified layer.

aws opsworks --region us-east-1 attach-elastic-load-balancer --elastic-load-balancer-name Java-LB --layer-id 888c5645-09a5-4d0e-95a8-812ef1db76a4

Output: None.

More Information

For more information, see Elastic Load Balancing in the Amazon OpsWorks User Guide.

The following code example shows how to use create-app.

Amazon CLI

Example 1: To create an app

The following example creates a PHP app named SimplePHPApp from code stored in a GitHub repository. The command uses the shorthand form of the application source definition.

aws opsworks create-app \ --region us-east-1 \ --stack-id f6673d70-32e6-4425-8999-265dd002fec7 \ --name SimplePHPApp \ --type php \ --app-source Type=git,Url=git://github.com/amazonwebservices/opsworks-demo-php-simple-app.git,Revision=version1

Output:

{ "AppId": "6cf5163c-a951-444f-a8f7-3716be75f2a2" }

Example 2: To create an app with an attached database

The following example creates a JSP app from code stored in .zip archive in a public S3 bucket. It attaches an RDS DB instance to serve as the app's data store. The application and database sources are defined in separate JSON files that are in the directory from which you run the command.

aws opsworks create-app \ --region us-east-1 \ --stack-id 8c428b08-a1a1-46ce-a5f8-feddc43771b8 \ --name SimpleJSP \ --type java \ --app-source file://appsource.json \ --data-sources file://datasource.json

The application source information is in appsource.json and contains the following.

{ "Type": "archive", "Url": "https://s3.amazonaws.com/opsworks-demo-assets/simplejsp.zip" }

The database source information is in datasource.json and contains the following.

[ { "Type": "RdsDbInstance", "Arn": "arn:aws:rds:us-west-2:123456789012:db:clitestdb", "DatabaseName": "mydb" } ]

Note: For an RDS DB instance, you must first use register-rds-db-instance to register the instance with the stack. For MySQL App Server instances, set Type to OpsworksMysqlInstance. These instances are created by Amazon OpsWorks, so they do not have to be registered.

Output:

{ "AppId": "26a61ead-d201-47e3-b55c-2a7c666942f8" }

For more information, see Adding Apps in the Amazon OpsWorks User Guide.

  • For API details, see CreateApp in Amazon CLI Command Reference.

The following code example shows how to use create-deployment.

Amazon 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 Amazon 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 Amazon 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 Amazon OpsWorks User Guide.

The following code example shows how to use create-instance.

Amazon CLI

To create an instance

The following create-instance command creates an m1.large Amazon Linux instance named myinstance1 in a specified stack. The instance is assigned to one layer.

aws opsworks --region us-east-1 create-instance --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --layer-ids 5c8c272a-f2d5-42e3-8245-5bf3927cb65b --hostname myinstance1 --instance-type m1.large --os "Amazon Linux"

To use an autogenerated name, call get-hostname-suggestion, which generates a hostname based on the theme that you specified when you created the stack. Then pass that name to the hostname argument.

Output:

{ "InstanceId": "5f9adeaa-c94c-42c6-aeef-28a5376002cd" }

More Information

For more information, see Adding an Instance to a Layer in the Amazon OpsWorks User Guide.

  • For API details, see CreateInstance in Amazon CLI Command Reference.

The following code example shows how to use create-layer.

Amazon CLI

To create a layer

The following create-layer command creates a PHP App Server layer named MyPHPLayer in a specified stack.

aws opsworks create-layer --region us-east-1 --stack-id f6673d70-32e6-4425-8999-265dd002fec7 --type php-app --name MyPHPLayer --shortname myphplayer

Output:

{ "LayerId": "0b212672-6b4b-40e4-8a34-5a943cf2e07a" }

More Information

For more information, see How to Create a Layer in the Amazon OpsWorks User Guide.

  • For API details, see CreateLayer 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 named automate-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 a create-server command, complete prerequisites in Getting Started with Amazon OpsWorks for Chef Automate in the Amazon Opsworks for Chef Automate User Guide.

aws opsworks-cm create-server \ --engine "ChefAutomate" \ --instance-profile-arn "arn:aws:iam::012345678901:instance-profile/aws-opsworks-cm-ec2-role" \ --instance-type "t2.medium" \ --server-name "automate-06" \ --service-role-arn "arn:aws:iam::012345678901:role/aws-opsworks-cm-service-role"

Output:

{ "Server": { "AssociatePublicIpAddress": true, "BackupRetentionCount": 10, "CreatedAt": 2019-12-29T13:38:47.520Z, "DisableAutomatedBackup": FALSE, "Endpoint": "https://opsworks-cm.us-east-1.amazonaws.com", "Engine": "ChefAutomate", "EngineAttributes": [ { "Name": "CHEF_AUTOMATE_ADMIN_PASSWORD", "Value": "1Example1" } ], "EngineModel": "Single", "EngineVersion": "2019-08", "InstanceProfileArn": "arn:aws:iam::012345678901:instance-profile/aws-opsworks-cm-ec2-role", "InstanceType": "t2.medium", "PreferredBackupWindow": "Sun:02:00", "PreferredMaintenanceWindow": "00:00", "SecurityGroupIds": [ "sg-12345678" ], "ServerArn": "arn:aws:iam::012345678901:instance/automate-06-1010V4UU2WRM2", "ServerName": "automate-06", "ServiceRoleArn": "arn:aws:iam::012345678901:role/aws-opsworks-cm-service-role", "Status": "CREATING", "SubnetIds": [ "subnet-12345678" ] } }

For more information, see CreateServer 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 create-stack.

Amazon CLI

To create a stack

The following create-stack command creates a stack named CLI Stack.

aws opsworks create-stack --name "CLI Stack" --stack-region "us-east-1" --service-role-arn arn:aws:iam::123456789012:role/aws-opsworks-service-role --default-instance-profile-arn arn:aws:iam::123456789012:instance-profile/aws-opsworks-ec2-role --region us-east-1

The service-role-arn and default-instance-profile-arn parameters are required. You typically use the ones that Amazon OpsWorks creates for you when you create your first stack. To get the Amazon Resource Names (ARNs) for your account, go to the IAM console, choose Roles in the navigation panel, choose the role or profile, and choose the Summary tab.

Output:

{ "StackId": "f6673d70-32e6-4425-8999-265dd002fec7" }

More Information

For more information, see Create a New Stack in the Amazon OpsWorks User Guide.

  • For API details, see CreateStack in Amazon CLI Command Reference.

The following code example shows how to use create-user-profile.

Amazon CLI

To create a user profile

You import an Amazon Identity and Access Manager (IAM) user into Amazon OpsWorks by calling create-user-profile to create a user profile. The following example creates a user profile for the cli-user-test IAM user, who is identified by Amazon Resource Name (ARN). The example assigns the user an SSH username of myusername and enables self management, which allows the user to specify an SSH public key.

aws opsworks --region us-east-1 create-user-profile --iam-user-arn arn:aws:iam::123456789102:user/cli-user-test --ssh-username myusername --allow-self-management

Output:

{ "IamUserArn": "arn:aws:iam::123456789102:user/cli-user-test" }

Tip: This command imports an IAM user into Amazon OpsWorks, but only with the permissions that are granted by the attached policies. You can grant per-stack Amazon OpsWorks permissions by using the set-permissions command.

More Information

For more information, see Importing Users into Amazon OpsWorks in the Amazon OpsWorks User Guide.

The following code example shows how to use delete-app.

Amazon CLI

To delete an app

The following example deletes a specified app, which is identified by its app ID. You can obtain an app ID by going to the app's details page on the Amazon OpsWorks console or by running the describe-apps command.

aws opsworks delete-app --region us-east-1 --app-id 577943b9-2ec1-4baf-a7bf-1d347601edc5

Output: None.

More Information

For more information, see Apps in the Amazon OpsWorks User Guide.

  • For API details, see DeleteApp in Amazon CLI Command Reference.

The following code example shows how to use delete-instance.

Amazon CLI

To delete an instance

The following delete-instance example deletes a specified instance, which is identified by its instance ID. You can find an instance ID by opening the instance's details page in the Amazon OpsWorks console, or by running the describe-instances command.

If the instance is online, you must first stop the instance by calling stop-instance, and then you must wait until the instance has stopped. Run describe-instances to check the instance status.

To remove the instance's Amazon EBS volumes or Elastic IP addresses, add the --delete-volumes or --delete-elastic-ip arguments, respectively.

aws opsworks delete-instance \ --region us-east-1 \ --instance-id 3a21cfac-4a1f-4ce2-a921-b2cfba6f7771

This command produces no output.

For more information, see Deleting Amazon OpsWorks Instances in the Amazon OpsWorks User Guide.

  • For API details, see DeleteInstance in Amazon CLI Command Reference.

The following code example shows how to use delete-layer.

Amazon CLI

To delete a layer

The following example deletes a specified layer, which is identified by its layer ID. You can obtain a layer ID by going to the layer's details page on the Amazon OpsWorks console or by running the describe-layers command.

Note: Before deleting a layer, you must use delete-instance to delete all of the layer's instances.

aws opsworks delete-layer --region us-east-1 --layer-id a919454e-b816-4598-b29a-5796afb498ed

Output: None.

More Information

For more information, see Deleting Amazon OpsWorks Instances in the Amazon OpsWorks User Guide.

  • For API details, see DeleteLayer in Amazon CLI Command Reference.

The following code example shows how to use delete-stack.

Amazon CLI

To delete a stack

The following example deletes a specified stack, which is identified by its stack ID. You can obtain a stack ID by clicking Stack Settings on the Amazon OpsWorks console or by running the describe-stacks command.

Note: Before deleting a layer, you must use delete-app, delete-instance, and delete-layer to delete all of the stack's apps, instances, and layers.

aws opsworks delete-stack --region us-east-1 --stack-id 154a9d89-7e9e-433b-8de8-617e53756c84

Output: None.

More Information

For more information, see Shut Down a Stack in the Amazon OpsWorks User Guide.

  • For API details, see DeleteStack in Amazon CLI Command Reference.

The following code example shows how to use delete-user-profile.

Amazon CLI

To delete a user profile and remove an IAM user from Amazon OpsWorks

The following example deletes the user profile for a specified Amazon Identity and Access Management (IAM) user, who is identified by Amazon Resource Name (ARN). The operation removes the user from Amazon OpsWorks, but does not delete the IAM user. You must use the IAM console, CLI, or API for that task.

aws opsworks --region us-east-1 delete-user-profile --iam-user-arn arn:aws:iam::123456789102:user/cli-user-test

Output: None.

More Information

For more information, see Importing Users into Amazon OpsWorks in the Amazon OpsWorks User Guide.

The following code example shows how to use deregister-elastic-ip.

Amazon CLI

To deregister an Elastic IP address from a stack

The following example deregisters an Elastic IP address, identified by its IP address, from its stack.

aws opsworks deregister-elastic-ip --region us-east-1 --elastic-ip 54.148.130.96

Output: None.

More Information

For more information, see Deregistering Elastic IP Addresses in the Amazon OpsWorks User Guide.

The following code example shows how to use deregister-instance.

Amazon CLI

To deregister a registered instance from a stack

The following deregister-instance command deregisters a registered instance from its stack.

aws opsworks --region us-east-1 deregister-instance --instance-id 4d6d1710-ded9-42a1-b08e-b043ad7af1e2

Output: None.

More Information

For more information, see Deregistering a Registered Instance in the Amazon OpsWorks User Guide.

The following code example shows how to use deregister-rds-db-instance.

Amazon CLI

To deregister an Amazon RDS DB instance from a stack

The following example deregisters an RDS DB instance, identified by its ARN, from its stack.

aws opsworks deregister-rds-db-instance --region us-east-1 --rds-db-instance-arn arn:aws:rds:us-west-2:123456789012:db:clitestdb

Output: None.

More Information

For more information, see Deregistering Amazon RDS Instances in the ASW OpsWorks User Guide.

instance ID: clitestdb Master usernams: cliuser Master PWD: some23!pwd DB Name: mydb aws opsworks deregister-rds-db-instance --region us-east-1 --rds-db-instance-arn arn:aws:rds:us-west-2:645732743964:db:clitestdb

The following code example shows how to use deregister-volume.

Amazon CLI

To deregister an Amazon EBS volume

The following example deregisters an EBS volume from its stack. The volume is identified by its volume ID, which is the GUID that Amazon OpsWorks assigned when you registered the volume with the stack, not the EC2 volume ID.

aws opsworks deregister-volume --region us-east-1 --volume-id 5c48ef52-3144-4bf5-beaa-fda4deb23d4d

Output: None.

More Information

For more information, see Deregistering Amazon EBS Volumes in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-apps.

Amazon CLI

To describe apps

The following describe-apps command describes the apps in a specified stack.

aws opsworks describe-apps \ --stack-id 38ee91e2-abdc-4208-a107-0b7168b3cc7a \ --region us-east-1

Output:

{ "Apps": [ { "StackId": "38ee91e2-abdc-4208-a107-0b7168b3cc7a", "AppSource": { "Url": "https://s3-us-west-2.amazonaws.com/opsworks-demo-assets/simplejsp.zip", "Type": "archive" }, "Name": "SimpleJSP", "EnableSsl": false, "SslConfiguration": {}, "AppId": "da1decc1-0dff-43ea-ad7c-bb667cd87c8b", "Attributes": { "RailsEnv": null, "AutoBundleOnDeploy": "true", "DocumentRoot": "ROOT" }, "Shortname": "simplejsp", "Type": "other", "CreatedAt": "2013-08-01T21:46:54+00:00" } ] }

For more information, see Apps in the Amazon OpsWorks User Guide.

  • For API details, see DescribeApps in Amazon CLI Command Reference.

The following code example shows how to use describe-commands.

Amazon CLI

To describe commands

The following describe-commands command describes the commands in a specified instance.

aws opsworks describe-commands \ --instance-id 8c2673b9-3fe5-420d-9cfa-78d875ee7687 \ --region us-east-1

Output:

{ "Commands": [ { "Status": "successful", "CompletedAt": "2013-07-25T18:57:47+00:00", "InstanceId": "8c2673b9-3fe5-420d-9cfa-78d875ee7687", "DeploymentId": "6ed0df4c-9ef7-4812-8dac-d54a05be1029", "AcknowledgedAt": "2013-07-25T18:57:41+00:00", "LogUrl": "https://s3.amazonaws.com/<bucket-name>/logs/008c1a91-ec59-4d51-971d-3adff54b00cc?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE &Expires=1375394373&Signature=HkXil6UuNfxTCC37EPQAa462E1E%3D&response-cache-control=private&response-content-encoding=gzip&response-content- type=text%2Fplain", "Type": "undeploy", "CommandId": "008c1a91-ec59-4d51-971d-3adff54b00cc", "CreatedAt": "2013-07-25T18:57:34+00:00", "ExitCode": 0 }, { "Status": "successful", "CompletedAt": "2013-07-25T18:55:40+00:00", "InstanceId": "8c2673b9-3fe5-420d-9cfa-78d875ee7687", "DeploymentId": "19d3121e-d949-4ff2-9f9d-94eac087862a", "AcknowledgedAt": "2013-07-25T18:55:32+00:00", "LogUrl": "https://s3.amazonaws.com/<bucket-name>/logs/899d3d64-0384-47b6-a586-33433aad117c?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE &Expires=1375394373&Signature=xMsJvtLuUqWmsr8s%2FAjVru0BtRs%3D&response-cache-control=private&response-content-encoding=gzip&response-conten t-type=text%2Fplain", "Type": "deploy", "CommandId": "899d3d64-0384-47b6-a586-33433aad117c", "CreatedAt": "2013-07-25T18:55:29+00:00", "ExitCode": 0 } ] }

For more information, see Amazon OpsWorks Lifecycle Events in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-deployments.

Amazon CLI

To describe deployments

The following describe-deployments command describes the deployments in a specified stack.

aws opsworks --region us-east-1 describe-deployments --stack-id 38ee91e2-abdc-4208-a107-0b7168b3cc7a

Output:

{ "Deployments": [ { "StackId": "38ee91e2-abdc-4208-a107-0b7168b3cc7a", "Status": "successful", "CompletedAt": "2013-07-25T18:57:49+00:00", "DeploymentId": "6ed0df4c-9ef7-4812-8dac-d54a05be1029", "Command": { "Args": {}, "Name": "undeploy" }, "CreatedAt": "2013-07-25T18:57:34+00:00", "Duration": 15, "InstanceIds": [ "8c2673b9-3fe5-420d-9cfa-78d875ee7687", "9e588a25-35b2-4804-bd43-488f85ebe5b7" ] }, { "StackId": "38ee91e2-abdc-4208-a107-0b7168b3cc7a", "Status": "successful", "CompletedAt": "2013-07-25T18:56:41+00:00", "IamUserArn": "arn:aws:iam::123456789012:user/someuser", "DeploymentId": "19d3121e-d949-4ff2-9f9d-94eac087862a", "Command": { "Args": {}, "Name": "deploy" }, "InstanceIds": [ "8c2673b9-3fe5-420d-9cfa-78d875ee7687", "9e588a25-35b2-4804-bd43-488f85ebe5b7" ], "Duration": 72, "CreatedAt": "2013-07-25T18:55:29+00:00" } ] }

More Information

For more information, see Deploying Apps in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-elastic-ips.

Amazon CLI

To describe Elastic IP instances

The following describe-elastic-ips command describes the Elastic IP addresses in a specified instance.

aws opsworks --region us-east-1 describe-elastic-ips --instance-id b62f3e04-e9eb-436c-a91f-d9e9a396b7b0

Output:

{ "ElasticIps": [ { "Ip": "192.0.2.0", "Domain": "standard", "Region": "us-west-2" } ] }

More Information

For more information, see Instances in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-elastic-load-balancers.

Amazon CLI

To describe a stack's elastic load balancers

The following describe-elastic-load-balancers command describes a specified stack's load balancers.

aws opsworks --region us-west-2 describe-elastic-load-balancers --stack-id 6f4660e5-37a6-4e42-bfa0-1358ebd9c182

Output: This particular stack has one load balancer.

{ "ElasticLoadBalancers": [ { "SubnetIds": [ "subnet-60e4ea04", "subnet-66e1c110" ], "Ec2InstanceIds": [], "ElasticLoadBalancerName": "my-balancer", "Region": "us-west-2", "LayerId": "344973cb-bf2b-4cd0-8d93-51cd819bab04", "AvailabilityZones": [ "us-west-2a", "us-west-2b" ], "VpcId": "vpc-b319f9d4", "StackId": "6f4660e5-37a6-4e42-bfa0-1358ebd9c182", "DnsName": "my-balancer-2094040179.us-west-2.elb.amazonaws.com" } ] }

More Information

For more information, see Apps in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-instances.

Amazon CLI

To describe instances

The following describe-instances command describes the instances in a specified stack:

aws opsworks --region us-east-1 describe-instances --stack-id 8c428b08-a1a1-46ce-a5f8-feddc43771b8

Output: The following output example is for a stack with two instances. The first is a registered EC2 instance, and the second was created by Amazon OpsWorks.

{ "Instances": [ { "StackId": "71c7ca72-55ae-4b6a-8ee1-a8dcded3fa0f", "PrivateDns": "ip-10-31-39-66.us-west-2.compute.internal", "LayerIds": [ "26cf1d32-6876-42fa-bbf1-9cadc0bff938" ], "EbsOptimized": false, "ReportedOs": { "Version": "14.04", "Name": "ubuntu", "Family": "debian" }, "Status": "online", "InstanceId": "4d6d1710-ded9-42a1-b08e-b043ad7af1e2", "SshKeyName": "US-West-2", "InfrastructureClass": "ec2", "RootDeviceVolumeId": "vol-d08ec6c1", "SubnetId": "subnet-b8de0ddd", "InstanceType": "t1.micro", "CreatedAt": "2015-02-24T20:52:49+00:00", "AmiId": "ami-35501205", "Hostname": "ip-192-0-2-0", "Ec2InstanceId": "i-5cd23551", "PublicDns": "ec2-192-0-2-0.us-west-2.compute.amazonaws.com", "SecurityGroupIds": [ "sg-c4d3f0a1" ], "Architecture": "x86_64", "RootDeviceType": "ebs", "InstallUpdatesOnBoot": true, "Os": "Custom", "VirtualizationType": "paravirtual", "AvailabilityZone": "us-west-2a", "PrivateIp": "10.31.39.66", "PublicIp": "192.0.2.06", "RegisteredBy": "arn:aws:iam::123456789102:user/AWS/OpsWorks/OpsWorks-EC2Register-i-5cd23551" }, { "StackId": "71c7ca72-55ae-4b6a-8ee1-a8dcded3fa0f", "PrivateDns": "ip-10-31-39-158.us-west-2.compute.internal", "SshHostRsaKeyFingerprint": "69:6b:7b:8b:72:f3:ed:23:01:00:05:bc:9f:a4:60:c1", "LayerIds": [ "26cf1d32-6876-42fa-bbf1-9cadc0bff938" ], "EbsOptimized": false, "ReportedOs": {}, "Status": "booting", "InstanceId": "9b137a0d-2f5d-4cc0-9704-13da4b31fdcb", "SshKeyName": "US-West-2", "InfrastructureClass": "ec2", "RootDeviceVolumeId": "vol-e09dd5f1", "SubnetId": "subnet-b8de0ddd", "InstanceProfileArn": "arn:aws:iam::123456789102:instance-profile/aws-opsworks-ec2-role", "InstanceType": "c3.large", "CreatedAt": "2015-02-24T21:29:33+00:00", "AmiId": "ami-9fc29baf", "SshHostDsaKeyFingerprint": "fc:87:95:c3:f5:e1:3b:9f:d2:06:6e:62:9a:35:27:e8", "Ec2InstanceId": "i-8d2dca80", "PublicDns": "ec2-192-0-2-1.us-west-2.compute.amazonaws.com", "SecurityGroupIds": [ "sg-b022add5", "sg-b122add4" ], "Architecture": "x86_64", "RootDeviceType": "ebs", "InstallUpdatesOnBoot": true, "Os": "Amazon Linux 2014.09", "VirtualizationType": "paravirtual", "AvailabilityZone": "us-west-2a", "Hostname": "custom11", "PrivateIp": "10.31.39.158", "PublicIp": "192.0.2.0" } ] }

More Information

For more information, see Instances in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-layers.

Amazon CLI

To describe a stack's layers

The following describe-layers command describes the layers in a specified stack:

aws opsworks --region us-east-1 describe-layers --stack-id 38ee91e2-abdc-4208-a107-0b7168b3cc7a

Output:

{ "Layers": [ { "StackId": "38ee91e2-abdc-4208-a107-0b7168b3cc7a", "Type": "db-master", "DefaultSecurityGroupNames": [ "AWS-OpsWorks-DB-Master-Server" ], "Name": "MySQL", "Packages": [], "DefaultRecipes": { "Undeploy": [], "Setup": [ "opsworks_initial_setup", "ssh_host_keys", "ssh_users", "mysql::client", "dependencies", "ebs", "opsworks_ganglia::client", "mysql::server", "dependencies", "deploy::mysql" ], "Configure": [ "opsworks_ganglia::configure-client", "ssh_users", "agent_version", "deploy::mysql" ], "Shutdown": [ "opsworks_shutdown::default", "mysql::stop" ], "Deploy": [ "deploy::default", "deploy::mysql" ] }, "CustomRecipes": { "Undeploy": [], "Setup": [], "Configure": [], "Shutdown": [], "Deploy": [] }, "EnableAutoHealing": false, "LayerId": "41a20847-d594-4325-8447-171821916b73", "Attributes": { "MysqlRootPasswordUbiquitous": "true", "RubygemsVersion": null, "RailsStack": null, "HaproxyHealthCheckMethod": null, "RubyVersion": null, "BundlerVersion": null, "HaproxyStatsPassword": null, "PassengerVersion": null, "MemcachedMemory": null, "EnableHaproxyStats": null, "ManageBundler": null, "NodejsVersion": null, "HaproxyHealthCheckUrl": null, "MysqlRootPassword": "*****FILTERED*****", "GangliaPassword": null, "GangliaUser": null, "HaproxyStatsUrl": null, "GangliaUrl": null, "HaproxyStatsUser": null }, "Shortname": "db-master", "AutoAssignElasticIps": false, "CustomSecurityGroupIds": [], "CreatedAt": "2013-07-25T18:11:19+00:00", "VolumeConfigurations": [ { "MountPoint": "/vol/mysql", "Size": 10, "NumberOfDisks": 1 } ] }, { "StackId": "38ee91e2-abdc-4208-a107-0b7168b3cc7a", "Type": "custom", "DefaultSecurityGroupNames": [ "AWS-OpsWorks-Custom-Server" ], "Name": "TomCustom", "Packages": [], "DefaultRecipes": { "Undeploy": [], "Setup": [ "opsworks_initial_setup", "ssh_host_keys", "ssh_users", "mysql::client", "dependencies", "ebs", "opsworks_ganglia::client" ], "Configure": [ "opsworks_ganglia::configure-client", "ssh_users", "agent_version" ], "Shutdown": [ "opsworks_shutdown::default" ], "Deploy": [ "deploy::default" ] }, "CustomRecipes": { "Undeploy": [], "Setup": [ "tomcat::setup" ], "Configure": [ "tomcat::configure" ], "Shutdown": [], "Deploy": [ "tomcat::deploy" ] }, "EnableAutoHealing": true, "LayerId": "e6cbcd29-d223-40fc-8243-2eb213377440", "Attributes": { "MysqlRootPasswordUbiquitous": null, "RubygemsVersion": null, "RailsStack": null, "HaproxyHealthCheckMethod": null, "RubyVersion": null, "BundlerVersion": null, "HaproxyStatsPassword": null, "PassengerVersion": null, "MemcachedMemory": null, "EnableHaproxyStats": null, "ManageBundler": null, "NodejsVersion": null, "HaproxyHealthCheckUrl": null, "MysqlRootPassword": null, "GangliaPassword": null, "GangliaUser": null, "HaproxyStatsUrl": null, "GangliaUrl": null, "HaproxyStatsUser": null }, "Shortname": "tomcustom", "AutoAssignElasticIps": false, "CustomSecurityGroupIds": [], "CreatedAt": "2013-07-25T18:12:53+00:00", "VolumeConfigurations": [] } ] }

More Information

For more information, see Layers in the Amazon OpsWorks User Guide.

  • For API details, see DescribeLayers in Amazon CLI Command Reference.

The following code example shows how to use describe-load-based-auto-scaling.

Amazon CLI

To describe a layer's load-based scaling configuration

The following example describes a specified layer's load-based scaling configuration. The layer is identified by its layer ID, which you can find on the layer's details page or by running describe-layers.

aws opsworks describe-load-based-auto-scaling --region us-east-1 --layer-ids 6bec29c9-c866-41a0-aba5-fa3e374ce2a1

Output: The example layer has a single load-based instance.

{ "LoadBasedAutoScalingConfigurations": [ { "DownScaling": { "IgnoreMetricsTime": 10, "ThresholdsWaitTime": 10, "InstanceCount": 1, "CpuThreshold": 30.0 }, "Enable": true, "UpScaling": { "IgnoreMetricsTime": 5, "ThresholdsWaitTime": 5, "InstanceCount": 1, "CpuThreshold": 80.0 }, "LayerId": "6bec29c9-c866-41a0-aba5-fa3e374ce2a1" } ] }

More Information

For more information, see How Automatic Load-based Scaling Works in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-my-user-profile.

Amazon CLI

To obtain a user's profile

The following example shows how to obtain the profile of the Amazon Identity and Access Management (IAM) user that is running the command.

aws opsworks --region us-east-1 describe-my-user-profile

Output: For brevity, most of the user's SSH public key is replaced by an ellipsis (...).

{ "UserProfile": { "IamUserArn": "arn:aws:iam::123456789012:user/myusername", "SshPublicKey": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQ...3LQ4aX9jpxQw== rsa-key-20141104", "Name": "myusername", "SshUsername": "myusername" } }

More Information

For more information, see Importing Users into Amazon OpsWorks in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-permissions.

Amazon CLI

To obtain a user's per-stack Amazon OpsWorks permission level

The following example shows how to to obtain an Amazon Identity and Access Management (IAM) user's permission level on a specified stack.

aws opsworks --region us-east-1 describe-permissions --iam-user-arn arn:aws:iam::123456789012:user/cli-user-test --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06

Output:

{ "Permissions": [ { "StackId": "d72553d4-8727-448c-9b00-f024f0ba1b06", "IamUserArn": "arn:aws:iam::123456789012:user/cli-user-test", "Level": "manage", "AllowSudo": true, "AllowSsh": true } ] }

More Information

For more information, see Granting Per-Stack Permissions Levels in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-raid-arrays.

Amazon CLI

To describe RAID arrays

The following example describes the RAID arrays attached to the instances in a specified stack.

aws opsworks --region us-east-1 describe-raid-arrays --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06

Output: The following is the output for a stack with one RAID array.

{ "RaidArrays": [ { "StackId": "d72553d4-8727-448c-9b00-f024f0ba1b06", "AvailabilityZone": "us-west-2a", "Name": "Created for php-app1", "NumberOfDisks": 2, "InstanceId": "9f14adbc-ced5-43b6-bf01-e7d0db6cf2f7", "RaidLevel": 0, "VolumeType": "standard", "RaidArrayId": "f2d4e470-5972-4676-b1b8-bae41ec3e51c", "Device": "/dev/md0", "MountPoint": "/mnt/workspace", "CreatedAt": "2015-02-26T23:53:09+00:00", "Size": 100 } ] }

For more information, see EBS Volumes in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-rds-db-instances.

Amazon CLI

To describe a stack's registered Amazon RDS instances

The following example describes the Amazon RDS instances registered with a specified stack.

aws opsworks --region us-east-1 describe-rds-db-instances --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06

Output: The following is the output for a stack with one registered RDS instance.

{ "RdsDbInstances": [ { "Engine": "mysql", "StackId": "d72553d4-8727-448c-9b00-f024f0ba1b06", "MissingOnRds": false, "Region": "us-west-2", "RdsDbInstanceArn": "arn:aws:rds:us-west-2:123456789012:db:clitestdb", "DbPassword": "*****FILTERED*****", "Address": "clitestdb.cdlqlk5uwd0k.us-west-2.rds.amazonaws.com", "DbUser": "cliuser", "DbInstanceIdentifier": "clitestdb" } ] }

For more information, see Resource Management in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-stack-provisioning-parameters.

Amazon CLI

To return the provisioning parameters for a stack

The following describe-stack-provisioning-parameters example returns the provisioning parameters for a specified stack. Provisioning parameters include settings such as the agent installation location and public key that OpsWorks uses to manage the agent on instances in a stack.

aws opsworks describe-stack-provisioning-parameters \ --stack-id 62744d97-6faf-4ecb-969b-a086fEXAMPLE

Output:

{ "AgentInstallerUrl": "https://opsworks-instance-agent-us-west-2.s3.amazonaws.com/ID_number/opsworks-agent-installer.tgz", "Parameters": { "agent_installer_base_url": "https://opsworks-instance-agent-us-west-2.s3.amazonaws.com", "agent_installer_tgz": "opsworks-agent-installer.tgz", "assets_download_bucket": "opsworks-instance-assets-us-west-2.s3.amazonaws.com", "charlie_public_key": "-----BEGIN PUBLIC KEY-----PUBLIC_KEY_EXAMPLE\n-----END PUBLIC KEY-----", "instance_service_endpoint": "opsworks-instance-service.us-west-2.amazonaws.com", "instance_service_port": "443", "instance_service_region": "us-west-2", "instance_service_ssl_verify_peer": "true", "instance_service_use_ssl": "true", "ops_works_endpoint": "opsworks.us-west-2.amazonaws.com", "ops_works_port": "443", "ops_works_region": "us-west-2", "ops_works_ssl_verify_peer": "true", "ops_works_use_ssl": "true", "verbose": "false", "wait_between_runs": "30" } }

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

The following code example shows how to use describe-stack-summary.

Amazon CLI

To describe a stack's configuration

The following describe-stack-summary command returns a summary of the specified stack's configuration.

aws opsworks --region us-east-1 describe-stack-summary --stack-id 8c428b08-a1a1-46ce-a5f8-feddc43771b8

Output:

{ "StackSummary": { "StackId": "8c428b08-a1a1-46ce-a5f8-feddc43771b8", "InstancesCount": { "Booting": 1 }, "Name": "CLITest", "AppsCount": 1, "LayersCount": 1, "Arn": "arn:aws:opsworks:us-west-2:123456789012:stack/8c428b08-a1a1-46ce-a5f8-feddc43771b8/" } }

More Information

For more information, see Stacks in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-stacks.

Amazon CLI

To describe stacks

The following describe-stacks command describes an account's stacks.

aws opsworks --region us-east-1 describe-stacks

Output:

{ "Stacks": [ { "ServiceRoleArn": "arn:aws:iam::444455556666:role/aws-opsworks-service-role", "StackId": "aeb7523e-7c8b-49d4-b866-03aae9d4fbcb", "DefaultRootDeviceType": "instance-store", "Name": "TomStack-sd", "ConfigurationManager": { "Version": "11.4", "Name": "Chef" }, "UseCustomCookbooks": true, "CustomJson": "{\n \"tomcat\": {\n \"base_version\": 7,\n \"java_opts\": \"-Djava.awt.headless=true -Xmx256m\"\n },\n \"datasources\": {\n \"ROOT\": \"jdbc/mydb\"\n }\n}", "Region": "us-east-1", "DefaultInstanceProfileArn": "arn:aws:iam::444455556666:instance-profile/aws-opsworks-ec2-role", "CustomCookbooksSource": { "Url": "git://github.com/example-repo/tomcustom.git", "Type": "git" }, "DefaultAvailabilityZone": "us-east-1a", "HostnameTheme": "Layer_Dependent", "Attributes": { "Color": "rgb(45, 114, 184)" }, "DefaultOs": "Amazon Linux", "CreatedAt": "2013-08-01T22:53:42+00:00" }, { "ServiceRoleArn": "arn:aws:iam::444455556666:role/aws-opsworks-service-role", "StackId": "40738975-da59-4c5b-9789-3e422f2cf099", "DefaultRootDeviceType": "instance-store", "Name": "MyStack", "ConfigurationManager": { "Version": "11.4", "Name": "Chef" }, "UseCustomCookbooks": false, "Region": "us-east-1", "DefaultInstanceProfileArn": "arn:aws:iam::444455556666:instance-profile/aws-opsworks-ec2-role", "CustomCookbooksSource": {}, "DefaultAvailabilityZone": "us-east-1a", "HostnameTheme": "Layer_Dependent", "Attributes": { "Color": "rgb(45, 114, 184)" }, "DefaultOs": "Amazon Linux", "CreatedAt": "2013-10-25T19:24:30+00:00" } ] }

More Information

For more information, see Stacks in the Amazon OpsWorks User Guide.

  • For API details, see DescribeStacks in Amazon CLI Command Reference.

The following code example shows how to use describe-timebased-auto-scaling.

Amazon CLI

To describe the time-based scaling configuration of an instance

The following example describes a specified instance's time-based scaling configuration. The instance is identified by its instance ID, which you can find on the instances's details page or by running describe-instances.

aws opsworks describe-time-based-auto-scaling --region us-east-1 --instance-ids 701f2ffe-5d8e-4187-b140-77b75f55de8d

Output: The example has a single time-based instance.

{ "TimeBasedAutoScalingConfigurations": [ { "InstanceId": "701f2ffe-5d8e-4187-b140-77b75f55de8d", "AutoScalingSchedule": { "Monday": { "11": "on", "10": "on", "13": "on", "12": "on" }, "Tuesday": { "11": "on", "10": "on", "13": "on", "12": "on" } } } ] }

More Information

For more information, see How Automatic Time-based Scaling Works in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-user-profiles.

Amazon CLI

To describe user profiles

The following describe-user-profiles command describes the account's user profiles.

aws opsworks --region us-east-1 describe-user-profiles

Output:

{ "UserProfiles": [ { "IamUserArn": "arn:aws:iam::123456789012:user/someuser", "SshPublicKey": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAkOuP7i80q3Cko...", "AllowSelfManagement": true, "Name": "someuser", "SshUsername": "someuser" }, { "IamUserArn": "arn:aws:iam::123456789012:user/cli-user-test", "AllowSelfManagement": true, "Name": "cli-user-test", "SshUsername": "myusername" } ] }

More Information

For more information, see Managing Amazon OpsWorks Users in the Amazon OpsWorks User Guide.

The following code example shows how to use describe-volumes.

Amazon CLI

To describe a stack's volumes

The following example describes a stack's EBS volumes.

aws opsworks --region us-east-1 describe-volumes --stack-id 8c428b08-a1a1-46ce-a5f8-feddc43771b8

Output:

{ "Volumes": [ { "Status": "in-use", "AvailabilityZone": "us-west-2a", "Name": "CLITest", "InstanceId": "dfe18b02-5327-493d-91a4-c5c0c448927f", "VolumeType": "standard", "VolumeId": "56b66fbd-e1a1-4aff-9227-70f77118d4c5", "Device": "/dev/sdi", "Ec2VolumeId": "vol-295c1638", "MountPoint": "/mnt/myvolume", "Size": 1 } ] }

More Information

For more information, see Resource Management in the Amazon OpsWorks User Guide.

The following code example shows how to use detach-elastic-load-balancer.

Amazon CLI

To detach a load balancer from its layer

The following example detaches a load balancer, identified by its name, from its layer.

aws opsworks --region us-east-1 detach-elastic-load-balancer --elastic-load-balancer-name Java-LB --layer-id 888c5645-09a5-4d0e-95a8-812ef1db76a4

Output: None.

More Information

For more information, see Elastic Load Balancing in the Amazon OpsWorks User Guide.

The following code example shows how to use disassociate-elastic-ip.

Amazon CLI

To disassociate an Elastic IP address from an instance

The following example disassociates an Elastic IP address from a specified instance.

aws opsworks --region us-east-1 disassociate-elastic-ip --elastic-ip 54.148.130.96

Output: None.

More Information

For more information, see Resource Management in the Amazon OpsWorks User Guide.

The following code example shows how to use get-hostname-suggestion.

Amazon CLI

To get the next hostname for a layer

The following example gets the next generated hostname for a specified layer. The layer used for this example is a Java Application Server layer with one instance. The stack's hostname theme is the default, Layer_Dependent.

aws opsworks --region us-east-1 get-hostname-suggestion --layer-id 888c5645-09a5-4d0e-95a8-812ef1db76a4

Output:

{ "Hostname": "java-app2", "LayerId": "888c5645-09a5-4d0e-95a8-812ef1db76a4" }

More Information

For more information, see Create a New Stack in the Amazon OpsWorks User Guide.

The following code example shows how to use reboot-instance.

Amazon CLI

To reboot an instance

The following example reboots an instance.

aws opsworks --region us-east-1 reboot-instance --instance-id dfe18b02-5327-493d-91a4-c5c0c448927f

Output: None.

More Information

For more information, see Rebooting an Instance in the Amazon OpsWorks User Guide.

  • For API details, see RebootInstance in Amazon CLI Command Reference.

The following code example shows how to use register-elastic-ip.

Amazon CLI

To register an Elastic IP address with a stack

The following example registers an Elastic IP address, identified by its IP address, with a specified stack.

Note: The Elastic IP address must be in the same region as the stack.

aws opsworks register-elastic-ip --region us-east-1 --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06 --elastic-ip 54.148.130.96

Output

{ "ElasticIp": "54.148.130.96" }

More Information

For more information, see Registering Elastic IP Addresses with a Stack in the OpsWorks User Guide.

The following code example shows how to use register-rds-db-instance.

Amazon CLI

To register an Amazon RDS instance with a stack

The following example registers an Amazon RDS DB instance, identified by its Amazon Resource Name (ARN), with a specified stack. It also specifies the instance's master username and password. Note that Amazon OpsWorks does not validate either of these values. If either one is incorrect, your application will not be able to connect to the database.

aws opsworks register-rds-db-instance --region us-east-1 --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06 --rds-db-instance-arn arn:aws:rds:us-west-2:123456789012:db:clitestdb --db-user cliuser --db-password some23!pwd

Output: None.

More Information

For more information, see Registering Amazon RDS Instances with a Stack in the Amazon OpsWorks User Guide.

The following code example shows how to use register-volume.

Amazon CLI

To register an Amazon EBS volume with a stack

The following example registers an Amazon EBS volume, identified by its volume ID, with a specified stack.

aws opsworks register-volume --region us-east-1 --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06 --ec-2-volume-id vol-295c1638

Output:

{ "VolumeId": "ee08039c-7cb7-469f-be10-40fb7f0c05e8" }

More Information

For more information, see Registering Amazon EBS Volumes with a Stack in the Amazon OpsWorks User Guide.

  • For API details, see RegisterVolume in Amazon CLI Command Reference.

The following code example shows how to use register.

Amazon CLI

To register instances with a stack

The following examples show a variety of ways to register instances with a stack that were created outside of Amazon Opsworks. You can run register from the instance to be registered, or from a separate workstation. For more information, see Registering Amazon EC2 and On-premises Instances in the Amazon OpsWorks User Guide.

Note: For brevity, the examples omit the region argument.

To register an Amazon EC2 instance

To indicate that you are registering an EC2 instance, set the --infrastructure-class argument to ec2.

The following example registers an EC2 instance with the specified stack from a separate workstation. The instance is identified by its EC2 ID, i-12345678. The example uses the workstation's default SSH username and attempts to log in to the instance using authentication techniques that do not require a password, such as a default private SSH key. If that fails, register queries for the password.

aws opsworks register --infrastructure-class=ec2 --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb i-12345678

The following example registers an EC2 instance with the specifed stack from a separate workstation. It uses the --ssh-username and --ssh-private-key arguments to explicitly specify the SSH username and private key file that the command uses to log into the instance. ec2-user is the standard username for Amazon Linux instances. Use ubuntu for Ubuntu instances.

aws opsworks register --infrastructure-class=ec2 --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --ssh-username ec2-user --ssh-private-key ssh_private_key i-12345678

The following example registers the EC2 instance that is running the register command. Log in to the instance with SSH and run register with the --local argument instead of an instance ID or hostname.

aws opsworks register --infrastructure-class ec2 --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --local

To register an on-premises instance

To indicate that you are registering an on-premises instance, set the --infrastructure-class argument to on-premises.

The following example registers an existing on-premises instance with a specified stack from a separate workstation. The instance is identified by its IP address, 192.0.2.3. The example uses the workstation's default SSH username and attempts to log in to the instance using authentication techniques that do not require a password, such as a default private SSH key. If that fails, register queries for the password.

aws opsworks register --infrastructure-class on-premises --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb 192.0.2.3

The following example registers an on-premises instance with a specified stack from a separate workstation. The instance is identified by its hostname, host1. The --override-... arguments direct Amazon OpsWorks to display webserver1 as the host name and 192.0.2.3 and 10.0.0.2 as the instance's public and private IP addresses, respectively.

aws opsworks register --infrastructure-class on-premises --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --override-hostname webserver1 --override-public-ip 192.0.2.3 --override-private-ip 10.0.0.2 host1

The following example registers an on-premises instance with a specified stack from a separate workstation. The instance is identified by its IP address. register logs into the instance using the specified SSH username and private key file.

aws opsworks register --infrastructure-class on-premises --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --ssh-username admin --ssh-private-key ssh_private_key 192.0.2.3

The following example registers an existing on-premises instance with a specified stack from a separate workstation. The command logs into the instance using a custom SSH command string that specifies the SSH password and the instance's IP address.

aws opsworks register --infrastructure-class on-premises --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --override-ssh "sshpass -p 'mypassword' ssh your-user@192.0.2.3"

The following example registers the on-premises instance that is running the register command. Log in to the instance with SSH and run register with the --local argument instead of an instance ID or hostname.

aws opsworks register --infrastructure-class on-premises --stack-id 935450cc-61e0-4b03-a3e0-160ac817d2bb --local

Output: The following is typical output for registering an EC2 instance.

Warning: Permanently added '52.11.41.206' (ECDSA) to the list of known hosts. % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 6403k 100 6403k 0 0 2121k 0 0:00:03 0:00:03 --:--:-- 2121k [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Initializing AWS OpsWorks environment [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Running on Ubuntu [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Checking if OS is supported [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Running on supported OS [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Setup motd [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Executing: ln -sf --backup /etc/motd.opsworks-static /etc/motd [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Enabling multiverse repositories [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Customizing APT environment [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Installing system packages [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Executing: dpkg --configure -a [Tue, 24 Feb 2015 20:48:37 +0000] opsworks-init: Executing with retry: apt-get update [Tue, 24 Feb 2015 20:49:13 +0000] opsworks-init: Executing: apt-get install -y ruby ruby-dev libicu-dev libssl-dev libxslt-dev libxml2-dev libyaml-dev monit [Tue, 24 Feb 2015 20:50:13 +0000] opsworks-init: Using assets bucket from environment: 'opsworks-instance-assets-us-east-1.s3.amazonaws.com'. [Tue, 24 Feb 2015 20:50:13 +0000] opsworks-init: Installing Ruby for the agent [Tue, 24 Feb 2015 20:50:13 +0000] opsworks-init: Executing: /tmp/opsworks-agent-installer.YgGq8wF3UUre6yDy/opsworks-agent-installer/opsworks-agent/bin/installer_wrapper.sh -r -R opsworks-instance-assets-us-east-1.s3.amazonaws.com [Tue, 24 Feb 2015 20:50:44 +0000] opsworks-init: Starting the installer Instance successfully registered. Instance ID: 4d6d1710-ded9-42a1-b08e-b043ad7af1e2 Connection to 52.11.41.206 closed.

More Information

For more information, see Registering an Instance with an Amazon OpsWorks Stack in the Amazon OpsWorks User Guide.

  • For API details, see Register in Amazon CLI Command Reference.

The following code example shows how to use set-load-based-auto-scaling.

Amazon CLI

To set the load-based scaling configuration for a layer

The following example enables load-based scaling for a specified layer and sets the configuration for that layer. You must use create-instance to add load-based instances to the layer.

aws opsworks --region us-east-1 set-load-based-auto-scaling --layer-id 523569ae-2faf-47ac-b39e-f4c4b381f36d --enable --up-scaling file://upscale.json --down-scaling file://downscale.json

The example puts the upscaling threshold settings in a separate file in the working directory named upscale.json, which contains the following.

{ "InstanceCount": 2, "ThresholdsWaitTime": 3, "IgnoreMetricsTime": 3, "CpuThreshold": 85, "MemoryThreshold": 85, "LoadThreshold": 85 }

The example puts the downscaling threshold settings in a separate file in the working directory named downscale.json, which contains the following.

{ "InstanceCount": 2, "ThresholdsWaitTime": 3, "IgnoreMetricsTime": 3, "CpuThreshold": 35, "MemoryThreshold": 30, "LoadThreshold": 30 }

Output: None.

More Information

For more information, see Using Automatic Load-based Scaling in the Amazon OpsWorks User Guide.

The following code example shows how to use set-permission.

Amazon CLI

To grant per-stack Amazon OpsWorks permission levels

When you import an Amazon Identity and Access Management (IAM) user into Amazon OpsWorks by calling create-user-profile, the user has only those permissions that are granted by the attached IAM policies. You can grant Amazon OpsWorks permissions by modifying a user's policies. However, it is often easier to import a user and then use the set-permission command to grant the user one of the standard permission levels for each stack to which the user will need access.

The following example grants permission for the specified stack for a user, who is identified by Amazon Resource Name (ARN). The example grants the user a Manage permissions level, with sudo and SSH privileges on the stack's instances.

aws opsworks set-permission --region us-east-1 --stack-id 71c7ca72-55ae-4b6a-8ee1-a8dcded3fa0f --level manage --iam-user-arn arn:aws:iam::123456789102:user/cli-user-test --allow-ssh --allow-sudo

Output: None.

More Information

For more information, see Granting Amazon OpsWorks Users Per-Stack Permissions in the Amazon OpsWorks User Guide.

  • For API details, see SetPermission in Amazon CLI Command Reference.

The following code example shows how to use set-time-based-auto-scaling.

Amazon CLI

To set the time-based scaling configuration for a layer

The following example sets the time-based configuration for a specified instance. You must first use create-instance to add the instance to the layer.

aws opsworks --region us-east-1 set-time-based-auto-scaling --instance-id 69b6237c-08c0-4edb-a6af-78f3d01cedf2 --auto-scaling-schedule file://schedule.json

The example puts the schedule in a separate file in the working directory named schedule.json. For this example, the instance is on for a few hours around midday UTC (Coordinated Universal Time) on Monday and Tuesday.

{ "Monday": { "10": "on", "11": "on", "12": "on", "13": "on" }, "Tuesday": { "10": "on", "11": "on", "12": "on", "13": "on" } }

Output: None.

More Information

For more information, see Using Automatic Time-based Scaling in the Amazon OpsWorks User Guide.

The following code example shows how to use start-instance.

Amazon CLI

To start an instance

The following start-instance command starts a specified 24/7 instance.

aws opsworks start-instance --instance-id f705ee48-9000-4890-8bd3-20eb05825aaf

Output: None. Use describe-instances to check the instance's status.

Tip You can start every offline instance in a stack with one command by calling start-stack.

More Information

For more information, see Manually Starting, Stopping, and Rebooting 24/7 Instances in the Amazon OpsWorks User Guide.

  • For API details, see StartInstance in Amazon CLI Command Reference.

The following code example shows how to use start-stack.

Amazon CLI

To start a stack's instances

The following example starts all of a stack's 24/7 instances. To start a particular instance, use start-instance.

aws opsworks --region us-east-1 start-stack --stack-id 8c428b08-a1a1-46ce-a5f8-feddc43771b8

Output: None.

More Information

For more information, see Starting an Instance in the Amazon OpsWorks User Guide.

  • For API details, see StartStack in Amazon CLI Command Reference.

The following code example shows how to use stop-instance.

Amazon CLI

To stop an instance

The following example stops a specified instance, which is identified by its instance ID. You can obtain an instance ID by going to the instance's details page on the Amazon OpsWorks console or by running the describe-instances command.

aws opsworks stop-instance --region us-east-1 --instance-id 3a21cfac-4a1f-4ce2-a921-b2cfba6f7771

You can restart a stopped instance by calling start-instance or by deleting the instance by calling delete-instance.

Output: None.

More Information

For more information, see Stopping an Instance in the Amazon OpsWorks User Guide.

  • For API details, see StopInstance in Amazon CLI Command Reference.

The following code example shows how to use stop-stack.

Amazon CLI

To stop a stack's instances

The following example stops all of a stack's 24/7 instances. To stop a particular instance, use stop-instance.

aws opsworks --region us-east-1 stop-stack --stack-id 8c428b08-a1a1-46ce-a5f8-feddc43771b8

Output: No output.

More Information

For more information, see Stopping an Instance in the Amazon OpsWorks User Guide.

  • For API details, see StopStack in Amazon CLI Command Reference.

The following code example shows how to use unassign-instance.

Amazon CLI

To unassign a registered instance from its layers

The following unassign-instance command unassigns an instance from its attached layers.

aws opsworks --region us-east-1 unassign-instance --instance-id 4d6d1710-ded9-42a1-b08e-b043ad7af1e2

Output: None.

More Information

For more information, see Unassigning a Registered Instance in the Amazon OpsWorks User Guide.

The following code example shows how to use unassign-volume.

Amazon CLI

To unassign a volume from its instance

The following example unassigns a registered Amazon Elastic Block Store (Amazon EBS) volume from its instance. The volume is identified by its volume ID, which is the GUID that Amazon OpsWorks assigns when you register the volume with a stack, not the Amazon Elastic Compute Cloud (Amazon EC2) volume ID.

aws opsworks --region us-east-1 unassign-volume --volume-id 8430177d-52b7-4948-9c62-e195af4703df

Output: None.

More Information

For more information, see Unassigning Amazon EBS Volumes in the Amazon OpsWorks User Guide.

  • For API details, see UnassignVolume in Amazon CLI Command Reference.

The following code example shows how to use update-app.

Amazon CLI

To update an app

The following example updates a specified app to change its name.

aws opsworks --region us-east-1 update-app --app-id 26a61ead-d201-47e3-b55c-2a7c666942f8 --name NewAppName

Output: None.

More Information

For more information, see Editing Apps in the Amazon OpsWorks User Guide.

  • For API details, see UpdateApp in Amazon CLI Command Reference.

The following code example shows how to use update-elastic-ip.

Amazon CLI

To update an Elastic IP address name

The following example updates the name of a specified Elastic IP address.

aws opsworks --region us-east-1 update-elastic-ip --elastic-ip 54.148.130.96 --name NewIPName

Output: None.

More Information

For more information, see Resource Management in the Amazon OpsWorks User Guide.

The following code example shows how to use update-instance.

Amazon CLI

To update an instance

The following example updates a specified instance's type.

aws opsworks --region us-east-1 update-instance --instance-id dfe18b02-5327-493d-91a4-c5c0c448927f --instance-type c3.xlarge

Output: None.

More Information

For more information, see Editing the Instance Configuration in the Amazon OpsWorks User Guide.

  • For API details, see UpdateInstance in Amazon CLI Command Reference.

The following code example shows how to use update-layer.

Amazon CLI

To update a layer

The following example updates a specified layer to use Amazon EBS-optimized instances.

aws opsworks --region us-east-1 update-layer --layer-id 888c5645-09a5-4d0e-95a8-812ef1db76a4 --use-ebs-optimized-instances

Output: None.

More Information

For more information, see Editing an OpsWorks Layer's Configuration in the Amazon OpsWorks User Guide.

  • For API details, see UpdateLayer in Amazon CLI Command Reference.

The following code example shows how to use update-my-user-profile.

Amazon CLI

To update a user's profile

The following example updates the development user's profile to use a specified SSH public key. The user's Amazon credentials are represented by the development profile in the credentials file (~\.aws\credentials), and the key is in a .pem file in the working directory.

aws opsworks --region us-east-1 --profile development update-my-user-profile --ssh-public-key file://development_key.pem

Output: None.

More Information

For more information, see Editing Amazon OpsWorks User Settings in the Amazon OpsWorks User Guide.

The following code example shows how to use update-rds-db-instance.

Amazon CLI

To update a registered Amazon RDS DB instance

The following example updates an Amazon RDS instance's master password value. Note that this command does not change the RDS instance's master password, just the password that you provide to Amazon OpsWorks. If this password does not match the RDS instance's password, your application will not be able to connect to the database.

aws opsworks --region us-east-1 update-rds-db-instance --db-password 123456789

Output: None.

More Information

For more information, see Registering Amazon RDS Instances with a Stack in the Amazon OpsWorks User Guide.

The following code example shows how to use update-volume.

Amazon CLI

To update a registered volume

The following example updates a registered Amazon Elastic Block Store (Amazon EBS) volume's mount point. The volume is identified by its volume ID, which is the GUID that Amazon OpsWorks assigns to the volume when you register it with a stack, not the Amazon Elastic Compute Cloud (Amazon EC2) volume ID.:

aws opsworks --region us-east-1 update-volume --volume-id 8430177d-52b7-4948-9c62-e195af4703df --mount-point /mnt/myvol

Output: None.

More Information

For more information, see Assigning Amazon EBS Volumes to an Instance in the Amazon OpsWorks User Guide.

  • For API details, see UpdateVolume in Amazon CLI Command Reference.