Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mats16 committed Dec 1, 2022
1 parent aa40e1e commit c1ef473
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/ecs-patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { NetworkLoadBalancedTaskImageOptions } from 'aws-cdk-lib/aws-ecs-pattern
import * as elb from 'aws-cdk-lib/aws-elasticloadbalancingv2';
//import * as iam from 'aws-cdk-lib/aws-iam';
import * as logs from 'aws-cdk-lib/aws-logs';
//import * as servicediscovery from 'aws-cdk-lib/aws-servicediscovery';
import * as servicediscovery from 'aws-cdk-lib/aws-servicediscovery';
import { Construct } from 'constructs';
import { AuthProvider } from './supabase-auth-provider';
import { SupabaseDatabase } from './supabase-db';
Expand All @@ -21,6 +21,7 @@ export interface BaseFargateServiceProps {
serviceName?: string;
cluster: ecs.ICluster;
taskImageOptions: SupabaseTaskImageOptions;
enableCloudMap?: boolean;
}

export interface AutoScalingFargateServiceProps extends BaseFargateServiceProps {
Expand All @@ -42,8 +43,10 @@ export class BaseFargateService extends Construct {

const serviceName = props.serviceName || id.toLowerCase();
const { cluster, taskImageOptions } = props;
const enableCloudMap = (typeof props.enableCloudMap == 'undefined') ? false : props.enableCloudMap;

this.listenerPort = taskImageOptions.containerPort;
this.endpoint = `http://${serviceName}.${cluster.defaultCloudMapNamespace?.namespaceName}:${this.listenerPort}`;

const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
runtimePlatform: {
Expand Down Expand Up @@ -88,15 +91,15 @@ export class BaseFargateService extends Construct {
logDriver,
});

this.endpoint = `http://${serviceName}.${cluster.defaultCloudMapNamespace?.namespaceName}:${this.listenerPort}`;

//const cloudMapService = this.service.enableCloudMap({
// name: this.serviceName,
// dnsRecordType: servicediscovery.DnsRecordType.SRV,
// container: appContainer,
// dnsTtl: cdk.Duration.seconds(10),
//});
//(cloudMapService.node.defaultChild as servicediscovery.CfnService).addPropertyOverride('DnsConfig.DnsRecords.1', { Type: 'A', TTL: 10 });
if (enableCloudMap) {
const cloudMapService = this.service.enableCloudMap({
name: serviceName,
dnsRecordType: servicediscovery.DnsRecordType.SRV,
container: appContainer,
dnsTtl: cdk.Duration.seconds(10),
});
(cloudMapService.node.defaultChild as servicediscovery.CfnService).addPropertyOverride('DnsConfig.DnsRecords.1', { Type: 'A', TTL: 10 });
}
}

addApplicationLoadBalancer(props: { healthCheck?: elb.HealthCheck }) {
Expand Down

0 comments on commit c1ef473

Please sign in to comment.