Skip to content

Commit

Permalink
fix: include serviceName in IService
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hammond committed Feb 10, 2020
1 parent bc0fe14 commit c18217d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions 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
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as cdk from '@aws-cdk/core';
import { Construct, Lazy, Resource, Stack } from '@aws-cdk/core';
import { BaseService, BaseServiceOptions, IService, LaunchType, PropagatedTagSource } from '../base/base-service';
import { NetworkMode, TaskDefinition } from '../base/task-definition';
Expand Down Expand Up @@ -98,9 +99,15 @@ export class Ec2Service extends BaseService implements IEc2Service {
* Imports from the specified service ARN.
*/
public static fromEc2ServiceArn(scope: Construct, id: string, ec2ServiceArn: string): IEc2Service {
class Import extends Resource implements IEc2Service {
const serviceName = cdk.Stack.of(scope).parseArn(ec2ServiceArn).serviceName;
if (!serviceName) {
throw new Error(`ECS ARN must be in the format 'arn:aws:ecs:<region>:<account>:service/<serviceName>', got: '${fargateServiceArn}'`);
}
class Import extends cdk.Resource implements IEc2Service {
public readonly serviceArn = ec2ServiceArn;
public readonly serviceName = serviceName
}

return new Import(scope, id);
}

Expand Down
7 changes: 6 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ export interface IFargateService extends IService {
export class FargateService extends BaseService implements IFargateService {

/**
* Import a task definition from the specified task definition ARN.
* Import a service definition from the specified task definition ARN.
*/
public static fromFargateServiceArn(scope: cdk.Construct, id: string, fargateServiceArn: string): IFargateService {
const serviceName = cdk.Stack.of(scope).parseArn(fargateServiceArn).serviceName;
if (!serviceName) {
throw new Error(`ECS ARN must be in the format 'arn:aws:ecs:<region>:<account>:service/<serviceName>', got: '${fargateServiceArn}'`);
}
class Import extends cdk.Resource implements IFargateService {
public readonly serviceArn = fargateServiceArn;
public readonly serviceName = serviceName
}
return new Import(scope, id);
}
Expand Down

0 comments on commit c18217d

Please sign in to comment.