CodeWithYou

Code anywhere. AWS Cloud9

Published on
Authors
Code anywhere. AWS Cloud9
Photo by Lukas Blazek

Recently I've been working on a project that requires me to work on a remote server. I've been using AWS Cloud9 for a while now and I'm really happy with it. It's a great tool for developers who want to code anywhere. It's a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser. It comes with a powerful code editor, debugger, and terminal. You can create and switch between multiple Cloud9 environments that include a full-fledged Linux server, code editor, and terminal. You can also connect to your existing AWS resources from within the IDE.

Features

  • Code editor: Cloud9 comes with a powerful code editor that supports syntax highlighting, code completion, and code folding. It also supports multiple themes and keyboard shortcuts.

  • Debugger: Cloud9 comes with a powerful debugger that lets you debug your code in the browser. It supports breakpoints, step-by-step debugging, and variable inspection.

  • Terminal: Cloud9 comes with a full-fledged terminal that lets you run commands on the server. It also supports multiple tabs and split panes.

  • AWS integration: Cloud9 lets you connect to your existing AWS resources from within the IDE. You can create and manage AWS resources, such as Amazon EC2 instances, Amazon S3 buckets, and Amazon DynamoDB tables, directly from the IDE. This is really useful if you want to build a serverless application. And if you're using AWS Amplify, you can use the Amplify CLI directly from the IDE.

  • Collaboration: Cloud9 lets you collaborate with your team members in real-time. You can share your Cloud9 environment with your team members and work on the same project together. You can also chat with your team members directly from the IDE.

Setup Cloud9 by using AWS CDK

You can create a Cloud9 environment by using the AWS console. This is the easiest way to create a Cloud9 environment. You can also create a Cloud9 environment by using AWS CDK. This is a great way to create a Cloud9 environment because you can automate the process of creating a Cloud9 environment.

In this post, I'll show you how to create a Cloud9 environment by using AWS CDK. I'll also show you how to create a Cloud9 environment by using the AWS CloudFormation console.

Advertisement

Create a Cloud9 environment by using AWS CDK

// use default VPC
const defaultVpc = ec2.Vpc.fromLookup(this, 'DefaultVPC', {
  isDefault: true,
})

// you should create a new user and use that user's ARN
// you can use the following command to get the ARN of the user
// aws iam get-user --user-name <user-name> --query 'User.Arn'
const ownerArn = `arn:aws:iam::${this.account}:user/${this.node.tryGetContext('user')}`

//  create a new Cloud9 environment.
const c9env = new cloud9.CfnEnvironmentEC2(this, 'C9Env', {
  name: 'c9env',
  description: 'Cloud9 Environment',
  automaticStopTimeMinutes: 15, // stop the environment after 15 minutes of inactivity
  instanceType: 't2.micro',
  ownerArn, // if you don't specify this, the environment will create a new user for you
  connectionType: 'CONNECT_SSM', // use SSM to connect to the environment. You can also use SSH
  subnetId: defaultVpc.selectSubnets({
    subnetType: ec2.SubnetType.PUBLIC,
  }).subnetIds[0], // use the first public subnet
})

const environmentId = c9env.ref
const ideUrl = `https://${this.region}.console.aws.amazon.com/cloud9/ide/${environmentId}`

new CfnOutput(this, 'Cloud9IDEUrl', {
  value: ideUrl,
})

Full code is available on GitHub

After you deploy the stack, you can open the Cloud9 IDE by using the URL that is displayed in the output. You can also open the Cloud9 IDE by using the following command:

aws cloud9 describe-environments --environment-ids <environment-id> --query 'environments[0].ideUrl'
Cloud9 IDE

That's it. You can now start coding anywhere.

That all for this post. I hope you find it useful. If you have any questions, feel free to leave a comment below. Thanks for reading.

Advertisement