Skip to content

Commit

Permalink
fix(aws-ecs): propagate dnsTtl property part of cloudMapOptions (#6370)
Browse files Browse the repository at this point in the history
Fixes #6223
  • Loading branch information
efekarakus committed Feb 19, 2020
1 parent b47eccc commit 747bdb2
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/base/base-service.ts
Expand Up @@ -514,7 +514,8 @@ export abstract class BaseService extends Resource
namespace: sdNamespace,
name: options.name,
dnsRecordType: dnsRecordType!,
customHealthCheck: { failureThreshold: options.failureThreshold || 1 }
customHealthCheck: { failureThreshold: options.failureThreshold || 1 },
dnsTtl: options.dnsTtl,
});

const serviceArn = cloudmapService.serviceArn;
Expand Down
66 changes: 64 additions & 2 deletions packages/@aws-cdk/aws-ecs/test/fargate/test.fargate-service.ts
Expand Up @@ -1334,7 +1334,7 @@ export = {
test.done();
},

'creates AWS Cloud Map service for Private DNS namespace with SRV records'(test: Test) {
'creates AWS Cloud Map service for Private DNS namespace with SRV records with proper defaults'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
Expand All @@ -1359,7 +1359,7 @@ export = {
taskDefinition,
cloudMapOptions: {
name: 'myApp',
dnsRecordType: cloudmap.DnsRecordType.SRV
dnsRecordType: cloudmap.DnsRecordType.SRV,
}
});

Expand Down Expand Up @@ -1394,6 +1394,68 @@ export = {

test.done();
},

'creates AWS Cloud Map service for Private DNS namespace with SRV records with overriden defaults'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const vpc = new ec2.Vpc(stack, 'MyVpc', {});
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
cluster.addCapacity('DefaultAutoScalingGroup', { instanceType: new ec2.InstanceType('t2.micro') });

const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef');
const container = taskDefinition.addContainer('MainContainer', {
image: ecs.ContainerImage.fromRegistry('hello'),
memoryLimitMiB: 512
});
container.addPortMappings({ containerPort: 8000 });

// WHEN
cluster.addDefaultCloudMapNamespace({
name: 'foo.com',
type: cloudmap.NamespaceType.DNS_PRIVATE
});

new ecs.FargateService(stack, 'Service', {
cluster,
taskDefinition,
cloudMapOptions: {
name: 'myApp',
dnsRecordType: cloudmap.DnsRecordType.SRV,
dnsTtl: cdk.Duration.seconds(10),
}
});

// THEN
expect(stack).to(haveResource('AWS::ServiceDiscovery::Service', {
DnsConfig: {
DnsRecords: [
{
TTL: 10,
Type: "SRV"
}
],
NamespaceId: {
'Fn::GetAtt': [
'EcsClusterDefaultServiceDiscoveryNamespaceB0971B2F',
'Id'
]
},
RoutingPolicy: 'MULTIVALUE'
},
HealthCheckCustomConfig: {
FailureThreshold: 1
},
Name: "myApp",
NamespaceId: {
'Fn::GetAtt': [
'EcsClusterDefaultServiceDiscoveryNamespaceB0971B2F',
'Id'
]
}
}));

test.done();
},
},

'Metric'(test: Test) {
Expand Down

0 comments on commit 747bdb2

Please sign in to comment.