Skip to content

Commit

Permalink
davidchristiansen/LoadBalancedFargateService-ContainerNameAndRoleOver…
Browse files Browse the repository at this point in the history
…ridesImplemenation of execution tests, task role andcontainer name overrides + tests
  • Loading branch information
DavidChristiansen committed Jun 10, 2019
1 parent 523807c commit 2b5cdba
Show file tree
Hide file tree
Showing 4 changed files with 905 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import ecs = require('@aws-cdk/aws-ecs');
import iam = require('@aws-cdk/aws-iam');
import { AliasRecord, IHostedZone } from '@aws-cdk/aws-route53';
import { AddressRecordTarget, ARecord, IHostedZone } from '@aws-cdk/aws-route53';
import targets = require('@aws-cdk/aws-route53-targets');
import cdk = require('@aws-cdk/cdk');
Expand Down Expand Up @@ -72,6 +74,34 @@ export interface LoadBalancedFargateServiceProps extends LoadBalancedServiceBase
* @default true
*/
readonly createLogs?: boolean;

/**
* 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 @@ -89,12 +119,16 @@ export class LoadBalancedFargateService extends LoadBalancedServiceBase {

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

const optIn = props.createLogs !== undefined ? props.createLogs : true;

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

const container = taskDefinition.addContainer(containerName, {
image: props.image,
logging: optIn ? this.createAWSLogDriver(this.node.id) : undefined,
environment: props.environment
Expand All @@ -109,7 +143,8 @@ export class LoadBalancedFargateService extends LoadBalancedServiceBase {
cluster: props.cluster,
desiredCount: props.desiredCount || 1,
taskDefinition,
assignPublicIp
assignPublicIp,
serviceName: props.serviceName || undefined
});
this.service = service;

Expand Down
Loading

0 comments on commit 2b5cdba

Please sign in to comment.