File tree Expand file tree Collapse file tree 3 files changed +44
-1
lines changed
packages/@aws-cdk/aws-elasticloadbalancingv2 Expand file tree Collapse file tree 3 files changed +44
-1
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,9 @@ lb.addRedirect({
182182
183183If you do not provide any options for this method, it redirects HTTP port 80 to HTTPS port 443.
184184
185+ By default all ingress traffic will be allowed on the source port. If you want to be more selective with your
186+ ingress rules then set ` open: false ` and use the listener's ` connections ` object to selectively grant access to the listener.
187+
185188## Defining a Network Load Balancer
186189
187190Network Load Balancers are defined in a similar way to Application Load
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
119119 return this . addListener ( `Redirect${ sourcePort } To${ targetPort } ` , {
120120 protocol : props . sourceProtocol ?? ApplicationProtocol . HTTP ,
121121 port : sourcePort ,
122- open : true ,
122+ open : props . open ?? true ,
123123 defaultAction : ListenerAction . redirect ( {
124124 port : targetPort ,
125125 protocol : props . targetProtocol ?? ApplicationProtocol . HTTPS ,
@@ -665,4 +665,19 @@ export interface ApplicationLoadBalancerRedirectConfig {
665665 */
666666 readonly targetPort ?: number ;
667667
668+ /**
669+ * Allow anyone to connect to this listener
670+ *
671+ * If this is specified, the listener will be opened up to anyone who can reach it.
672+ * For internal load balancers this is anyone in the same VPC. For public load
673+ * balancers, this is anyone on the internet.
674+ *
675+ * If you want to be more selective about who can access this load
676+ * balancer, set this to `false` and use the listener's `connections`
677+ * object to selectively grant access to the listener.
678+ *
679+ * @default true
680+ */
681+ readonly open ?: boolean ;
682+
668683}
Original file line number Diff line number Diff line change @@ -727,6 +727,31 @@ describe('tests', () => {
727727 } ) ;
728728 } ) ;
729729
730+ test ( 'Can supress default ingress rules on a simple redirect response' , ( ) => {
731+ // GIVEN
732+ const stack = new cdk . Stack ( ) ;
733+ const vpc = new ec2 . Vpc ( stack , 'Stack' ) ;
734+
735+ const loadBalancer = new elbv2 . ApplicationLoadBalancer ( stack , 'LB' , {
736+ vpc,
737+ } ) ;
738+
739+ // WHEN
740+ loadBalancer . addRedirect ( { open : false } ) ;
741+
742+ // THEN
743+ expect ( stack ) . not . toHaveResourceLike ( 'AWS::EC2::SecurityGroup' , {
744+ SecurityGroupIngress : [
745+ {
746+ CidrIp : '0.0.0.0/0' ,
747+ Description : 'Allow from anyone on port 80' ,
748+ IpProtocol : 'tcp' ,
749+ } ,
750+ ] ,
751+ } ) ;
752+
753+ } ) ;
754+
730755 test ( 'Can add simple redirect responses with custom values' , ( ) => {
731756 // GIVEN
732757 const stack = new cdk . Stack ( ) ;
You can’t perform that action at this time.
0 commit comments