Skip to content

Commit

Permalink
feat(ecs-patterns): LoadBalancedFargateService - allow specifying con…
Browse files Browse the repository at this point in the history
…tainerName and role (#2764)

Implementation of execution tests, task role and container name overrides + tests
  • Loading branch information
DavidChristiansen authored and Elad Ben-Israel committed Jun 13, 2019
1 parent 849b693 commit df12197
Show file tree
Hide file tree
Showing 4 changed files with 901 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ecs = require('@aws-cdk/aws-ecs');
import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');
import { LoadBalancedServiceBase, LoadBalancedServiceBaseProps } from '../base/load-balanced-service-base';

Expand Down Expand Up @@ -42,6 +43,34 @@ export interface LoadBalancedFargateServiceProps extends LoadBalancedServiceBase
* @default 512
*/
readonly memoryLimitMiB?: number;

/**
* Override for the Fargate Task Definition execution role
*
* @default - No value
*/
readonly executionRole?: iam.IRole;

/**
* Override for the Fargate Task Definition task role
*
* @default - No value
*/
readonly taskRole?: iam.IRole;

/**
* Override value for the container name
*
* @default - No value
*/
readonly containerName?: string;

/**
* Override value for the service name
*
* @default - No value
*/
readonly serviceName?: string;
}

/**
Expand All @@ -59,10 +88,14 @@ export class LoadBalancedFargateService extends LoadBalancedServiceBase {

const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
memoryLimitMiB: props.memoryLimitMiB,
cpu: props.cpu
cpu: props.cpu,
executionRole: props.executionRole !== undefined ? props.executionRole : undefined,
taskRole: props.taskRole !== undefined ? props.taskRole : undefined
});

const container = taskDefinition.addContainer('web', {
const containerName = props.containerName !== undefined ? props.containerName : 'web';

const container = taskDefinition.addContainer(containerName, {
image: props.image,
logging: this.logDriver,
environment: props.environment
Expand All @@ -71,13 +104,13 @@ export class LoadBalancedFargateService extends LoadBalancedServiceBase {
container.addPortMappings({
containerPort: props.containerPort || 80,
});

const assignPublicIp = props.publicTasks !== undefined ? props.publicTasks : false;
const service = new ecs.FargateService(this, "Service", {
cluster: props.cluster,
desiredCount: props.desiredCount || 1,
taskDefinition,
assignPublicIp
assignPublicIp,
serviceName: props.serviceName || undefined
});
this.service = service;

Expand Down
Loading

0 comments on commit df12197

Please sign in to comment.