Skip to content

Commit

Permalink
Merge branch 'main' into add-tg-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
edisongustavo committed Feb 8, 2023
2 parents 5f9d157 + a5317ca commit 2026066
Show file tree
Hide file tree
Showing 211 changed files with 14,947 additions and 5,349 deletions.
4 changes: 4 additions & 0 deletions .gitallowed
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ account: '012345678913'

# Account patterns used in the CHANGELOG
account: '123456789012'

111111111111
222222222222
123456789012
333333333333

# The account ID's of public facing ECR images for App Mesh Envoy
# https://docs.aws.amazon.com/app-mesh/latest/userguide/envoy.html
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.v2.alpha.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.63.2-alpha.0](https://github.com/aws/aws-cdk/compare/v2.63.1-alpha.0...v2.63.2-alpha.0) (2023-02-04)

## [2.63.1-alpha.0](https://github.com/aws/aws-cdk/compare/v2.63.0-alpha.0...v2.63.1-alpha.0) (2023-02-03)

## [2.63.0-alpha.0](https://github.com/aws/aws-cdk/compare/v2.62.2-alpha.0...v2.63.0-alpha.0) (2023-01-31)


Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [2.63.2](https://github.com/aws/aws-cdk/compare/v2.63.1...v2.63.2) (2023-02-04)

## [2.63.1](https://github.com/aws/aws-cdk/compare/v2.63.0...v2.63.1) (2023-02-03)


### Reverts

* **cdk-assets:** packaging assets is broken on Node older than 14.17 ([#23994](https://github.com/aws/aws-cdk/issues/23994)) ([1976f1a](https://github.com/aws/aws-cdk/commit/1976f1a7f585b1adb582c5cb557b96ed38418fca)), closes [#23859](https://github.com/aws/aws-cdk/issues/23859)

## [2.63.0](https://github.com/aws/aws-cdk/compare/v2.62.2...v2.63.0) (2023-01-31)


Expand Down
54 changes: 45 additions & 9 deletions packages/@aws-cdk/aws-cloud9/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.


Expand All @@ -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: {
Expand Down Expand Up @@ -104,3 +104,39 @@ new cloud9.Ec2Environment(this, 'C9Env', {
imageId: cloud9.ImageId.AMAZON_LINUX_2,
});
```

## Specifying Owners

Every Cloud9 Environment has an **owner**. An owner has full control over the environment, and can invite additional members to the environment for collaboration purposes. For more information, see [Working with shared environments in AWS Cloud9](https://docs.aws.amazon.com/cloud9/latest/user-guide/share-environment.html)).

By default, the owner will be the identity that creates the Environment, which is most likely your CloudFormation Execution Role when the Environment is created using CloudFormation. Provider a value for the `owner` property to assign a different owner, either a specific IAM User or the AWS Account Root User.

`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 (but using the account root user is not recommended, see [environment sharing best practices](https://docs.aws.amazon.com/cloud9/latest/user-guide/share-environment.html#share-environment-best-practices)).

To specify the AWS Account Root User as the environment owner, use `Owner.accountRoot()`

```ts
declare const vpc: ec2.Vpc;
new cloud9.Ec2Environment(this, 'C9Env', {
vpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,

owner: cloud9.Owner.accountRoot('111111111')
})
```

To specify a specific IAM User as the environment owner, use `Owner.user()`. The user should have the `AWSCloud9Administrator` managed policy

```ts
import * as iam from '@aws-cdk/aws-iam';

const user = new iam.User(this, 'user');
user.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSCloud9Administrator'));
declare const vpc: ec2.Vpc;
new cloud9.Ec2Environment(this, 'C9Env', {
vpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,

owner: cloud9.Owner.user(user)
})
```
47 changes: 46 additions & 1 deletion packages/@aws-cdk/aws-cloud9/lib/environment.ts
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';
Expand Down Expand Up @@ -53,11 +54,19 @@ export enum ImageId {
*/
UBUNTU_18_04 = 'ubuntu-18.04-x86_64'
}

/**
* Properties for Ec2Environment
*/
export interface Ec2EnvironmentProps {
/**
* Owner of the environment.
*
* The owner has full control of the environment and can invite additional members.
*
* @default - The identity that CloudFormation executes under will be the owner
*/
readonly owner?: Owner;

/**
* The type of instance to connect to the environment.
*
Expand Down Expand Up @@ -182,6 +191,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 => ({
Expand Down Expand Up @@ -217,3 +227,38 @@ export class CloneRepository {

private constructor(public readonly repositoryUrl: string, public readonly pathComponent: string) {}
}

/**
* An environment owner
*
*
*/
export class Owner {
/**
* Make an IAM user the environment owner
*
* 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 };
}


/**
* Make the Account Root User the environment owner (not recommended)
*
* @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) {}
}
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-cloud9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@
"dependencies": {
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/core": "0.0.0",
"constructs": "^10.0.0"
},
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"@aws-cdk/aws-codecommit": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
"@aws-cdk/aws-iam": "0.0.0",
"@aws-cdk/core": "0.0.0",
"constructs": "^10.0.0"
},
Expand Down
35 changes: 33 additions & 2 deletions packages/@aws-cdk/aws-cloud9/test/cloud9.environment.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Match, Template } from '@aws-cdk/assertions';
import * as codecommit from '@aws-cdk/aws-codecommit';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import * as cloud9 from '../lib';
import { ConnectionType, ImageId } from '../lib';
import { ConnectionType, ImageId, Owner } from '../lib';

let stack: cdk.Stack;
let vpc: ec2.IVpc;
Expand Down Expand Up @@ -79,7 +80,6 @@ test('throw error when subnetSelection not specified and the provided VPC has no
test('can use CodeCommit repositories', () => {
// WHEN
const repo = codecommit.Repository.fromRepositoryName(stack, 'Repo', 'foo');

new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
clonedRepositories: [
Expand Down Expand Up @@ -114,6 +114,37 @@ test('can use CodeCommit repositories', () => {
});
});

test('environment owner can be an IAM user', () => {
// WHEN
const user = new iam.User(stack, 'User', {
userName: 'testUser',
});
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,
owner: Owner.user(user),
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Cloud9::EnvironmentEC2', {
OwnerArn: {
'Fn::GetAtt': ['User00B015A1', 'Arn'],
},
});
});

test('environment owner can be account root', () => {
// WHEN
new cloud9.Ec2Environment(stack, 'C9Env', {
vpc,
imageId: cloud9.ImageId.AMAZON_LINUX_2,
owner: Owner.accountRoot('12345678'),
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Cloud9::EnvironmentEC2', {
OwnerArn: 'arn:aws:iam::12345678:root',
});
});

test.each([
[ConnectionType.CONNECT_SSH, 'CONNECT_SSH'],
[ConnectionType.CONNECT_SSM, 'CONNECT_SSM'],
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codedeploy/lib/ecs/deployment-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class EcsDeploymentGroup extends DeploymentGroupBase implements IEcsDeplo
this.alarms = props.alarms || [];

this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('AWSCodeDeployRoleForECS'));
this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE);

if (cdk.Resource.isOwnedResource(props.service)) {
const cfnSvc = (props.service as ecs.BaseService).node.defaultChild as ecs.CfnService;
Expand Down Expand Up @@ -358,6 +358,6 @@ class ImportedEcsDeploymentGroup extends ImportedDeploymentGroupBase implements
});

this.application = props.application;
this.deploymentConfig = props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || EcsDeploymentConfig.ALL_AT_ONCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class LambdaDeploymentGroup extends DeploymentGroupBase implements ILambd
this.alarms = props.alarms || [];

this.role.addManagedPolicy(iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSCodeDeployRoleForLambdaLimited'));
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES);

const resource = new CfnDeploymentGroup(this, 'Resource', {
applicationName: this.application.applicationName,
Expand Down Expand Up @@ -290,6 +290,6 @@ class ImportedLambdaDeploymentGroup extends ImportedDeploymentGroupBase implemen
});

this.application = props.application;
this.deploymentConfig = props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES;
this.deploymentConfig = this._bindDeploymentConfig(props.deploymentConfig || LambdaDeploymentConfig.CANARY_10PERCENT_5MINUTES);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as iam from '@aws-cdk/aws-iam';
import { Resource, IResource, ArnFormat, Arn, Aws } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { IBaseDeploymentConfig } from '../base-deployment-config';
import { CfnDeploymentGroup } from '../codedeploy.generated';
import { isPredefinedDeploymentConfig } from './predefined-deployment-config';
import { validateName } from './utils';

/**
Expand Down Expand Up @@ -52,6 +54,15 @@ export class ImportedDeploymentGroupBase extends Resource {
this.deploymentGroupName = deploymentGroupName;
this.deploymentGroupArn = deploymentGroupArn;
}

/**
* Bind DeploymentGroupConfig to the current group, if supported
*
* @internal
*/
protected _bindDeploymentConfig(config: IBaseDeploymentConfig) {
return isPredefinedDeploymentConfig(config) ? config.bindEnvironment(this) : config;
}
}

export interface DeploymentGroupBaseProps {
Expand Down Expand Up @@ -114,6 +125,15 @@ export class DeploymentGroupBase extends Resource {
this.node.addValidation({ validate: () => validateName('Deployment group', this.physicalName) });
}

/**
* Bind DeploymentGroupConfig to the current group, if supported
*
* @internal
*/
protected _bindDeploymentConfig(config: IBaseDeploymentConfig) {
return isPredefinedDeploymentConfig(config) ? config.bindEnvironment(this) : config;
}

/**
* Set name and ARN properties.
*
Expand All @@ -135,4 +155,4 @@ export class DeploymentGroupBase extends Resource {
arnFormat: ArnFormat.COLON_RESOURCE_NAME,
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { IResource } from '@aws-cdk/core';
import { IBaseDeploymentConfig } from '../base-deployment-config';

/**
* A reference to a DeploymentConfig that is managed by AWS
*
* Since these DeploymentConfigs are present in every region, and we might use
* them in conjunction with cross-region DeploymentGroups, we need to specialize
* the account and region to the DeploymentGroup before using.
*
* A DeploymentGroup must call `bindEnvironment()` first if it detects this type,
* before reading the DeploymentConfig ARN.
*
* This type is fully hidden, which means that the constant objects provided by
* CDK will have magical behavior that customers can't reimplement themselves.
* Not ideal, but our DeploymentConfig type inheritance is already overly
* complicated and to do it properly with the nominal typing we are emplying
* will require adding 4 more empty or nearly empty interfaces, which seems a
* bit silly for a need that's not necessarily clearly needed by customers.
* We can always move to exposing later.
*/
export interface IPredefinedDeploymentConfig {
/**
* Bind the predefined deployment config to the environment of the given resource
*/
bindEnvironment(deploymentGroup: IResource): IBaseDeploymentConfig;
}

export function isPredefinedDeploymentConfig(x: unknown): x is IPredefinedDeploymentConfig {
return typeof x === 'object' && !!x && !!(x as any).bindEnvironment;
}
Loading

0 comments on commit 2026066

Please sign in to comment.