Menu
AWS Cloud9
User Guide

AWS Command Line Interface Sample for AWS Cloud9

This sample enables you to set up the AWS Command Line Interface (AWS CLI) in an AWS Cloud9 development environment. The AWS CLI is a unified tool that provides a consistent interface for interacting with all parts of AWS. You can use the AWS CLI instead of the AWS Management Console to quickly run commands to interact with AWS, and some of these commands can only be run with the AWS CLI.

For more information about the AWS CLI, see the AWS CLI User Guide.

For a list of commands you can run to interact with AWS, see the AWS CLI Reference.

Note

This sample assumes you already have the AWS Cloud9 IDE for your AWS Cloud9 development environment open in your web browser, and that you're using an AWS Cloud9 EC2 development environment that is connected to an Amazon EC2 instance running Amazon Linux. In you're using a different operating system or using an AWS Cloud9 SSH development environment, you might need to adapt this sample's instructions to correctly install and configure this sample's required tools. To create an environment, see Creating an Environment.

When you're using this sample, be sure you're signed in to AWS with the AWS account ID and name and password of the user you created or identified in Team Setup.

Creating this sample may result in charges to your AWS account. These include possible charges for services such as Amazon EC2 and Amazon S3. For more information, see Amazon EC2 Pricing and Amazon S3 Pricing.

Step 1: Install the AWS CLI in Your Environment

In this step, you use the AWS Cloud9 IDE to install the AWS CLI in your environment so you can run commands to interact with AWS.

If you are using an AWS Cloud9 EC2 development environment, you can skip ahead to Step 3: Run Some Basic Commands with the AWS CLI in Your Environment. This is because the AWS CLI is already installed in an EC2 environment, and a set of AWS access credentials is already set up in the environment. For more information, see AWS Managed Temporary Credentials.

If you are not using an EC2 environment, do the following to install the AWS CLI:

  1. With your environment open, in the IDE, check whether the AWS CLI is already installed. In the terminal, run the aws --version command. (To start a new terminal session, on the menu bar, choose Window, New Terminal.) If the AWS CLI is installed, the version number is displayed, with information such as the version numbers of Python and the operating system version number of your Amazon EC2 instance or your own server. For example, aws-cli N.NN.NN Python/N.N.NN OS/VERSION . If the AWS CLI is installed, skip ahead to Step 2: Set up Credentials Management in Your Environment.

  2. To install the AWS CLI, see Installing the AWS Command Line Interface in the AWS CLI User Guide. For example, for an EC2 environment running Amazon Linux, run these three commands, one at a time, in the terminal to install the AWS CLI.

    Copy
    sudo yum -y update # Install the latest system updates. sudo yum -y install aws-cli # Install the AWS CLI. aws --version # Confirm the AWS CLI was installed.

Step 2: Set up Credentials Management in Your Environment

Each time you use the AWS CLI to call an AWS service, you must provide a set of credentials with the call. These credentials determine whether the AWS CLI has the appropriate permissions to make that call. If the credentials don't cover the appropriate permissions, the call will fail.

If you are using an AWS Cloud9 EC2 development environment, you can skip ahead to Step 3: Run Some Basic Commands with the AWS CLI in Your Environment. This is because credentials are already set up in an EC2 environment. For more information, see AWS Managed Temporary Credentials.

If you are not using an EC2 environment, you must manually store your credentials within the environment. To do this, follow the instructions in Calling AWS Services from an Environment in AWS Cloud9, and then return to this topic.

Step 3: Run Some Basic Commands with the AWS CLI in Your Environment

In this step, you use the AWS CLI in your environment to create a bucket in Amazon S3, list your available buckets, and then delete the bucket.

  1. Create a bucket. Run the aws s3 mb command, supplying the name of the bucket to create. In this example, we use a bucket named s3://cloud9-ACCOUNT-ID-bucket, where ACCOUNT-ID is your AWS account ID. If you use a different name, substitute it throughout this step.

    Copy
    aws s3 mb s3://cloud9-ACCOUNT-ID-bucket

    Note

    Bucket names must be unique across all of AWS, not just your AWS account. The preceding suggested bucket name can help you come up with a unique bucket name. If you get a message that contains the error BucketAlreadyExists, you must run the command again with a different bucket name.

  2. List your available buckets. Run the aws s3 ls command. A list of your available buckets is displayed.

  3. Delete the bucket. Run the aws s3 rb command, supplying the name of the bucket to delete.

    Copy
    aws s3 rb s3://cloud9-ACCOUNT-ID-bucket

    To confirm whether the bucket was deleted, run the aws s3 ls command again. The name of the bucket that was deleted should no longer appear in the list.

    Note

    You don't have to delete the bucket if you want to keep using it. For more information, see Add an Object to a Bucket in the Amazon S3 Getting Started Guide. See also s3 commands in the AWS CLI Reference. (Remember, if you don't delete the bucket, it may result in ongoing charges to your AWS account.)

To continue experimenting with the AWS CLI, see Working with Amazon Web Services in the AWS CLI User Guide. See also the AWS CLI Reference.

Step 4: Clean Up

To prevent ongoing charges to your AWS account after you're done using this sample, you should delete the environment. For instructions, see Deleting an Environment.