Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Features of AWS CloudShell
2.1.
AWS Command Line Interface
2.2.
Shells and development tools
2.3.
Persistent storage
2.4.
Security
2.4.1.
Permissions management with IAM
2.4.2.
Shell session management
2.4.3.
Safe Paste for text input
3.
Customization options
4.
Pricing
5.
Getting started with AWS CloudShell
5.1.
Prerequisites
5.1.1.
IAM Permissions
5.1.2.
Exercise File
6.
Steps to use AWS CloudShell
7.
Frequently Asked Questions
7.1.
What is AWS CloudShell?
7.2.
Is the AWS CLI the same as CloudShell?
7.3.
What distinguishes CloudShell from Amazon EC2 Instance Connect?
7.4.
How can we stop AWS CloudShell?
8.
Conclusion
Last Updated: Mar 27, 2024
Easy

AWS Cloudshell

Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

The AWS Management Console provides access to AWS CloudShell, a browser-based shell. Customers may immediately access an Amazon Linux 2 environment with the AWS Command Line Interface (CLI) pre-installed and pre-authenticated using the same credentials used to get into the Management Console by establishing a CloudShell session after logging into the console. CloudShell makes it simple to securely manage, interact with, and explore your resources from the command line. Standard tools, including AWS CLIs, are pre-installed, and root access allows you to install additional tools as needed. Bash, zsh, and PowerShell are all provided, so you may use whatever shell you choose.

AWS CloudShell may be launched with a single click from any supported AWS Region. Up to 1GB of data may be uploaded and downloaded to your CloudShell home directory ($HOME), and files, scripts, and tools saved there will persist across sessions. Per Region, CloudShell comes with 1 GB of persistent storage. Go to the top of any console page that shows when you're in a compatible Region and click the CloudShell symbol link.

AWS CloudShell comes at no additional cost. We only pay for other AWS resources that CloudShell uses to build and execute your apps. At launch, AWS CloudShell is accessible in the following regions: us-east-1 (North Carolina), us-east-2 (Ohio), us-west-2 (Oregon), ap-northeast-1 (Tokyo), and eu-west-1 (Ireland). The AWS CloudShell User Guide can help you learn more about CloudShell.

Source: https://docs.aws.amazon.com/cloudshell/latest/userguide/images/cloudshell-welcome.png

Features of AWS CloudShell

Following are the key features of AWS cloudshell:

AWS Command Line Interface

The AWS credentials you used to sign in to the console are instantly accessible in a new shell session when running AWS CloudShell from the AWS Management Console. This pre-authentication of AWS CloudShell users allows you to communicate with AWS services using AWS CLI version 2 (pre-installed on the shell's compute environment) without having to configure credentials.

Shells and development tools

We may smoothly transition between our favorite command-line shells using the shell generated for AWS CloudShell sessions. For example, we may switch between Bash, PowerShell, and Z shell. We can also use pre-installed utilities and tools like git, build, pip, sudo, tar, tmux, vim, wget, and zip.

The shell environment comes pre-configured with support for popular programming languages, allowing you to execute Node.js and Python applications without needing to install runtime libraries. The .NET Core runtime is available to PowerShell users.

A local repository can be used to commit files generated in or uploaded to AWS CloudShell before being submitted to a remote repository managed by AWS CodeCommit.

Persistent storage

When using AWS CloudShell, you get 1 GB of free persistent storage for each AWS Region. The persistent storage is private to us and is located in your home directory ($HOME). Data in our home directory remains between shell sessions, unlike ephemeral environment resources that are refreshed after each shell session.

Security

Specific security features, such as IAM rights management, shell session limitations, and Safe Paste for text input secure the AWS CloudShell environment and its users.

Permissions management with IAM

IAM policies allow administrators to give and restrict rights to AWS CloudShell users. Administrators can also define policies that specify the specific operations that users can execute with the shell environment at a granular level.

Shell session management

Long-running and inactive sessions are automatically terminated and recycled.

Safe Paste for text input

Safe Paste is a security feature that prompts you to check that the multiline text you will paste into the shell doesn't include harmful scripts. It's enabled by default.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Customization options

Change screen layouts (many tabs), font sizes, and light/dark interface styles to personalize your AWS CloudShell experience. Installing your software and altering start-up shell scripts are other ways to customize your shell environment.

Pricing

AWS CloudShell is a free service provided by Amazon Web Services. Any additional AWS resources that you use using AWS CloudShell are your responsibility. Data transmission speeds are also standard.

Getting started with AWS CloudShell

This section demonstrates how to use the shell command-line interface to run AWS CloudShell and conduct essential operations.

Prerequisites

Here are some prerequisites that we must have before moving to a real task

IAM Permissions

Attaching the following AWS managed policy to your IAM identity (user, role, or group) is the easiest method to get rights for AWS CloudShell:

  • AWSCloudShellFullAccess: Gives customers complete control over AWS CloudShell and related features.

We'll also use AWS services in this lesson (in this case, creating an Amazon S3 bucket and adding an object to it.) As a result, our IAM identity requires a policy that authorizes the s3:CreateBucket and s3:PutObject capabilities at a minimum.

Exercise File

This exercise also requires us to upload and change a file, which is then launched as a program via the command-line interface. Add the following code snippet to a text editor on your local machine:

import sys
a=int(sys.argv[1])
b=int(sys.argv[2])
s=a+b
print("The resultant sum is",s)

 

Add the name add_prog.py to the file.

Steps to use AWS CloudShell

Step 1: To use the AWS Management Console, we must first input your IAM user details. Skip to step 2 if you're already in the console.

You may access the AWS Management Console using an IAM user sign-in URL or the primary sign-in page.

Source: https://miro.medium.com/max/678/0*LCqeNplaDHvn2oSu.png

 

Source: https://miro.medium.com/max/662/0*VZaDsSOSvz4sJjXG.png

Step 2: This step involves launching AWS CloudShell from the console, selecting an AWS Region, and switching to your favorite shell (Bash, PowerShell, or Z shell).

You may start AWS CloudShell from the AWS Management Console by selecting one of the options on the navigation bar, i.e., Choose the AWS CloudShell icon or Start putting "cloudshell" into the search box, then choose CloudShell.

               Source: https://docs.aws.amazon.com/cloudshell/latest/userguide/images/launch_options.png

 

To work in an AWS Region, go to the Select a Region menu and choose a supported AWS Region to work in. (Regions that are available are marked.)

At the command line prompt, type the name of the pre-installed shell you want to use.

Step 3: This step demonstrates how to upload a file and then move it to a new directory in your home directory.

To determine your current working directory, type the following command at the prompt:

pwd

 

The shell returns your current working directory when you hit Enter. For instance, /home/cloudshell-user.

  1. Go to Actions and pick Upload file from the menu to add a file to this directory.
  2. Choose Browse.
  3. Select the text file you produced for this lesson (add prog.py) in your system's File upload dialogue box and click Open.
  4. Select Upload from the Upload file dialogue box.

 

The upload is tracked via a progress metre. If the upload is successful, a notice will appear confirming that add_prog.py has been has been placed at the beginning of your home directory

Enter the make directories command: mkdir mysub_dir to create a directory for the file.

Use the mv command to relocate the uploaded file from the root of your home directory to the new directory:

mv add_prog.py mysub_dir.

 

Enter cd mysub_dir to move your working directory to the new directory.
The command prompt changes to reflect that you have changed your working directory.

 

Enter the ls command to see the contents of the current directory, mysub_dir.
The working directory contents are presented, including the file you just uploaded.
 

Step 4: This section shows how to work with a file using the pre-installed Vim editor. The file is then executed as a programme from the command line.

Enter the following command to modify the file you submitted in the previous step:

vim add_prog.py

 

The shell interface updates to show the Vim editor.

 

Press the I key to open the file in Vim. Now change the code so that the program adds three digits instead of two:

import sys
x=int(sys.argv[1])
y=int(sys.argv[2])
z=int(sys.argv[3])
sum=x+y+z
print("The sum is",sum)

After editing the program, hit Esc to enter Vim command mode. Then, to save the file and close the editor, use the following command:

:wq

Return to the main command-line interface and enter three digits as input:

python3 add_prog.py 4 5 6

 

The program output is displayed on the command line: The total is 15.

 

Step 5: In this step, you establish an Amazon S3 bucket and then use the PutObject function to add your code file to that bucket as an object.

Enter the following command to create a bucket in a certain AWS Region:

aws s3api create-bucket --bucket insert-unique-bucket-name-here --region us-east-1                 

 

If the request is completed, the command line shows a response from the service that looks like this:

{
    "Location": "/insert-unique-bucket-name-here"
}   

 

To upload a file and add it as an object to the newly constructed bucket, use the PutObject method:

aws s3api put-object --bucket insert-unique-bucket-name-here --key add_prog --body add_prog.py

 

If the item is successfully uploaded to the Amazon S3 bucket, the command line outputs something like this:

{
           "ETag": "\"ab123c1:w:wad4a567d8bfd9a1234ebeea56\""
}

 

The ETag is a hash of the item that was saved. It may be used to validate the item uploaded to Amazon S3.

Frequently Asked Questions

What is AWS CloudShell?

AWS CloudShell is a browser-based shell that makes it simple to manage, investigate, and interact with your AWS resources safely. CloudShell has already been authenticated using your console credentials. Common Development and operations tools are pre-installed, so there is no need for local installation or configuration.

Is the AWS CLI the same as CloudShell?

Every CloudShell shell environment has the AWS Command Line Interface (CLI) (v2) installed and configured, allowing you to perform aws commands right away. The Python and Node runtimes are also included, with many more to follow in the future.

What distinguishes CloudShell from Amazon EC2 Instance Connect?

Amazon EC2 Instance Connect allows you to connect to existing EC2 instances in your account using a web terminal. CloudShell requires no resources in your account. EC2 Instance Connect is best for connecting to existing EC2 instances through SSH, whereas CloudShell is best for AWS CLI commands and general-purpose scripting.

How can we stop AWS CloudShell?

We can end a shell session and log out from the command line using the exit command. We may then rejoin and continue using AWS CloudShell by pressing any key.

Conclusion

In this article, we have extensively discussed AWS Coudshell. We start with a brief introduction of the AWS Cloudshell, then discuss the steps to use it.

After reading about the AWS Coudshell, are you not feeling excited to read/explore more articles on the topic of AWS? Don't worry; Coding Ninjas has you covered. To learn, see AWS Cloud MapAWS Cloud DirectoryAWS Application Discovery Service, and Data Exchange in AWS, Nmap commands

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc., you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Previous article
AWS Babelfish
Next article
AWS Codeartifact
Live masterclass