DEV Community

Revathi Joshi for AWS Community Builders

Posted on

A small but informative article on Cloudshell

As I was exploring AWS new services, I found this new feature - Cloudshell. In this article I am going to show you how CloudShell works.

What is CloudShell?

  • AWS CloudShell is a browser-based shell that you can interact with your AWS services with your own credentials.

  • It can be launched from the AWS Management Console.

  • No need to install any software or patches.

  • It runs on Amazon Linux 2 and you can run scripts with the AWS Command Line Interfaces, including AWS CLI, Amazon ECS CLI, AWS SAM CLI and AWS SDKs for Python and Node.js.

  • Other commonly used command line utilities for shells (Bash, PowerShell, Zsh), editors (vi), source control (Git), and package management (npm, pip) are also installed.

  • You can upload or download files upto 1 GB to your $HOME (home directory) on your CloudShell instance through your browser from your local machine.

  • It has persistent storage of 1 GB for each AWS Region at no additional cost.

Most importantly, Unlike Cloud9, you are billed for the EC2 instance that runs on your Cloud9 environment, AWS CloudShell is free of charge. You pay for any AWS resources that you use with AWS CloudShell.

Only drawback is, you cannot currently access resources that are in your private VPC in this release of CloudShell.

Please visit my GitHub Repository for CloudShell articles on various topics being updated on constant basis.

Let’s get started!

Pre-requisites:

  • AWS user account with admin access, not a root account.

Objectives:

1: Sign in to AWS Management Console

2: Launch AWS CloudShell, select a Region, and choose a shell.

3. Create a test file - welcome.py to upload into CloudShell environment

4: Upload file welcome.py to AWS CloudShell

5: Edit your file's code and run it from the command line

6: Use AWS CLI to add the file as an object in an Amazon S3 bucket.

Resources Used:

CloudShell Documentation

AWS S3 CLI

Steps for implementation to this project:

1. Sign in to AWS Management Console

Account ID (12 digits) or account alias: Enter your Account ID (12 digits) or account alias

IAM user name: Your user name

Password: your password

Sign in

Image description

2. Launch AWS CloudShell environment, select a Region, and choose a shell.

To check if your AWS CloudShell is available in your region, look for a shell icon in the top bar. Check out the image below.

Image description

If you can't find the icon, it means AWS cloudShell is not available in that region yet.

You can find any AWS service in US East (N. Virginia). Click here to access the shell.

3. Create a test file welcome.py to upload into CloudShell environment

  • Open a text editor, like notepad on your local machine and add the following code:
# The function will accept a single argument called “name.” 
# If the provided name is infact the name of the user interacting, 
# and if the user answers "yes", then the program prints a greeting message.
# Otherwise, it will ask the user to enter the name again, 
# and the program will ask the user to enter his/her "provided name"

def checkName(name):
    answer = input("Is your name " + name + "? ") 

    if answer.lower() == "yes": # lower() turns the answer into lowercase   
        print("Hello,", name)  
    else:    
        new_name = input("We're sorry about that. What is your name again? ")    
        print("Welcome,", new_name, "to CloudShell!")

checkName("Revathi")
Enter fullscreen mode Exit fullscreen mode
  • Save the file and name it as welcome.py

4. Upload file welcome.py to AWS CloudShell

Actions / Upload file / Choose Browse / select the text file welcome.py that you created just now /

choose Open

  • If the upload is successful, a message shows up on the right side of the screen, that welcome.py was added to the root of your home directory - /home/clodshell-user.

    • Check to see you are in the $HOME home directory.
    • Make a sub-directory 120722
    • Change to the sub-directory
    • move the file welcome.py to your sub-directory
    • List the file

pwd

mkdir 120722

cd 120722

mv ../welcome.py .

ls

Image description

5. Edit your file's code and run it from the command line

  • Edit your file's code

  • press i to insert a new line into the code snippet

  • Enter a new line at the end of your code

  • press escape out of insert mode

  • Save the file welcome.py

  • Run the program

vi welcome.py
i
print("Start working on your CloudShell environment!")
Esc
:wq
python3 welcome.py

Image description

6. Use AWS CLI to add the file as an object in an Amazon S3 bucket.

  • Create a S3 bucket - rev123456 in a us-east-1 AWS Region, enter the following command:

  • If successfull, you will see this message

  • call the PutObject method to upload your file welcome.py

  • If the upload is successfull, you will see this message

  • List the file welcome.py from the S3 bucket - rev123456

aws s3api create-bucket --bucket rev123456 --region us-east-1

aws s3api put-object --bucket rev123456 --key welcome --body welcome.py

aws s3 ls s3://rev123456

Image description

Cleanup

  • Delete the file welcome.py from your bucket

  • Check to see if the file is deleted

  • Delete the bucket rev123456

  • Ckeck to see if the bucket is deleted

  • Delete the file welcome.py from the CloudShell environment

  • Ckeck to see if the file is deleted from CloudShell environment

  • Go back to the root $Home home directory

  • Remove the sub-directory - 120722

  • Finally, exit out of CloudShell environment

aws s3 rm s3://rev123456/welcome.py

aws s3 ls s3::/rev123456

aws s3api delete-bucket --bucket rev123456 --region us-east-1

aws s3api list-buckets --query "Buckets[].Name"

rm welcome.py

ls

cd ../

rmdir 120722

exit

Image description

What we have done so far

We have successfully launched AWS CloudShell, created a sub-directory 120722, created a test file welcome.py, changed the contents of the file, ran the file to see the output, created a S3 bucket rev123456, moved the file into S3 bucket.

Finally, deleted the test file - welcome.py, S3 bucket rev123456, and sub-directory 120722 from the CloudShell environment and exited out of it.

Top comments (0)