Creating an EC2 Environment - AWS Cloud9

Creating an EC2 Environment

In this procedure, AWS Cloud9 creates an EC2 environment and a new Amazon EC2 instance, and connects the environment to this instance. AWS Cloud9 manages the lifecycle of this instance, including starting, stopping, and restarting the instance as needed. If you ever delete this environment, AWS Cloud9 automatically terminates this instance.

You can create an AWS Cloud9 EC2 development environment in the AWS Cloud9 console or with code.

Note

Completing this procedure might result in charges to your AWS account. This includes possible charges for Amazon EC2. For more information, see Amazon EC2 Pricing.

Warning

A compatibility issue exists with AWS Cloud9 and the AWS Control Tower proactive control CT.EC2.PR.8. If this control is enabled, you cannot create an EC2 environment in AWS Cloud9. For more information on this issue, see Troubleshooting AWS Cloud9.

Prerequisites

Complete the steps in Setting up AWS Cloud9 so that you can sign in to the AWS Cloud9 console and create environments.

Create an EC2 environment with the console

  1. Sign in to the AWS Cloud9 console:

    • If you're the only one that using your AWS account or you're an IAM user in a single AWS account, go to https://console.aws.amazon.com/cloud9/.

    • If your organization uses AWS IAM Identity Center, ask your AWS account administrator for sign-in instructions.

    • If you're a student in a classroom, ask your instructor for sign-in instructions.

  2. After you sign in to the AWS Cloud9 console, in the top navigation bar choose an AWS Region to create the environment in. For a list of available AWS Regions, see AWS Cloud9 in the AWS General Reference.

    
                AWS Region selector in the AWS Cloud9 console
  3. Choose the large Create environment button in one of the locations shown.

    If you don't already have AWS Cloud9 environments, the button is shown on a welcome page.

    
                Welcome page in the AWS Cloud9 console

    If you already have AWS Cloud9 environments, the button is shown as follows.

    
                Create environment button in the AWS Cloud9 console
  4. On the Create environment page, for Name, enter a name for your environment.

  5. To add a description to your environment, enter it in the Description field.

  6. For Environment type, choose New EC2 instance to create an Amazon EC2 environment:

    • Existing compute – Launches an existing Amazon EC2 instance that requires SSH login details for which the Amazon EC2 instance must have an inbound security group rule.

      • If you select the Existing compute option, a service role is automatically created. You can view the name of the service role in a note at the bottom of the setup screen.

    Note

    Automatic shutdown will not be available for AWS Cloud9 environments created using an Amazon EC2 instance using existing compute.

    Warning

    Creating an Amazon EC2 instance for your environment might result in possible charges to your AWS account for Amazon EC2. There's no additional cost to use Systems Manager to manage connections to your EC2 instance.

  7. For Instance type, choose an instance type with the amount of RAM and vCPUs that you think you need for the kinds of tasks that you want to do.

    Warning

    Choosing instance types with more RAM and vCPUs might result in additional charges to your AWS account for Amazon EC2. For information on which instance type is suitable for your workload, see the Amazon EC2 Instance Type page.

  8. For Platform, choose the type of Amazon EC2 instance that you want: Amazon Linux 2023, Amazon Linux 2 or Ubuntu 22.04 LTS. AWS Cloud9 creates the instance and then connects the environment to it.

    Important

    We recommend that you choose the Amazon Linux 2023 option for your EC2 environment. In addition to providing a secure, stable, and high-performance runtime environment, Amazon Linux 2023 AMI includes long-term support through 2024.

    For more information, see the AL2023 page.

  9. Choose a time period for Timeout. This option determines how long AWS Cloud9 is inactive before auto-hibernating. When all web browser instances that are connected to the IDE for the environment are closed, AWS Cloud9 waits the amount of time specified and then shuts down the Amazon EC2 instance for the environment.

    Warning

    Choosing a longer time period might result in more charges to your AWS account.

  10. On the Network settings panel, choose how your environment is accessed from the two following options:

    • AWS Systems Manager (SSM) – This method accesses the environment using SSM without opening inbound ports.

    • Secure Shell (SSH) – This method accesses the environment using SSH and requires open inbound ports.

  11. Choose VPC Settings to display the Amazon Virtual Private Cloud and Subnet for your environment. AWS Cloud9 uses Amazon Virtual Private Cloud (Amazon VPC) to communicate with the newly created Amazon EC2 instance. For this tutorial, we recommend that you don't change the preselected default settings. With the default settings, AWS Cloud9 attempts to use the default VPC with its single subnet in the same AWS account and Region as the new environment. Depending on how Amazon VPC is set up, follow one of the following set of instructions.

    If you're not sure what to choose, we recommend that you skip ahead to the next step in this procedure.

    If you skip past Network settings (advanced) and leave the preselected default settings, AWS Cloud9 attempts to use the default VPC with its single subnet. AWS Cloud9 chooses the subnet based on the instance-type that you selected. These are in the same AWS account and AWS Region as the new environment.

    Important

    If you selected Existing compute as your environment type, you can launch your instance into a public or private subnet.

    • Public subnet: Attach an internet gateway to the subnet to allow the instance SSM agent to communicate with Systems Manager.

    • Private subnet: Create a NAT gateway to enable the instance to communicate with the internet and other AWS services.

    Currently, you can't use AWS managed temporary credentials to allow the EC2 environment to access an AWS service on behalf of an AWS entity, such as an IAM user.

    For more information about configuring subnets, see VPC settings for AWS Cloud9 Development Environments.

    Does the AWS account have access to an Amazon VPC? Is that VPC in the same AWS account and Region as the new environment? Is that VPC the default VPC for its AWS account? Does that VPC contain a single subnet? Follow these instructions

    No

    If no VPC exists, create one.

    To create a VPC in the same AWS account and Region as the new environment, choose Create new VPC, and then follow the on-screen directions. For more information, see Create a VPC plus other VPC resources.

    To create a VPC in a different AWS account than the new environment, see Working with Shared VPCs in the Amazon VPC User Guide.

    Yes

    Yes

    Yes

    Yes

    Skip ahead to the next step in this procedure.

    When you skip Network settings (advanced) and don't change the preselected default settings, AWS Cloud9 attempts to use the default VPC with its single subnet in the same account and Region as the new environment.

    Yes

    Yes

    Yes

    No

    If the default VPC has multiple subnets, expand Network settings (advanced). For Subnet, choose the subnet that you want AWS Cloud9 to use in the preselected default VPC.

    If the default VPC has no subnets, create one. To do this, choose Create new subnet, and then follow the on-screen directions. For more information, see Create a subnet for AWS Cloud9.

    Yes

    Yes

    No

    Yes

    Expand Network settings. For Network (VPC), choose the VPC that you want AWS Cloud9 to use.

    Yes

    Yes

    No

    No

    Expand Network settings. For Network (VPC), choose the VPC that you want AWS Cloud9 to use.

    If the chosen VPC has multiple subnets, expand Network settings (advanced). For Subnet, choose the subnet that you want AWS Cloud9 to use in the chosen VPC.

    If the chosen VPC has no subnets, create one. To do this, choose Create new subnet, and then follow the on-screen directions. For more information, see Create a subnet for AWS Cloud9.

    Yes

    No

    Yes

    AWS Cloud9 can't use a default VPC in an AWS account that's different than the account for the new environment. Choose a different option in this list.

    Yes

    No

    No

    Yes

    Expand Network settings. For Network (VPC), choose the VPC that you want AWS Cloud9 to use.

    Note

    The VPC must be in the same Region as the new environment, even if the VPC is in a different account.

    Yes

    No

    No

    No

    Expand Network settings. For Network (VPC), choose the VPC that you want AWS Cloud9 to use.

    For Subnet, choose the subnet you want AWS Cloud9 to use in the chosen VPC.

    If the chosen VPC has no subnets, to create a subnet for a VPC in a different AWS account than the new environment, see Working with Shared VPCs in the Amazon VPC User Guide.

    Note

    The VPC and subnet must be in the same Region as the new environment, even if the VPC and subnet are in a different account.

    For more information about these choices, see VPC settings for AWS Cloud9 Development Environments.

  12. Add up to 50 tags by supplying a Key and Value for each tag. Do so by selecting Add new tag. The tags are attached to the AWS Cloud9 environment as resource tags, and are propagated to the following underlying resources: the AWS CloudFormation stack, the Amazon EC2 instance, and Amazon EC2 security groups. To learn more about tags, see Control Access Using AWS Resource Tags in the IAM User Guide and advanced information in this guide.

    Warning

    If you update these tags after you create them, the changes aren't propagated to the underlying resources. For more information, see Propagating tag updates to underlying resources in the advanced information about tags.

  13. Choose Create to create your environment, and then you're redirected to the home page. If the account is successfully created, a green flash bar appears at the top of the AWS Cloud9 console. You can select the new environment and choose Open in Cloud9 to launch the IDE.

    
        AWS Cloud9 IDE selector in the AWS Cloud9 console

    If the account fails to create, a red flash bar appears at the top of the AWS Cloud9 console. Your account might fail to create because of a problem with your web browser, your AWS access permissions, the instance, or the associated network. You can find information about possible fixes in the AWS Cloud9 Troubleshooting section.

    Note

    AWS Cloud9 supports both IMDSv1 and IMDSv2. We recommend adopting IMDSv2 as it provides an enhanced level of security compared to IMDSv1. For more information on the benefits of IMDSv2, see AWS Security Blog. For information on how to transition to IMDSv2 from IMDSv1, see Transition to using Instance Metadata Service Version 2 in the Amazon EC2 User Guide for Linux Instances.

    Note

    If your environment is using a proxy to access the internet, you must provide proxy details to AWS Cloud9 so it can install dependencies. For more information, see Failed to install dependencies.

Creating an environment with code

To use code to create an EC2 environment in AWS Cloud9, call the AWS Cloud9 create EC2 environment operation, as follows.

AWS CLI

create-environment-ec2

AWS SDK for C++

CreateEnvironmentEC2Request, CreateEnvironmentEC2Result

AWS SDK for Go

CreateEnvironmentEC2, CreateEnvironmentEC2Request, CreateEnvironmentEC2WithContext

AWS SDK for Java

CreateEnvironmentEC2Request, CreateEnvironmentEC2Result

AWS SDK for JavaScript

createEnvironmentEC2

AWS SDK for .NET

CreateEnvironmentEC2Request, CreateEnvironmentEC2Response

AWS SDK for PHP

createEnvironmentEC2

AWS SDK for Python (Boto)

create_environment_ec2

AWS SDK for Ruby

create_environment_ec2

AWS Tools for Windows PowerShell

New-C9EnvironmentEC2

AWS Cloud9 API

CreateEnvironmentEC2

Note

If your environment is using a proxy to access the internet, you must provide proxy details to AWS Cloud9 so it can install dependencies. For more information, see Failed to install dependencies.