Working with AWS services in AWS CloudShell - AWS CloudShell

Working with AWS services in AWS CloudShell

A key benefit of AWS CloudShell is that you can use it to manage your AWS services from the command line interface. This means that you don't need to download and install tools or configure your credentials locally beforehand. When you launch AWS CloudShell, a compute environment is created that has the following AWS command line tools already installed:

And because you’ve already signed into AWS, there's no requirement to configure your credentials locally before using services. The credentials you used to sign in to the AWS Management Console are forwarded to AWS CloudShell.

The rest of this topic demonstrates how you can start using AWS CloudShell to interact with selected AWS services from the command line.

AWS CLI command line examples for selected AWS services

The following examples represent only some of the numerous AWS services that you can work with using commands available from AWS CLI Version 2. For a full listing, see the AWS CLI Command Reference.

DynamoDB

DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. This service's implementation of the NoSQL mode supports key-value and document data structures.

The following create-table command creates a NoSQL-style table that's named MusicCollection in your AWS account.

aws dynamodb create-table \ --table-name MusicCollection \ --attribute-definitions AttributeName=Artist,AttributeType=S AttributeName=SongTitle,AttributeType=S \ --key-schema AttributeName=Artist,KeyType=HASH AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \ --tags Key=Owner,Value=blueTeam

For more information, see Using DynamoDB with the AWS CLI in the AWS Command Line Interface User Guide.

AWS Cloud9

AWS Cloud9 is a cloud-based integrated development environment (IDE) that you can use to write, run, and debug your code in a browser window. The environment features a code editor, debugger, and terminal.

The following create-environment-ec2 command creates an AWS Cloud9 EC2 development environment with the specified settings. It launches an 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 --subnet-id subnet-1fab8aEX --automatic-stop-time-minutes 60 --owner-arn arn:aws:iam::123456789012:user/MyDemoUser

For more information, see AWS Cloud9 command-line reference.

Amazon EC2

Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides secure and resizable compute capacity in the cloud. It's designed to make web-scale cloud computing easier and more accessible.

The following run-instances command launches a t2.micro instance in the specified subnet of a VPC:

aws ec2 run-instances --image-id ami-xxxxxxxx --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-903004f8 --subnet-id subnet-6e7f829e

For more information, see Using Amazon EC2 with the AWS CLI in the AWS Command Line Interface User Guide.

S3 Glacier

S3 Glacier and S3 Glacier Deep Archive are a secure, durable, and extremely low-cost Amazon S3 cloud storage classes for data archiving and long-term backup.

The following create-vault command creates a vault—a container for storing archives:

aws glacier create-vault --vault-name my-vault --account-id -

For more information, see Using Amazon S3 Glacier with the AWS CLI in the AWS Command Line Interface User Guide.

AWS Elastic Beanstalk CLI

The AWS Elastic Beanstalk CLI provides a command line interface made to simplify creating, updating, and monitoring environments from a local repository. In this context, an environment refers to a collection of AWS resources running an application version.

The following create command creates a new environment in a custom Amazon Virtual Private Cloud (VPC).

$ eb create dev-vpc --vpc.id vpc-0ce8dd99 --vpc.elbsubnets subnet-b356d7c6,subnet-02f74b0c --vpc.ec2subnets subnet-0bb7f0cd,subnet-3b6697c1 --vpc.securitygroup sg-70cff265

For more information, see the EB CLI command reference in the AWS Elastic Beanstalk Developer Guide.

Amazon ECS CLI

The Amazon Elastic Container Service (Amazon ECS) command line interface (CLI) provides several high-level commands. These are designed to simplify the processes of creating, updating, and monitoring clusters and tasks from a local development environment. (An Amazon ECS cluster is a logical grouping of tasks or services.)

The following configure command configures the Amazon ECS CLI to create a cluster configuration named ecs-cli-demo. This cluster configuration uses FARGATE as the default launch type for the ecs-cli-demo cluster in the us-east-1 region.

ecs-cli configure --region us-east-1 --cluster ecs-cli-demo --default-launch-type FARGATE --config-name ecs-cli-demo

For more information, see the Amazon ECS Command Line Reference in the Amazon Elastic Container Service Developer Guide.

AWS SAM CLI

AWS SAM CLI is a command line tool that operates on an AWS Serverless Application Model template and application code. You can perform several tasks using it. These include invoking Lambda functions locally, creating a deployment package for your serverless application, and deploying your serverless application to the AWS Cloud.

The following init command initializes a new SAM project with required parameters passed as parameters:

sam init --runtime python3.7 --dependency-manager pip --app-template hello-world --name sam-app

For more information, see the AWS SAM CLI command reference in the AWS Serverless Application Model Developer Guide.