@@ -577,6 +577,7 @@ export class Service extends pulumi.ComponentResource implements cloud.Service {
577
577
public readonly ecsService : aws . ecs . Service ;
578
578
579
579
public readonly endpoints : pulumi . Output < Endpoints > ;
580
+ public readonly defaultEndpoint : pulumi . Output < Endpoint | undefined > ;
580
581
581
582
public readonly getEndpoint : ( containerName ?: string , containerPort ?: number ) => Promise < cloud . Endpoint > ;
582
583
@@ -661,27 +662,17 @@ export class Service extends pulumi.ComponentResource implements cloud.Service {
661
662
662
663
const localEndpoints = getEndpoints ( ports ) ;
663
664
this . endpoints = localEndpoints ;
665
+ this . defaultEndpoint = localEndpoints . apply ( getDefaultEndpoint ) ;
664
666
665
667
this . getEndpoint = async ( containerName , containerPort ) => {
666
668
const endpoints = localEndpoints . get ( ) ;
667
669
668
- containerName = containerName || Object . keys ( endpoints ) [ 0 ] ;
669
- if ( ! containerName ) {
670
- throw new Error ( `No containers available in this service ` ) ;
670
+ const defaultEndpoint = getDefaultEndpoint ( endpoints , containerName , containerPort ) ;
671
+ if ( ! defaultEndpoint ) {
672
+ throw new Error ( `No endpoint found matching provided container name and port. ` ) ;
671
673
}
672
674
673
- const containerPorts = endpoints [ containerName ] || { } ;
674
- containerPort = containerPort || + Object . keys ( containerPorts ) [ 0 ] ;
675
- if ( ! containerPort ) {
676
- throw new Error ( `No ports available in service container ${ containerName } ` ) ;
677
- }
678
-
679
- const endpoint = containerPorts [ containerPort ] ;
680
- if ( ! endpoint ) {
681
- throw new Error ( `No exposed port for ${ containerName } port ${ containerPort } ` ) ;
682
- }
683
-
684
- return endpoint ;
675
+ return defaultEndpoint ;
685
676
} ;
686
677
}
687
678
}
@@ -698,6 +689,26 @@ function getEndpoints(ports: ExposedPorts): pulumi.Output<Endpoints> {
698
689
} ) ) ;
699
690
}
700
691
692
+ function getDefaultEndpoint ( endpoints : Endpoints , containerName ?: string , containerPort ?: number ) : Endpoint | undefined {
693
+ containerName = containerName || Object . keys ( endpoints ) [ 0 ] ;
694
+ if ( ! containerName ) {
695
+ return ;
696
+ }
697
+
698
+ const containerPorts = endpoints [ containerName ] || { } ;
699
+ containerPort = containerPort || + Object . keys ( containerPorts ) [ 0 ] ;
700
+ if ( ! containerPort ) {
701
+ return ;
702
+ }
703
+
704
+ const endpoint = containerPorts [ containerPort ] ;
705
+ if ( ! endpoint ) {
706
+ return ;
707
+ }
708
+
709
+ return endpoint ;
710
+ }
711
+
701
712
const volumeNames = new Set < string > ( ) ;
702
713
703
714
export interface Volume extends cloud . Volume {
0 commit comments