Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-ecs): propagate the dnsTtl property when defining cloudMapOptions for an ecs service #6370

Merged
merged 1 commit into from Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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