-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(cloud9): support setting environment owner #23878
Changes from 3 commits
2a47f13
43ded09
85e85a7
c52b45e
a695cd5
beaf73c
4f014c1
a4c5e8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -23,19 +23,19 @@ | |||||
|
||||||
This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aws-cdk) project. | ||||||
|
||||||
AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a | ||||||
browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular | ||||||
programming languages, including JavaScript, Python, PHP, and more, so you don’t need to install files or configure your | ||||||
development machine to start new projects. Since your Cloud9 IDE is cloud-based, you can work on your projects from your | ||||||
office, home, or anywhere using an internet-connected machine. Cloud9 also provides a seamless experience for developing | ||||||
serverless applications enabling you to easily define resources, debug, and switch between local and remote execution of | ||||||
serverless applications. With Cloud9, you can quickly share your development environment with your team, enabling you to pair | ||||||
AWS Cloud9 is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a | ||||||
browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular | ||||||
programming languages, including JavaScript, Python, PHP, and more, so you don’t need to install files or configure your | ||||||
development machine to start new projects. Since your Cloud9 IDE is cloud-based, you can work on your projects from your | ||||||
office, home, or anywhere using an internet-connected machine. Cloud9 also provides a seamless experience for developing | ||||||
serverless applications enabling you to easily define resources, debug, and switch between local and remote execution of | ||||||
serverless applications. With Cloud9, you can quickly share your development environment with your team, enabling you to pair | ||||||
program and track each other's inputs in real time. | ||||||
|
||||||
|
||||||
## Creating EC2 Environment | ||||||
|
||||||
EC2 Environments are defined with `Ec2Environment`. To create an EC2 environment in the private subnet, specify | ||||||
EC2 Environments are defined with `Ec2Environment`. To create an EC2 environment in the private subnet, specify | ||||||
`subnetSelection` with private `subnetType`. | ||||||
|
||||||
|
||||||
|
@@ -52,7 +52,7 @@ new cloud9.Ec2Environment(this, 'Cloud9Env2', { | |||||
imageId: cloud9.ImageId.AMAZON_LINUX_2, | ||||||
}); | ||||||
|
||||||
// or specify in a different subnetSelection | ||||||
// or specify in a different subnetSelection | ||||||
const c9env = new cloud9.Ec2Environment(this, 'Cloud9Env3', { | ||||||
vpc, | ||||||
subnetSelection: { | ||||||
|
@@ -104,3 +104,39 @@ new cloud9.Ec2Environment(this, 'C9Env', { | |||||
imageId: cloud9.ImageId.AMAZON_LINUX_2, | ||||||
}); | ||||||
``` | ||||||
|
||||||
## Specifying Owners | ||||||
`Owner` is a user that owns a Cloud9 environment . `Owner` has their own access permissions, resources. And we can specify an `Owner`in an Ec2 environment which could be of two types, 1. AccountRoot and 2. Iam User. It allows AWS to determine who has permissions to manage the environment, either an IAM user or the account root user | ||||||
|
||||||
### AccountRoot | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```ts | ||||||
new cloud9.Ec2Environment(this, 'C9Env', { | ||||||
// provides root account id. | ||||||
owner: cloud9.Owner.AccountRoot('root account id') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
``` | ||||||
|
||||||
### Iam User | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
```ts | ||||||
import * as iam from '@aws-cdk/aws-iam'; | ||||||
|
||||||
const user = new iam.User(stack, 'User'); | ||||||
// provides an iam user. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's helpful if the example is complete and works. Since we know that the user must have the
Suggested change
|
||||||
new cloud9.Ec2Environment(this, 'C9Env', { | ||||||
owner: cloud9.Owner.User(user) | ||||||
}) | ||||||
``` | ||||||
|
||||||
### create a new Cloud9 environment with an owner as an Iam User. | ||||||
|
||||||
```ts | ||||||
const user = new iam.User(stack, 'User'); | ||||||
declare const vpc: ec2.Vpc; | ||||||
new cloud9.Ec2Environment(this, 'C9Env', { | ||||||
vpc, | ||||||
imageId: cloud9.ImageId.AMAZON_LINUX_2, | ||||||
owner: cloud9.Owner.User(user) | ||||||
}); | ||||||
``` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This example isn't necessary any more, the previous example already covers that. |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,6 @@ | ||||||||||
import * as codecommit from '@aws-cdk/aws-codecommit'; | ||||||||||
import * as ec2 from '@aws-cdk/aws-ec2'; | ||||||||||
import { IUser } from '@aws-cdk/aws-iam'; | ||||||||||
import * as cdk from '@aws-cdk/core'; | ||||||||||
import { Construct } from 'constructs'; | ||||||||||
import { CfnEnvironmentEC2 } from '../lib/cloud9.generated'; | ||||||||||
|
@@ -53,11 +54,16 @@ export enum ImageId { | |||||||||
*/ | ||||||||||
UBUNTU_18_04 = 'ubuntu-18.04-x86_64' | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* Properties for Ec2Environment | ||||||||||
*/ | ||||||||||
export interface Ec2EnvironmentProps { | ||||||||||
/** | ||||||||||
* Owner of the environment. | ||||||||||
* | ||||||||||
rix0rrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
*/ | ||||||||||
readonly owner?: Owner; | ||||||||||
|
||||||||||
/** | ||||||||||
* The type of instance to connect to the environment. | ||||||||||
* | ||||||||||
|
@@ -136,7 +142,6 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment { | |||||||||
} | ||||||||||
return new Import(scope, id); | ||||||||||
} | ||||||||||
|
||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't remove this line, we try to keep an empty line between functions so they are easier to visually distinguish. |
||||||||||
/** | ||||||||||
* The environment name of this Cloud9 environment | ||||||||||
* | ||||||||||
|
@@ -182,6 +187,7 @@ export class Ec2Environment extends cdk.Resource implements IEc2Environment { | |||||||||
const c9env = new CfnEnvironmentEC2(this, 'Resource', { | ||||||||||
name: props.ec2EnvironmentName, | ||||||||||
description: props.description, | ||||||||||
ownerArn: props.owner?.ownerArn, | ||||||||||
instanceType: props.instanceType?.toString() ?? ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO).toString(), | ||||||||||
subnetId: this.vpc.selectSubnets(vpcSubnets).subnetIds[0], | ||||||||||
repositories: props.clonedRepositories ? props.clonedRepositories.map(r => ({ | ||||||||||
|
@@ -217,3 +223,38 @@ export class CloneRepository { | |||||||||
|
||||||||||
private constructor(public readonly repositoryUrl: string, public readonly pathComponent: string) {} | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* The class for different types of owners | ||||||||||
* | ||||||||||
* | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
*/ | ||||||||||
export class Owner { | ||||||||||
/** | ||||||||||
* import from Owner Iuser | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
* | ||||||||||
rix0rrr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
* User need to have AWSCloud9Administrator permissions | ||||||||||
* @see https://docs.aws.amazon.com/cloud9/latest/user-guide/share-environment.html#share-environment-about | ||||||||||
* | ||||||||||
* @param user the User object to use as the environment owner | ||||||||||
*/ | ||||||||||
public static User(user: IUser): Owner { | ||||||||||
return { ownerArn: user.userArn }; | ||||||||||
} | ||||||||||
|
||||||||||
|
||||||||||
/** | ||||||||||
* import from Owner account root | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
* | ||||||||||
* @param accountId the AccountId to use as the environment owner. | ||||||||||
*/ | ||||||||||
public static AccountRoot(accountId: string): Owner { | ||||||||||
return { ownerArn: `arn:aws:iam::${accountId}:root` }; | ||||||||||
} | ||||||||||
|
||||||||||
/** | ||||||||||
* | ||||||||||
* @param ownerArn of environment owner. | ||||||||||
*/ | ||||||||||
private constructor(public readonly ownerArn: string) {} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try and explain a bit more what this represents.
For example: