Namespace Amazon.CDK.AWS.ElasticLoadBalancingV2.Actions
Actions for AWS Elastic Load Balancing V2
This package contains integration actions for ELBv2. See the README of the aws-cdk-lib/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:
using Amazon.CDK.AWS.CertificateManager;
Vpc vpc;
Certificate certificate;
var lb = new ApplicationLoadBalancer(this, "LB", new ApplicationLoadBalancerProps {
Vpc = vpc,
InternetFacing = true
});
var userPool = new UserPool(this, "UserPool");
var userPoolClient = new UserPoolClient(this, "Client", new UserPoolClientProps {
UserPool = userPool,
// Required minimal configuration for use with an ELB
GenerateSecret = true,
AuthFlows = new AuthFlow {
UserPassword = true
},
OAuth = new OAuthSettings {
Flows = new OAuthFlows {
AuthorizationCodeGrant = true
},
Scopes = new [] { OAuthScope.EMAIL },
CallbackUrls = new [] { $"https://{lb.loadBalancerDnsName}/oauth2/idpresponse" }
}
});
var cfnClient = (CfnUserPoolClient)userPoolClient.Node.DefaultChild;
cfnClient.AddPropertyOverride("RefreshTokenValidity", 1);
cfnClient.AddPropertyOverride("SupportedIdentityProviders", new [] { "COGNITO" });
var userPoolDomain = new UserPoolDomain(this, "Domain", new UserPoolDomainProps {
UserPool = userPool,
CognitoDomain = new CognitoDomainOptions {
DomainPrefix = "test-cdk-prefix"
}
});
lb.AddListener("Listener", new BaseApplicationListenerProps {
Port = 443,
Certificates = new [] { certificate },
DefaultAction = new AuthenticateCognitoAction(new AuthenticateCognitoActionProps {
UserPool = userPool,
UserPoolClient = userPoolClient,
UserPoolDomain = userPoolDomain,
Next = ListenerAction.FixedResponse(200, new FixedResponseOptions {
ContentType = "text/plain",
MessageBody = "Authenticated"
})
})
});
new CfnOutput(this, "DNS", new CfnOutputProps {
Value = lb.LoadBalancerDnsName
});
Classes
AuthenticateCognitoAction | A Listener Action to authenticate with Cognito. |
AuthenticateCognitoActionProps | Properties for AuthenticateCognitoAction. |
Interfaces
IAuthenticateCognitoActionProps | Properties for AuthenticateCognitoAction. |