Important Note: You will create AWS resources during the exercise which will incur cost in your AWS account. It is recommended to clean-up the resources as soon as you finish the exercise to minimize the cost.

Configure AWS Cloud9 for Python Boto3 SDK Programming

AWS Cloud9 is a cloud-based integrated development environment (IDE) from Amazon Web Services. The Cloud9 IDE provides the software and tooling needed for dynamic programming with 40 languages including JavaScript, Python, PHP, Ruby, Go, and C++. You learn about configuring the IDE to be able to develop programming with the AWS Services using AWS SDK for Python Boto3.

Step1: Pre-Requisite


You need to have an AWS account with administrative access to complete the exercise. If you don’t have an AWS account, kindly use the link to create free trial account for AWS.

Step2: Launch Cloud9 Environment


You will launch AWS Cloud9 environment. When you launch an environment, it starts an Amazon EC2 instance in the background and uses it with AWS Cloud9 IDE as the development machine.

  1. Login to the AWS Console. Select an AWS Region of your choice where AWS Cloud9 is available. You will see the exercise using the Paris region.

  2. Goto the AWS Cloud9 console and click on the Create environment button.

    Cloud9

  3. On the next screen, enter dojoenvironment as the name and click on the Next step button.

    Cloud9

  4. On the next screen, select Environment type as Create a new instance for environment (EC2). Select Instance type as t3.small (2 GiB RAM + 2 vCPU). Select Ubuntu Server 18.04 LTS for the Platform. The development environment will have Ubuntu as the operating system. Keep rest of the fields with the default values and click on the Next step button.

    Cloud9

  5. On the next screen, click on the Create environment button.

  6. It will take couple of minutes to create the environment. Wait for the environment to be ready. Once it is ready, you can see console window in the bottom part of the screen. It provides console base access to the development machine.

  7. You will now configure the environment for the Python Boto3 SDK. Run the following command in the console to update the environment.

     sudo apt-get update
    

    ` Cloud9

  8. Python3 is already installed in the environment. You can check it by running the command bellow in the console.

     python3 --version
    

    ` Cloud9

  9. AWS SDK for Python Boto3 is not installed in the environment. Run the following command to install Boto3 package in the environment. When it asks for the confirmation; you can type in Y and enter.

     sudo apt install python-boto3
    

    ` Cloud9

  10. The Cloud9 environment is ready for the Python programming with AWS SDK Boto3. Let’s test it.

Step3: Create Test Python File


You will create a sample python file test.py which simply creates an Amazon S3 bucket to test the SDK.

  1. In AWS Cloud9 IDE, Click on the New File option under the File menu to create a new file.

    Cloud9

  2. It creates a new Untitled1 file. Copy-paste the following code in the file. When you run the program and it gives error for the bucket name not available; you should change the code and use a bucket name which is available in the line 3 of the code. Similarly, if you are using a region other than Paris then update the region code in the line 3.

     import boto3
     s3 = boto3.client('s3')
     s3.create_bucket(Bucket='aws-dojo-cloud9-bucket',CreateBucketConfiguration={'LocationConstraint': 'eu-west-3'})
     print('The bucket is created')
    

    `

    Cloud9

  3. In AWS Cloud9 IDE, Click on the Save option under the File menu to save the file. In the popup, enter the file name as test.py and click the Save button.

    Cloud9

  4. In order to run the file, click on Python 3 option in the menu Run > Run With.

    Cloud9

  5. The file with the python code will execute. As per code logic, the bucket is created and you can also see the success message in the console.

    Cloud9

  6. Similarly, you can write Python code with Boto3 SDK for other AWS Services as well. Congratulations, it finishes the exercise. Please follow the next steps to clean the AWS account so that you don’t incur any further cost.

Step4: Clean up


Goto the AWS Cloud9 console and delete dojoenvironment environment.

Goto the AWS S3 console and delete the aws-dojo-cloud9-bucket bucket. If you create bucket with a different name, then delete that one.

Thanks and hope you enjoyed the exercise.


Back to the Exercises