diff --git a/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts b/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts index 2238b56d7f6e5..e52a2e1db8935 100644 --- a/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts +++ b/packages/@aws-cdk/aws-codepipeline-actions/lib/ecs/deploy-action.ts @@ -52,7 +52,7 @@ export class EcsDeployAction extends codepipeline.Action { artifactBounds: deployArtifactBounds(), inputs: [determineInputArtifact(props)], configuration: { - ClusterName: props.service.clusterName, + ClusterName: props.service.cluster.clusterName, ServiceName: props.service.serviceName, FileName: props.imageFile && props.imageFile.fileName, }, diff --git a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts index cecdca76129bd..c3c12f1fb8ea0 100644 --- a/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/base/base-service.ts @@ -114,17 +114,16 @@ export abstract class BaseService extends Resource public readonly serviceName: string; /** - * Name of this service's cluster + * Task definition this service is associated with */ - public readonly clusterName: string; + public readonly taskDefinition: TaskDefinition; /** - * Task definition this service is associated with + * The cluster this service is scheduled on */ - public readonly taskDefinition: TaskDefinition; + public readonly cluster: ICluster; protected cloudmapService?: cloudmap.Service; - protected cluster: ICluster; protected loadBalancers = new Array(); protected networkConfiguration?: CfnService.NetworkConfigurationProperty; protected serviceRegistries = new Array(); @@ -136,7 +135,6 @@ export abstract class BaseService extends Resource id: string, props: BaseServiceProps, additionalProps: any, - clusterName: string, taskDefinition: TaskDefinition) { super(scope, id, { physicalName: props.serviceName, @@ -178,7 +176,6 @@ export abstract class BaseService extends Resource this.serviceArn = resourceIdentifiers.arn; this.serviceName = resourceIdentifiers.name; - this.clusterName = clusterName; this.cluster = props.cluster; if (props.serviceDiscoveryOptions) { @@ -224,7 +221,7 @@ export abstract class BaseService extends Resource return this.scalableTaskCount = new ScalableTaskCount(this, 'TaskCount', { serviceNamespace: appscaling.ServiceNamespace.ECS, - resourceId: `service/${this.clusterName}/${this.serviceName}`, + resourceId: `service/${this.cluster.clusterName}/${this.serviceName}`, dimension: 'ecs:service:DesiredCount', role: this.makeAutoScalingRole(), ...props @@ -238,7 +235,7 @@ export abstract class BaseService extends Resource return new cloudwatch.Metric({ namespace: 'AWS/ECS', metricName, - dimensions: { ClusterName: this.clusterName, ServiceName: this.serviceName }, + dimensions: { ClusterName: this.cluster.clusterName, ServiceName: this.serviceName }, ...props }); } diff --git a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts index dccf0cd573e4a..e80af08eaef1e 100644 --- a/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts @@ -85,11 +85,6 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal return new Import(scope, id); } - /** - * Name of the cluster - */ - public readonly clusterName: string; - private readonly constraints: CfnService.PlacementConstraintProperty[]; private readonly strategies: CfnService.PlacementStrategyProperty[]; private readonly daemon: boolean; @@ -125,9 +120,8 @@ export class Ec2Service extends BaseService implements IEc2Service, elb.ILoadBal placementConstraints: Lazy.anyValue({ produce: () => this.constraints }, { omitEmptyArray: true }), placementStrategies: Lazy.anyValue({ produce: () => this.strategies }, { omitEmptyArray: true }), schedulingStrategy: props.daemon ? 'DAEMON' : 'REPLICA', - }, props.cluster.clusterName, props.taskDefinition); + }, props.taskDefinition); - this.clusterName = props.cluster.clusterName; this.constraints = []; this.strategies = []; this.daemon = props.daemon || false; diff --git a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts index 8a7c03d0937cf..bd92b644e0f0b 100644 --- a/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts +++ b/packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts @@ -78,7 +78,7 @@ export class FargateService extends BaseService implements IFargateService { taskDefinition: props.taskDefinition.taskDefinitionArn, launchType: 'FARGATE', platformVersion: props.platformVersion, - }, props.cluster.clusterName, props.taskDefinition); + }, props.taskDefinition); this.configureAwsVpcNetworking(props.cluster.vpc, props.assignPublicIp, props.vpcSubnets, props.securityGroup);