Skip navigation links

Package software.amazon.awscdk.services.elasticloadbalancingv2.actions

Actions for AWS Elastic Load Balancing V2

See: Description

Package software.amazon.awscdk.services.elasticloadbalancingv2.actions Description

Actions for AWS Elastic Load Balancing V2

This package contains integration actions for ELBv2. See the README of the @aws-cdk/aws-elasticloadbalancingv2 library.

Cognito

ELB allows for requests to be authenticated against a Cognito user pool using the AuthenticateCognitoAction. For details on the setup's requirements, read Prepare to use Amazon Cognito. Here's an example:

 // Example automatically generated from non-compiling source. May contain errors.
 Object lb = ApplicationLoadBalancer.Builder.create(this, "LB")
         .vpc(vpc)
         .internetFacing(true)
         .build();
 
 Object userPool = new UserPool(this, "UserPool");
 Object userPoolClient = UserPoolClient.Builder.create(this, "Client")
         .userPool(userPool)
 
         // Required minimal configuration for use with an ELB
         .generateSecret(true)
         .authFlows(Map.of(
                 "userPassword", true))
         .oAuth(Map.of(
                 "flows", Map.of(
                         "authorizationCodeGrant", true),
                 "scopes", List.of(cognito.getOAuthScope().getEMAIL()),
                 "callbackUrls", List.of(String.format("https://%s/oauth2/idpresponse", lb.getLoadBalancerDnsName()))))
         .build();
 Object cfnClient = (Object)userPoolClient.getNode().getDefaultChild();
 cfnClient.addPropertyOverride("RefreshTokenValidity", 1);
 cfnClient.addPropertyOverride("SupportedIdentityProviders", List.of("COGNITO"));
 
 Object userPoolDomain = UserPoolDomain.Builder.create(this, "Domain")
         .userPool(userPool)
         .cognitoDomain(Map.of(
                 "domainPrefix", "test-cdk-prefix"))
         .build();
 
 lb.addListener("Listener", Map.of(
         "port", 443,
         "certificates", List.of(certificate),
         "defaultAction", AuthenticateCognitoAction.Builder.create()
                 .userPool(userPool)
                 .userPoolClient(userPoolClient)
                 .userPoolDomain(userPoolDomain)
                 .next(elbv2.ListenerAction.fixedResponse(200, Map.of(
                         "contentType", "text/plain",
                         "messageBody", "Authenticated")))
                 .build()));
 
 CfnOutput.Builder.create(this, "DNS")
         .value(lb.getLoadBalancerDnsName())
         .build();
 
Skip navigation links

Copyright © 2022. All rights reserved.