Stelligent

Automating AWS Cloud9

AWSCloud9_logo_color_400x400
AWS Cloud9 is a cloud-based Integrated Development Environment (IDE) for writing, running, and debugging code. With Cloud9, you can code with only your web browser. No need to download software, configure your environments, or setup your IDE and its configuration on each of your computers. You can collaborate in the same environment with other developers while seeing each of your changes in real time – raising the bar wen it comes to pair programming and code reviews.
In this blog post, you’ll learn the problems that Cloud9 helps solve along with its benefits. You’ll also learn how to configure a Cloud9 environment using the console and how to automate the provisioning of Cloud9 environments using AWS CloudFormation.

The Problems with Local Machines

We’ve been developing solutions on AWS for almost a decade at Stelligent. I’ve always found the irony in writing code on my local machine – with its idiosyncratic configurations – and then deploying that same code to the AWS platform with its different configurations. In fact, much of the purpose of Continuous Integration (CI) is to identify those things that “work on my machine” but do not work in downstream environments on their way to production. From my early days in software development, I’ve always thought that assumptions are the bane of effective programming.
In fact, in an effort to reduce assumptions, and prior to Cloud9, I’d often use vim on a newly launched EC2 instance just to ensure I knew how it might work on someone else’s machine who doesn’t have the same local machine configuration as me. Even though I’ve used vi for years, I don’t really consider myself a relative expert, so it wasn’t necessarily preferable to operate this way but I also didn’t want to turn work over to others that didn’t consider the impact of dependencies and local machine configurations.
When each engineer is developing locally, it also makes it difficult to share work in real time. This is particularly relevant for distributed teams. Sure, you can you screen share but you cannot give others access to that code in real time – unless you hand the control over to your computer control to others. To say the least, this is not convenient nor desirable. Looking over each other’s screens does not scale well.
Being able to switch between devices is also a challenge. For instance, let’s say you’re working on your machine at work and want to switch to another machine while at home or traveling. Usually, this means you have to keep your IDE configurations in sync or accept the differences between the configuration of each of your machines.
Also, at the time of this writing, most IDEs don’t have much if any support for Serverless applications that integrate services such as Lambda and API Gateway into the IDE.
In short, most IDEs make it difficult to get to the point of doing what you really want to be doing: writing code, collaborating with others, and getting feedback from customers.  

Features and Benefits of Using Cloud9

With AWS Cloud9, you can simply launch an IDE from your web browser and get started quickly. Here are some of the features of Cloud9:

Cloud9 is a fully-functioning IDE you can run in your web browser enabling you to collaborate with other programmers in real time, eliminate dependencies on local configurations, and leverage AWS’ network throughput to rapidly focus on developing software

From the perspective of reducing the waiting and speeding up feedback loops, there are a couple of key benefits to Cloud9. The first is the real-time collaboration in being up to work with other developers in real time on the same code. The fact that most tools are already installed and configured (e.g. git and the AWS CLI) saves a lot of time and you can go from computer to computer and access your same environments and settings. All of this saves lots of unnecessary time and allows developers to focus on developing features for customers. In less than one minute, it launches your environment and you can immediately start writing code. 
Cloud9 comes integrated with the SAM Local CLI to support local development with AWS Lambda. It also supports integration with Lambda and running and debugging these functions in your IDE.
There is AWS CodeStar integration in Cloud9. With AWS CodeStar, you can set up your entire continuous delivery toolchain in minutes, allowing you to start releasing code faster.

Manually Setup a Cloud9 Environment

Here are the steps to manually configuring your AWS Cloud9 environment:

  1. Go to the AWS Cloud9 console and select Create environment
  2. Enter a Name and Description
  3. Select Next step
  4. Select Create a new instance for environment (EC2)
  5. Select t2.micro
  6. Leave the Cost-saving setting at the After 30-minute (default) option
  7. Select Next step
  8. Review best practices and select Create environment

After clicking the Create environment button, it usually takes less than a minute to launch your Cloud9 environment. You can use this environment for only you or have other team members access the environment. By using the same environment with others on your team, you can collaborate with one or more engineers on the same code using the same settings much the way you might do with something like Google Docs.
You can also modify IDE configurations such as custom key bindings, themes, AWS settings, user settings, and project settings.
You can access the terminal, individual files, and use built-in integrations to deploy and test your applications and services – all from within your Cloud9 IDE.

Create a CloudFormation Template

Now that you’ve manually created a Cloud9 environment using the AWS Console, here are the steps to automating the provisioning of your Cloud9 environment:

Parameters:
  EC2InstanceType:
    Default: t2.micro
    Description: EC2 instance type on which IDE runs
    Type: String
  AutoHibernateTimeout:
    Default: 30
    Description: How many minutes idle before shutting down the IDE
    Type: Number
  SubnetIdentifier:
    Description: SubnetId
    Type: AWS::EC2::Subnet::Id
Resources:
  IDE:
    Type: AWS::Cloud9::EnvironmentEC2
    Properties:
      Repositories:
      - RepositoryUrl: https://github.com/stelligent/mu-cloud9.git
        PathComponent: github.com/stelligent/mu-cloud9
      Description: Cloud9 IDE
      AutomaticStopTimeMinutes:
        Ref: AutoHibernateTimeout
      SubnetId:
        Ref: SubnetIdentifier
      InstanceType:
        Ref: EC2InstanceType
      Name:
        Ref: AWS::StackName

Deployment Steps

There are three main steps in launching this solution: preparing an AWS account, launching the stack, and testing the deployment. Each is described in more detail in this section.

Step 1. Prepare an AWS Account

  1. If you don’t already have an AWS account, create one at http://aws.amazon.com by following the on-screen instructions. Part of the sign-up process involves receiving a phone call and entering a PIN using the phone keypad. Be sure you’ve signed up for the CloudFormation service.
  2. Use the region selector in the navigation bar of the console to choose the Northern Virginia (us-east-1) region

Step 2. Launch the Stack

Click on the Launch Stack button below to launch the CloudFormation stack. Before you launch the stack, review the architecture, configuration, security, and other considerations discussed in this post. To download the template, click here.
Time to deploy: Approximately 2 minutes

You’ll go through a few screens as part of launching the stack. Once you see the CloudFormation Stack details, you’ll see a screen similar to the one below.

On this screen, there are four parameter values you may enter:

At the conclusion of this process, you’ll see a Create stack button which you will click to launch the Cloud9 environment.

Create Details

Here’s a listing of the key AWS resources that are created when this stack is launched:

The Cloud9 environment is configured on an EC2 instance within a subnet of a VPC.

Step 3. Test the Deployment

Once the primary CloudFormation stack has been launched, click on the Cloud9URL Output in your CloudFormation stack. Your newly provisioned Cloud9 environment will launch within your web browser. You may begin using the IDE.

Pricing

For Cloud9, AWS charges you for the EC2 instance the EBS storage. Since you can choose different EC2 instance types and the amount of time you use Cloud9 may vary, prices are variable Fortunately, AWS provides a typical example pricing chart on the the AWS Cloud9 Pricing page.
If you’re using the default settings running an IDE for 4 hours a day for 20 days a month with the auto-hibernate set to 30 minutes, you’re monthly charges for 90 hours of usage would be: $1.85 (this is for the compute and storage fees).

Additional Resources

Stelligent Amazon Pollycast