AWS Cloud9 examples using AWS CLI
The following code examples show you how to perform actions and implement common scenarios by using the AWS Command Line Interface with AWS 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.
- AWS CLI
-
To create an AWS Cloud9 EC2 development environment
The following
create-environment-ec2example creates an AWS 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 \ --namemy-demo-env\ --description"My demonstration development environment."\ --instance-typet2.micro\ --image-idamazonlinux-2023-x86_64\ --subnet-idsubnet-1fab8aEX\ --automatic-stop-time-minutes60\ --owner-arnarn:aws:iam::123456789012:user/MyDemoUserOutput:
{ "environmentId": "8a34f51ce1e04a08882f1e811bd706EX" }For more information, see Creating an EC2 Environment
in the AWS Cloud9 User Guide. -
For API details, see CreateEnvironmentEc2
in AWS CLI Command Reference.
-
The following code example shows how to use create-environment-membership.
- AWS CLI
-
To add an environment member to an AWS Cloud9 development environment
The following
create-environment-membershipexample adds the specified environment member to the specified AWS Cloud9 development environment.aws cloud9 create-environment-membership \ --environment-id8a34f51ce1e04a08882f1e811bd706EX\ --user-arnarn:aws:iam::123456789012:user/AnotherDemoUser\ --permissionsread-writeOutput:
{ "membership": { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJ3LOROMOUXTBSU6EX", "userArn": "arn:aws:iam::123456789012:user/AnotherDemoUser", "permissions": "read-write" } }For more information, see Working with shared environment in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see CreateEnvironmentMembership
in AWS CLI Command Reference.
-
The following code example shows how to use delete-environment-membership.
- AWS CLI
-
To delete an environment member from an AWS Cloud9 development environment
The following
delete-environment-membershipexample deletes the specified environment member from the specified AWS Cloud9 development environment.aws cloud9 delete-environment-membership \ --environment-id8a34f51ce1e04a08882f1e811bd706EX\ --user-arnarn:aws:iam::123456789012:user/AnotherDemoUserThis command produces no output.
For more information, see Remove another environment member
in the AWS Cloud9 User Guide. -
For API details, see DeleteEnvironmentMembership
in AWS CLI Command Reference.
-
The following code example shows how to use delete-environment.
- AWS CLI
-
To delete an AWS Cloud9 development environment
The following
delete-environmentexample deletes the specified AWS Cloud9 development environment. If an Amazon EC2 instance is connected to the environment, this example also terminates the instance.aws cloud9 delete-environment \ --environment-id8a34f51ce1e04a08882f1e811bd706EXThis command produces no output.
For more information, see Deleting an environment in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see DeleteEnvironment
in AWS CLI Command Reference.
-
The following code example shows how to use describe-environment-memberships.
- AWS CLI
-
Example 1: To get information about environment members for an AWS Cloud9 development environment
The following
describe-environment-membershipsexample gets information about environment members for the specified AWS Cloud9 development environment.aws cloud9 describe-environment-memberships \ --environment-id8a34f51ce1e04a08882f1e811bd706EXOutput:
{ "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" } ] }For more information, see Working with shared environment in AWS Cloud9
in the AWS Cloud9 User Guide. Example 2: To get information about the owner of an AWS Cloud9 development environment
The following
describe-environment-membershipsexample gets information about the owner of the specified AWS Cloud9 development environment.aws cloud9 describe-environment-memberships \ --environment-id8a34f51ce1e04a08882f1e811bd706EX\ --permissionsownerOutput:
{ "memberships": [ { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJNUEDQAQWFELJDLEX", "userArn": "arn:aws:iam::123456789012:user/MyDemoUser", "permissions": "owner" } ] }For more information, see Working with shared environment in AWS Cloud9
in the AWS Cloud9 User Guide. Example 3: To get information about an environment member for multiple AWS Cloud9 development environments
The following
describe-environment-membershipsexample gets information about the specified environment member for multiple AWS Cloud9 development environments.aws cloud9 describe-environment-memberships \ --user-arnarn:aws:iam::123456789012:user/MyDemoUserOutput:
{ "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" } ] }For more information, see Working with shared environment in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see DescribeEnvironmentMemberships
in AWS CLI Command Reference.
-
The following code example shows how to use describe-environment-status.
- AWS CLI
-
To get status information for an AWS Cloud9 development environment
The following
describe-environment-statusexample gets status information for the specified AWS Cloud9 development environment.aws cloud9 describe-environment-status \ --environment-id685f892f431b45c2b28cb69eadcdb0EXOutput:
{ "status": "ready", "message": "Environment is ready to use" }For more information, see Working with environments in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see DescribeEnvironmentStatus
in AWS CLI Command Reference.
-
The following code example shows how to use describe-environments.
- AWS CLI
-
To get information about AWS Cloud9 development environments
The following
describe-environmentsexample gets information about the specified AWS Cloud9 development environments.aws cloud9 describe-environments \ --environment-ids685f892f431b45c2b28cb69eadcdb0EX349c86d4579e4e7298d500ff57a6b2EXOutput:
{ "environments": [ { "id": "685f892f431b45c2b28cb69eadcdb0EX", "name": "my-demo-ec2-env", "description": "Created from CodeStar.", "type": "ec2", "arn": "arn:aws:cloud9:us-west-2: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-west-2:123456789012:environment:349c86d4579e4e7298d500ff57a6b2EX", "ownerArn": "arn:aws:iam::123456789012:user/MyDemoUser", "lifecycle": { "status": "CREATED" } } ] }For more information, see Working with environments in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see DescribeEnvironments
in AWS CLI Command Reference.
-
The following code example shows how to use list-environments.
- AWS CLI
-
To get a list of available AWS Cloud9 development environment identifiers
The following
list-environmentsexample gets a list of available AWS Cloud9 development environment identifiers.aws cloud9 list-environmentsOutput:
{ "environmentIds": [ "685f892f431b45c2b28cb69eadcdb0EX", "1980b80e5f584920801c09086667f0EX" ] }For more information, see Working with environments in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see ListEnvironments
in AWS CLI Command Reference.
-
The following code example shows how to use update-environment-membership.
- AWS CLI
-
To change the settings of an existing environment member for an AWS Cloud9 development environment
The following
update-environment-membershipexample changes the settings of the specified existing environment member for the specified AWS Cloud9 development environment.aws cloud9 update-environment-membership \ --environment-id8a34f51ce1e04a08882f1e811bd706EX\ --user-arnarn:aws:iam::123456789012:user/AnotherDemoUser\ --permissionsread-onlyOutput:
{ "membership": { "environmentId": "8a34f51ce1e04a08882f1e811bd706EX", "userId": "AIDAJ3LOROMOUXTBSU6EX", "userArn": "arn:aws:iam::123456789012:user/AnotherDemoUser", "permissions": "read-only" } }For more information, see Working with shared environment in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see UpdateEnvironmentMembership
in AWS CLI Command Reference.
-
The following code example shows how to use update-environment.
- AWS CLI
-
To change the settings of an existing AWS Cloud9 development environment
The following
update-environmentexample changes the specified settings of the specified existing AWS Cloud9 development environment.aws cloud9 update-environment \ --environment-id8a34f51ce1e04a08882f1e811bd706EX\ --namemy-changed-demo-env\ --description"My changed demonstration development environment."This command produces no output.
For more information, see Changing environment settings in AWS Cloud9
in the AWS Cloud9 User Guide. -
For API details, see UpdateEnvironment
in AWS CLI Command Reference.
-