Skip to content

Commit aff9a71

Browse files
authored
Merge branch 'master' into cross-account-event-bus
2 parents ca4b28f + fc87574 commit aff9a71

File tree

8 files changed

+92
-15
lines changed

8 files changed

+92
-15
lines changed

packages/@aws-cdk/aws-ec2/lib/cfn-init-elements.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ export abstract class InitFile extends InitElement {
327327
* Use a literal string as the file content
328328
*/
329329
public static fromString(fileName: string, content: string, options: InitFileOptions = {}): InitFile {
330+
if (!content) {
331+
throw new Error(`InitFile ${fileName}: cannot create empty file. Please supply at least one character of content.`);
332+
}
330333
return new class extends InitFile {
331334
protected _doBind(bindOptions: InitBindOptions) {
332335
return {

packages/@aws-cdk/aws-ec2/lib/vpc-endpoint.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ export class InterfaceVpcEndpointAwsService implements IInterfaceVpcEndpointServ
287287
public static readonly KMS = new InterfaceVpcEndpointAwsService('kms');
288288
public static readonly CLOUDWATCH_LOGS = new InterfaceVpcEndpointAwsService('logs');
289289
public static readonly CLOUDWATCH = new InterfaceVpcEndpointAwsService('monitoring');
290+
public static readonly RDS = new InterfaceVpcEndpointAwsService('rds');
290291
public static readonly SAGEMAKER_API = new InterfaceVpcEndpointAwsService('sagemaker.api');
291292
public static readonly SAGEMAKER_RUNTIME = new InterfaceVpcEndpointAwsService('sagemaker.runtime');
292293
public static readonly SAGEMAKER_RUNTIME_FIPS = new InterfaceVpcEndpointAwsService('sagemaker.runtime-fips');

packages/@aws-cdk/aws-ec2/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@
233233
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.KINESIS_STREAMS",
234234
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.KINESIS_FIREHOSE",
235235
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.KMS",
236+
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.RDS",
236237
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.SAGEMAKER_API",
237238
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.SAGEMAKER_NOTEBOOK",
238239
"docs-public-apis:@aws-cdk/aws-ec2.InterfaceVpcEndpointAwsService.SAGEMAKER_RUNTIME",

packages/@aws-cdk/aws-ec2/test/cfn-init-element.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ describe('InitFile', () => {
206206
});
207207
});
208208

209+
test('empty content string throws error', () => {
210+
expect(() => {
211+
ec2.InitFile.fromString('/tmp/foo', '');
212+
}).toThrow('InitFile /tmp/foo: cannot create empty file. Please supply at least one character of content.');
213+
});
214+
209215
test('symlink throws an error if mode is set incorrectly', () => {
210216
expect(() => {
211217
ec2.InitFile.symlink('/tmp/foo', '/tmp/bar', {

packages/@aws-cdk/aws-ecs/lib/ec2/ec2-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,9 @@ export class Ec2Service extends BaseService implements IEc2Service {
229229
this.addPlacementConstraints(...props.placementConstraints || []);
230230
this.addPlacementStrategies(...props.placementStrategies || []);
231231

232-
if (!this.taskDefinition.defaultContainer) {
233-
throw new Error('A TaskDefinition must have at least one essential container');
234-
}
232+
this.node.addValidation({
233+
validate: () => !this.taskDefinition.defaultContainer ? ['A TaskDefinition must have at least one essential container'] : [],
234+
});
235235
}
236236

237237
/**

packages/@aws-cdk/aws-ecs/lib/fargate/fargate-service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ export class FargateService extends BaseService implements IFargateService {
172172

173173
this.configureAwsVpcNetworkingWithSecurityGroups(props.cluster.vpc, props.assignPublicIp, props.vpcSubnets, securityGroups);
174174

175-
if (!props.taskDefinition.defaultContainer) {
176-
throw new Error('A TaskDefinition must have at least one essential container');
177-
}
175+
this.node.addValidation({
176+
validate: () => !this.taskDefinition.defaultContainer ? ['A TaskDefinition must have at least one essential container'] : [],
177+
});
178178
}
179179
}
180180

packages/@aws-cdk/aws-ecs/test/ec2/ec2-service.test.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, haveResource } from '@aws-cdk/assert';
1+
import { expect, haveResource, haveResourceLike } from '@aws-cdk/assert';
22
import * as ec2 from '@aws-cdk/aws-ec2';
33
import * as elb from '@aws-cdk/aws-elasticloadbalancing';
44
import * as elbv2 from '@aws-cdk/aws-elasticloadbalancingv2';
@@ -541,14 +541,48 @@ nodeunitShim({
541541
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
542542
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
543543

544+
// Errors on validation, not on construction.
545+
new ecs.Ec2Service(stack, 'Ec2Service', {
546+
cluster,
547+
taskDefinition,
548+
});
549+
544550
// THEN
545551
test.throws(() => {
546-
new ecs.Ec2Service(stack, 'Ec2Service', {
547-
cluster,
548-
taskDefinition,
549-
});
552+
expect(stack);
553+
}, /one essential container/);
554+
555+
test.done();
556+
},
557+
558+
'allows adding the default container after creating the service'(test: Test) {
559+
// GIVEN
560+
const stack = new cdk.Stack();
561+
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
562+
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
563+
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });
564+
const taskDefinition = new ecs.Ec2TaskDefinition(stack, 'Ec2TaskDef');
565+
566+
new ecs.Ec2Service(stack, 'FargateService', {
567+
cluster,
568+
taskDefinition,
550569
});
551570

571+
// Add the container *after* creating the service
572+
taskDefinition.addContainer('main', {
573+
image: ecs.ContainerImage.fromRegistry('somecontainer'),
574+
memoryReservationMiB: 10,
575+
});
576+
577+
// THEN
578+
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
579+
ContainerDefinitions: [
580+
{
581+
Name: 'main',
582+
},
583+
],
584+
}));
585+
552586
test.done();
553587
},
554588

packages/@aws-cdk/aws-ecs/test/fargate/fargate-service.test.ts

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,14 +482,46 @@ nodeunitShim({
482482
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
483483
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');
484484

485+
// Errors on validation, not on construction.
486+
new ecs.FargateService(stack, 'FargateService', {
487+
cluster,
488+
taskDefinition,
489+
});
490+
485491
// THEN
486492
test.throws(() => {
487-
new ecs.FargateService(stack, 'FargateService', {
488-
cluster,
489-
taskDefinition,
490-
});
493+
expect(stack);
494+
}, /one essential container/);
495+
496+
test.done();
497+
},
498+
499+
'allows adding the default container after creating the service'(test: Test) {
500+
// GIVEN
501+
const stack = new cdk.Stack();
502+
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
503+
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
504+
const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');
505+
506+
new ecs.FargateService(stack, 'FargateService', {
507+
cluster,
508+
taskDefinition,
491509
});
492510

511+
// Add the container *after* creating the service
512+
taskDefinition.addContainer('main', {
513+
image: ecs.ContainerImage.fromRegistry('somecontainer'),
514+
});
515+
516+
// THEN
517+
expect(stack).to(haveResourceLike('AWS::ECS::TaskDefinition', {
518+
ContainerDefinitions: [
519+
{
520+
Name: 'main',
521+
},
522+
],
523+
}));
524+
493525
test.done();
494526
},
495527

0 commit comments

Comments
 (0)