Skip to content

Commit

Permalink
fromEc2ServiceArn -> fromEc2ServiceAttributes, fromFargateServiceArn …
Browse files Browse the repository at this point in the history
…-> fromFargateServiceAttributes
  • Loading branch information
atsushi-ishibashi committed Feb 24, 2020
1 parent 8be4b51 commit f38e6f4
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class EcsDeployAction extends Action {

return {
configuration: {
ClusterName: this.props.service.cluster.clusterName,
ClusterName: this.props.service.clusterName,
ServiceName: this.props.service.serviceName,
FileName: this.props.imageFile && this.props.imageFile.fileName,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,8 @@ function anyEcsService(): ecs.FargateService {

function anyIService(): ecs.IService {
const stack = new cdk.Stack();
return ecs.FargateService.fromFargateServiceArn(stack, 'FargateService', 'serviceArn');
return ecs.FargateService.fromFargateServiceAttributes(stack, 'FargateService', {
serviceName: 'serviceName',
clusterName: 'clusterName',
});
}
29 changes: 25 additions & 4 deletions packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,32 @@ import { Protocol } from '../container-definition';
import { CfnService } from '../ecs.generated';
import { ScalableTaskCount } from './scalable-task-count';

/**
* The properties to import from the ECS cluster.
*/
export interface ServiceAttributes {
/**
* The name of the cluster that hosts the service.
*/
readonly clusterName: string;
/**
* The name of the service.
*/
readonly serviceName: string;
}

/**
* The interface for a service.
*/
export interface IService extends IResource {
/**
* The Amazon Resource Name (ARN) of the service.
*
* @attribute
* The name of the cluster that hosts the service.
*/
readonly serviceArn: string;
readonly clusterName: string;
/**
* The name of the service.
*/
readonly serviceName: string;
}

/**
Expand Down Expand Up @@ -277,6 +293,10 @@ export abstract class BaseService extends Resource
* The cluster that hosts the service.
*/
public readonly cluster: ICluster;
/**
* The cluster name that hosts the service.
*/
public readonly clusterName: string;

/**
* The details of the AWS Cloud Map service.
Expand Down Expand Up @@ -345,6 +365,7 @@ export abstract class BaseService extends Resource
this.serviceName = this.getResourceNameAttribute(this.resource.attrName);

this.cluster = props.cluster;
this.clusterName = props.cluster.clusterName

if (props.cloudMapOptions) {
this.enableCloudMap(props.cloudMapOptions);
Expand Down
7 changes: 4 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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, ServiceAttributes, IService, LaunchType, PropagatedTagSource } from '../base/base-service';
import { NetworkMode, TaskDefinition } from '../base/task-definition';
import { CfnService } from '../ecs.generated';
import { PlacementConstraint, PlacementStrategy } from '../placement';
Expand Down Expand Up @@ -97,9 +97,10 @@ export class Ec2Service extends BaseService implements IEc2Service {
/**
* Imports from the specified service ARN.
*/
public static fromEc2ServiceArn(scope: Construct, id: string, ec2ServiceArn: string): IEc2Service {
public static fromEc2ServiceAttributes(scope: Construct, id: string, attrs: ServiceAttributes): IEc2Service {
class Import extends Resource implements IEc2Service {
public readonly serviceArn = ec2ServiceArn;
public readonly serviceName = attrs.serviceName;
public readonly clusterName = attrs.clusterName;
}
return new Import(scope, id);
}
Expand Down
7 changes: 4 additions & 3 deletions packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { BaseService, BaseServiceOptions, IService, LaunchType, PropagatedTagSource } from '../base/base-service';
import { BaseService, BaseServiceOptions, ServiceAttributes, IService, LaunchType, PropagatedTagSource } from '../base/base-service';
import { TaskDefinition } from '../base/task-definition';

/**
Expand Down Expand Up @@ -75,9 +75,10 @@ export class FargateService extends BaseService implements IFargateService {
/**
* Import a task definition from the specified task definition ARN.
*/
public static fromFargateServiceArn(scope: cdk.Construct, id: string, fargateServiceArn: string): IFargateService {
public static fromFargateServiceAttributes(scope: cdk.Construct, id: string, attrs: ServiceAttributes): IFargateService {
class Import extends cdk.Resource implements IFargateService {
public readonly serviceArn = fargateServiceArn;
public readonly serviceName = attrs.serviceName;
public readonly clusterName = attrs.clusterName;
}
return new Import(scope, id);
}
Expand Down

0 comments on commit f38e6f4

Please sign in to comment.