@@ -5,7 +5,7 @@ import { NetworkLoadBalancedTaskImageOptions } from 'aws-cdk-lib/aws-ecs-pattern
55import * as elb from 'aws-cdk-lib/aws-elasticloadbalancingv2' ;
66//import * as iam from 'aws-cdk-lib/aws-iam';
77import * as logs from 'aws-cdk-lib/aws-logs' ;
8- // import * as servicediscovery from 'aws-cdk-lib/aws-servicediscovery';
8+ import * as servicediscovery from 'aws-cdk-lib/aws-servicediscovery' ;
99import { Construct } from 'constructs' ;
1010import { AuthProvider } from './supabase-auth-provider' ;
1111import { SupabaseDatabase } from './supabase-db' ;
@@ -21,6 +21,7 @@ export interface BaseFargateServiceProps {
2121 serviceName ?: string ;
2222 cluster : ecs . ICluster ;
2323 taskImageOptions : SupabaseTaskImageOptions ;
24+ enableCloudMap ?: boolean ;
2425}
2526
2627export interface AutoScalingFargateServiceProps extends BaseFargateServiceProps {
@@ -42,8 +43,10 @@ export class BaseFargateService extends Construct {
4243
4344 const serviceName = props . serviceName || id . toLowerCase ( ) ;
4445 const { cluster, taskImageOptions } = props ;
46+ const enableCloudMap = ( typeof props . enableCloudMap == 'undefined' ) ? false : props . enableCloudMap ;
4547
4648 this . listenerPort = taskImageOptions . containerPort ;
49+ this . endpoint = `http://${ serviceName } .${ cluster . defaultCloudMapNamespace ?. namespaceName } :${ this . listenerPort } ` ;
4750
4851 const taskDefinition = new ecs . FargateTaskDefinition ( this , 'TaskDef' , {
4952 runtimePlatform : {
@@ -88,15 +91,15 @@ export class BaseFargateService extends Construct {
8891 logDriver,
8992 } ) ;
9093
91- this . endpoint = `http:// ${ serviceName } . ${ cluster . defaultCloudMapNamespace ?. namespaceName } : ${ this . listenerPort } ` ;
92-
93- //const cloudMapService = this.service.enableCloudMap({
94- // name: this.serviceName ,
95- // dnsRecordType: servicediscovery.DnsRecordType.SRV ,
96- // container: appContainer ,
97- // dnsTtl: cdk.Duration.seconds(10),
98- // });
99- //(cloudMapService.node.defaultChild as servicediscovery.CfnService).addPropertyOverride('DnsConfig.DnsRecords.1', { Type: 'A', TTL: 10 });
94+ if ( enableCloudMap ) {
95+ const cloudMapService = this . service . enableCloudMap ( {
96+ name : serviceName ,
97+ dnsRecordType : servicediscovery . DnsRecordType . SRV ,
98+ container : appContainer ,
99+ dnsTtl : cdk . Duration . seconds ( 10 ) ,
100+ } ) ;
101+ ( cloudMapService . node . defaultChild as servicediscovery . CfnService ) . addPropertyOverride ( 'DnsConfig.DnsRecords.1' , { Type : 'A' , TTL : 10 } ) ;
102+ }
100103 }
101104
102105 addApplicationLoadBalancer ( props : { healthCheck ?: elb . HealthCheck } ) {
0 commit comments