Skip to content

Commit

Permalink
Merge branch 'master' into sagemaker-l2
Browse files Browse the repository at this point in the history
  • Loading branch information
petermeansrock authored Mar 12, 2020
2 parents fc25fdb + c63db52 commit f30c975
Show file tree
Hide file tree
Showing 31 changed files with 568 additions and 176 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudfront/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.30",
"aws-sdk": "^2.637.0",
"aws-sdk": "^2.638.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-cloudtrail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.30",
"aws-sdk": "^2.637.0",
"aws-sdk": "^2.638.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export enum ComparisonOperator {
GREATER_THAN_THRESHOLD = 'GreaterThanThreshold',
LESS_THAN_THRESHOLD = 'LessThanThreshold',
LESS_THAN_OR_EQUAL_TO_THRESHOLD = 'LessThanOrEqualToThreshold',
LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD = 'LessThanLowerOrGreaterThanUpperThreshold',
}

const OPERATOR_SYMBOLS: {[key: string]: string} = {
Expand Down
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-cloudwatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
"docs-public-apis:@aws-cdk/aws-cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD",
"docs-public-apis:@aws-cdk/aws-cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD",
"docs-public-apis:@aws-cdk/aws-cloudwatch.ComparisonOperator.LESS_THAN_OR_EQUAL_TO_THRESHOLD",
"docs-public-apis:@aws-cdk/aws-cloudwatch.ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD",
"docs-public-apis:@aws-cdk/aws-cloudwatch.PeriodOverride",
"docs-public-apis:@aws-cdk/aws-cloudwatch.PeriodOverride.AUTO",
"docs-public-apis:@aws-cdk/aws-cloudwatch.PeriodOverride.INHERIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codebuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@aws-cdk/aws-sns": "0.0.0",
"@aws-cdk/aws-sqs": "0.0.0",
"@types/nodeunit": "^0.0.30",
"aws-sdk": "^2.637.0",
"aws-sdk": "^2.638.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codecommit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@aws-cdk/assert": "0.0.0",
"@aws-cdk/aws-sns": "0.0.0",
"@types/nodeunit": "^0.0.30",
"aws-sdk": "^2.637.0",
"aws-sdk": "^2.638.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
"cfn2ts": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface EcsDeployActionProps extends codepipeline.CommonAwsActionProps
/**
* The ECS Service to deploy.
*/
readonly service: ecs.BaseService;
readonly service: ecs.IBaseService;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { expect, haveResourceLike } from '@aws-cdk/assert';
import * as codepipeline from '@aws-cdk/aws-codepipeline';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import { Test } from 'nodeunit';
import * as cpactions from '../../lib';
Expand Down Expand Up @@ -80,6 +82,71 @@ export = {

test.done();
},

'can be created by existing service'(test: Test) {
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'Vpc');
const service = ecs.FargateService.fromFargateServiceAttributes(stack, 'FargateService', {
serviceName: 'service-name',
cluster: ecs.Cluster.fromClusterAttributes(stack, 'Cluster', {
vpc,
securityGroups: [],
clusterName: 'cluster-name',
}),
});
const artifact = new codepipeline.Artifact('Artifact');
const bucket = new s3.Bucket(stack, 'PipelineBucket', {
versioned: true,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const source = new cpactions.S3SourceAction({
actionName: 'Source',
output: artifact,
bucket,
bucketKey: 'key',
});
const action = new cpactions.EcsDeployAction({
actionName: 'ECS',
service,
imageFile: artifact.atPath('imageFile.json'),
});
new codepipeline.Pipeline(stack, 'Pipeline', {
stages: [
{
stageName: 'Source',
actions: [source],
},
{
stageName: 'Deploy',
actions: [action],
}
],
});

expect(stack).to(haveResourceLike('AWS::CodePipeline::Pipeline', {
Stages: [
{},
{
Actions: [
{
Name: 'ECS',
ActionTypeId: {
Category: "Deploy",
Provider: "ECS"
},
Configuration: {
ClusterName: "cluster-name",
ServiceName: "service-name",
FileName: "imageFile.json"
}
}
]
}
]
}));

test.done();
},
},
};

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"devDependencies": {
"@aws-cdk/assert": "0.0.0",
"@types/nodeunit": "^0.0.30",
"aws-sdk": "^2.637.0",
"aws-sdk": "^2.638.0",
"aws-sdk-mock": "^5.1.0",
"cdk-build-tools": "0.0.0",
"cdk-integ-tools": "0.0.0",
Expand Down
14 changes: 7 additions & 7 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, haveResource, ResourcePart, SynthUtils } from '@aws-cdk/assert';
import * as appscaling from '@aws-cdk/aws-applicationautoscaling';
import * as iam from '@aws-cdk/aws-iam';
import { App, CfnDeletionPolicy, ConstructNode, RemovalPolicy, Stack, Tag } from '@aws-cdk/core';
import { App, CfnDeletionPolicy, ConstructNode, Duration, RemovalPolicy, Stack, Tag } from '@aws-cdk/core';
import { Test } from 'nodeunit';
import {
Attribute,
Expand Down Expand Up @@ -1142,7 +1142,7 @@ export = {

// THEN
test.deepEqual(stack.resolve(table.metricConsumedReadCapacityUnits()), {
period: { amount: 5, unit: { label: 'minutes', inSeconds: 60 } },
period: Duration.minutes(5),
dimensions: { TableName: { Ref: 'TableCD117FA1' } },
namespace: 'AWS/DynamoDB',
metricName: 'ConsumedReadCapacityUnits',
Expand All @@ -1161,7 +1161,7 @@ export = {

// THEN
test.deepEqual(stack.resolve(table.metricConsumedWriteCapacityUnits()), {
period: { amount: 5, unit: { label: 'minutes', inSeconds: 60 } },
period: Duration.minutes(5),
dimensions: { TableName: { Ref: 'TableCD117FA1' } },
namespace: 'AWS/DynamoDB',
metricName: 'ConsumedWriteCapacityUnits',
Expand All @@ -1180,7 +1180,7 @@ export = {

// THEN
test.deepEqual(stack.resolve(table.metricSystemErrors()), {
period: { amount: 5, unit: { label: 'minutes', inSeconds: 60 } },
period: Duration.minutes(5),
dimensions: { TableName: { Ref: 'TableCD117FA1' } },
namespace: 'AWS/DynamoDB',
metricName: 'SystemErrors',
Expand All @@ -1199,7 +1199,7 @@ export = {

// THEN
test.deepEqual(stack.resolve(table.metricUserErrors()), {
period: { amount: 5, unit: { label: 'minutes', inSeconds: 60 } },
period: Duration.minutes(5),
dimensions: { TableName: { Ref: 'TableCD117FA1' } },
namespace: 'AWS/DynamoDB',
metricName: 'UserErrors',
Expand All @@ -1218,7 +1218,7 @@ export = {

// THEN
test.deepEqual(stack.resolve(table.metricConditionalCheckFailedRequests()), {
period: { amount: 5, unit: { label: 'minutes', inSeconds: 60 } },
period: Duration.minutes(5),
dimensions: { TableName: { Ref: 'TableCD117FA1' } },
namespace: 'AWS/DynamoDB',
metricName: 'ConditionalCheckFailedRequests',
Expand All @@ -1237,7 +1237,7 @@ export = {

// THEN
test.deepEqual(stack.resolve(table.metricSuccessfulRequestLatency()), {
period: { amount: 5, unit: { label: 'minutes', inSeconds: 60 } },
period: Duration.minutes(5),
dimensions: { TableName: { Ref: 'TableCD117FA1' } },
namespace: 'AWS/DynamoDB',
metricName: 'SuccessfulRequestLatency',
Expand Down
19 changes: 18 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export interface IService extends IResource {
* @attribute
*/
readonly serviceArn: string;

/**
* The name of the service.
*
* @attribute
*/
readonly serviceName: string;
}

/**
Expand Down Expand Up @@ -245,11 +252,21 @@ class NetworkListenerConfig extends ListenerConfig {
}
}

/**
* The interface for BaseService.
*/
export interface IBaseService extends IService {
/**
* The cluster that hosts the service.
*/
readonly cluster: ICluster;
}

/**
* The base class for Ec2Service and FargateService services.
*/
export abstract class BaseService extends Resource
implements IService, elbv2.IApplicationLoadBalancerTarget, elbv2.INetworkLoadBalancerTarget, elb.ILoadBalancerTarget {
implements IBaseService, elbv2.IApplicationLoadBalancerTarget, elbv2.INetworkLoadBalancerTarget, elb.ILoadBalancerTarget {

/**
* The security groups which manage the allowed network traffic for the service.
Expand Down
57 changes: 57 additions & 0 deletions packages/@aws-cdk/aws-ecs/lib/base/from-service-attributes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Construct, Resource, Stack } from '@aws-cdk/core';
import { IBaseService } from '../base/base-service';
import { ICluster } from '../cluster';

/**
* The properties to import from the service.
*/
export interface ServiceAttributes {
/**
* The cluster that hosts the service.
*/
readonly cluster: ICluster;

/**
* The service ARN.
*
* @default - either this, or {@link serviceName}, is required
*/
readonly serviceArn?: string;

/**
* The name of the service.
*
* @default - either this, or {@link serviceArn}, is required
*/
readonly serviceName?: string;
}

export function fromServiceAtrributes(scope: Construct, id: string, attrs: ServiceAttributes): IBaseService {
if ((attrs.serviceArn && attrs.serviceName) || (!attrs.serviceArn && !attrs.serviceName)) {
throw new Error('You can only specify either serviceArn or serviceName.');
}

const stack = Stack.of(scope);
let name: string;
let arn: string;
if (attrs.serviceName) {
name = attrs.serviceName as string;
arn = stack.formatArn({
partition: stack.partition,
service: 'ecs',
region: stack.region,
account: stack.account,
resource: 'service',
resourceName: name,
});
} else {
arn = attrs.serviceArn as string;
name = stack.parseArn(arn).resourceName as string;
}
class Import extends Resource implements IBaseService {
public readonly serviceArn = arn;
public readonly serviceName = name;
public readonly cluster = attrs.cluster;
}
return new Import(scope, id);
}
36 changes: 35 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import { Construct, Lazy, Resource, Stack } from '@aws-cdk/core';
import { BaseService, BaseServiceOptions, IService, LaunchType, PropagatedTagSource } from '../base/base-service';
import { BaseService, BaseServiceOptions, IBaseService, IService, LaunchType, PropagatedTagSource } from '../base/base-service';
import { fromServiceAtrributes } from '../base/from-service-attributes';
import { NetworkMode, TaskDefinition } from '../base/task-definition';
import { ICluster } from '../cluster';
import { CfnService } from '../ecs.generated';
import { PlacementConstraint, PlacementStrategy } from '../placement';

Expand Down Expand Up @@ -87,6 +89,30 @@ export interface IEc2Service extends IService {

}

/**
* The properties to import from the service using the EC2 launch type.
*/
export interface Ec2ServiceAttributes {
/**
* The cluster that hosts the service.
*/
readonly cluster: ICluster;

/**
* The service ARN.
*
* @default - either this, or {@link serviceName}, is required
*/
readonly serviceArn?: string;

/**
* The name of the service.
*
* @default - either this, or {@link serviceArn}, is required
*/
readonly serviceName?: string;
}

/**
* This creates a service using the EC2 launch type on an ECS cluster.
*
Expand All @@ -100,10 +126,18 @@ export class Ec2Service extends BaseService implements IEc2Service {
public static fromEc2ServiceArn(scope: Construct, id: string, ec2ServiceArn: string): IEc2Service {
class Import extends Resource implements IEc2Service {
public readonly serviceArn = ec2ServiceArn;
public readonly serviceName = Stack.of(scope).parseArn(ec2ServiceArn).resourceName as string;
}
return new Import(scope, id);
}

/**
* Imports from the specified service attrributes.
*/
public static fromEc2ServiceAttributes(scope: Construct, id: string, attrs: Ec2ServiceAttributes): IBaseService {
return fromServiceAtrributes(scope, id, attrs);
}

private readonly constraints: CfnService.PlacementConstraintProperty[];
private readonly strategies: CfnService.PlacementStrategyProperty[];
private readonly daemon: boolean;
Expand Down
Loading

0 comments on commit f30c975

Please sign in to comment.