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

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 create-environment-ec2.

Amazon CLI

To create an Amazon Cloud9 EC2 development environment

This following create-environment-ec2 example creates an Amazon Cloud9 development environment with the specified settings, launches an Amazon Elastic Compute Cloud (Amazon EC2) instance, and then connects from the instance to the environment.

aws cloud9 create-environment-ec2 \ --name my-demo-env \ --description "My demonstration development environment." \ --instance-type t2.micro --image-id amazonlinux-2023-x86_64 \ --subnet-id subnet-1fab8aEX \ --automatic-stop-time-minutes 60 \ --owner-arn arn:aws:iam::123456789012:user/MyDemoUser

Output:

{ "environmentId": "8a34f51ce1e04a08882f1e811bd706EX" }

For more information, see Creating an EC2 Environment in the Amazon Cloud9 User Guide.

The following code example shows how to use create-environment-membership.

Amazon CLI

To add an environment member to an Amazon Cloud9 development environment

This example adds the specified environment member to the specified Amazon Cloud9 development environment.

Command:

aws cloud9 create-environment-membership --environment-id 8a34f51ce1e04a08882f1e811bd706EX --user-arn arn:aws:iam::123456789012:user/AnotherDemoUser --permissions read-write

Output:

{ "membership": { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJ3LOROMOUXTBSU6EX", "userArn": "arn:aws:iam::123456789012:user/AnotherDemoUser", "permissions": "read-write" } }

The following code example shows how to use delete-environment-membership.

Amazon CLI

To delete an environment member from an Amazon Cloud9 development environment

This example deletes the specified environment member from the specified Amazon Cloud9 development environment.

Command:

aws cloud9 delete-environment-membership --environment-id 8a34f51ce1e04a08882f1e811bd706EX --user-arn arn:aws:iam::123456789012:user/AnotherDemoUser

Output:

None.

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

Amazon CLI

To delete an Amazon Cloud9 development environment

This example deletes the specified Amazon Cloud9 development environment. If an Amazon EC2 instance is connected to the environment, also terminates the instance.

Command:

aws cloud9 delete-environment --environment-id 8a34f51ce1e04a08882f1e811bd706EX

Output:

None.

The following code example shows how to use describe-environment-memberships.

Amazon CLI

To gets information about environment members for an Amazon Cloud9 development environment

This example gets information about environment members for the specified Amazon Cloud9 development environment.

Command:

aws cloud9 describe-environment-memberships --environment-id 8a34f51ce1e04a08882f1e811bd706EX

Output:

{ "memberships": [ { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJ3LOROMOUXTBSU6EX", "userArn": "arn:aws:iam::123456789012:user/AnotherDemoUser", "permissions": "read-write" }, { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJNUEDQAQWFELJDLEX", "userArn": "arn:aws:iam::123456789012:user/MyDemoUser", "permissions": "owner" } ] }

To get information about the owner of an Amazon Cloud9 development environment

This example gets information about the owner of the specified Amazon Cloud9 development environment.

Command:

aws cloud9 describe-environment-memberships --environment-id 8a34f51ce1e04a08882f1e811bd706EX --permissions owner

Output:

{ "memberships": [ { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJNUEDQAQWFELJDLEX", "userArn": "arn:aws:iam::123456789012:user/MyDemoUser", "permissions": "owner" } ] }

To get information about an environment member for multiple Amazon Cloud9 development environments

This example gets information about the specified environment member for multiple Amazon Cloud9 development environments.

Command:

aws cloud9 describe-environment-memberships --user-arn arn:aws:iam::123456789012:user/MyDemoUser

Output:

{ "memberships": [ { "environmentId": "10a75714bd494714929e7f5ec4125aEX", "lastAccess": 1516213427.0, "userId": "AIDAJNUEDQAQWFELJDLEX", "userArn": "arn:aws:iam::123456789012:user/MyDemoUser", "permissions": "owner" }, { "environmentId": "1980b80e5f584920801c09086667f0EX", "lastAccess": 1516144884.0, "userId": "AIDAJNUEDQAQWFELJDLEX", "userArn": "arn:aws:iam::123456789012:user/MyDemoUser", "permissions": "owner" } ] }

The following code example shows how to use describe-environment-status.

Amazon CLI

To get status information for an Amazon Cloud9 development environment

This example gets status information for the specified Amazon Cloud9 development environment.

Command:

aws cloud9 describe-environment-status --environment-id 685f892f431b45c2b28cb69eadcdb0EX

Output:

{ "status": "ready", "message": "Environment is ready to use" }

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

Amazon CLI

To get information about Amazon Cloud9 development environments

This example gets information about the specified Amazon Cloud9 development environments.

Command:

aws cloud9 describe-environments --environment-ids 685f892f431b45c2b28cb69eadcdb0EX 349c86d4579e4e7298d500ff57a6b2EX

Output:

{ "environments": [ { "id": "685f892f431b45c2b28cb69eadcdb0EX", "name": "my-demo-ec2-env", "description": "Created from CodeStar.", "type": "ec2", "arn": "arn:aws:cloud9:us-east-1:123456789012:environment:685f892f431b45c2b28cb69eadcdb0EX", "ownerArn": "arn:aws:iam::123456789012:user/MyDemoUser", "lifecycle": { "status": "CREATED" } }, { "id": "349c86d4579e4e7298d500ff57a6b2EX", "name": my-demo-ssh-env", "description": "", "type": "ssh", "arn": "arn:aws:cloud9:us-east-1:123456789012:environment:349c86d4579e4e7298d500ff57a6b2EX", "ownerArn": "arn:aws:iam::123456789012:user/MyDemoUser", "lifecycle": { "status": "CREATED" } } ] }

The following code example shows how to use list-environments.

Amazon CLI

To get a list of available Amazon Cloud9 development environment identifiers

This example gets a list of available Amazon Cloud9 development environment identifiers.

Command:

aws cloud9 list-environments

Output:

{ "environmentIds": [ "685f892f431b45c2b28cb69eadcdb0EX", "1980b80e5f584920801c09086667f0EX" ] }

The following code example shows how to use update-environment-membership.

Amazon CLI

To change the settings of an existing environment member for an Amazon Cloud9 development environment

This example changes the settings of the specified existing environment member for the specified Amazon Cloud9 development environment.

Command:

aws cloud9 update-environment-membership --environment-id 8a34f51ce1e04a08882f1e811bd706EX --user-arn arn:aws:iam::123456789012:user/AnotherDemoUser --permissions read-only

Output:

{ "membership": { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJ3LOROMOUXTBSU6EX", "userArn": "arn:aws:iam::123456789012:user/AnotherDemoUser", "permissions": "read-only" } }

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

Amazon CLI

To change the settings of an existing Amazon Cloud9 development environment

This example changes the specified settings of the specified existing Amazon Cloud9 development environment.

Command:

aws cloud9 update-environment --environment-id 8a34f51ce1e04a08882f1e811bd706EX --name my-changed-demo-env --description "My changed demonstration development environment."

Output:

None.