2 types
This package contains integration actions for ELBv2. See the README of the aws-cdk-lib/aws-elasticloadbalancingv2 library.
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:
require 'aws-cdk-lib'
vpc = nil # AWSCDK::EC2::VPC
certificate = nil # AWSCDK::CertificateManager::Certificate
lb = AWSCDK::ElasticLoadBalancingv2::ApplicationLoadBalancer.new(self, "LB", {
vpc: vpc,
internet_facing: true,
})
user_pool = AWSCDK::Cognito::UserPool.new(self, "UserPool")
user_pool_client = AWSCDK::Cognito::UserPoolClient.new(self, "Client", {
user_pool: user_pool,
# Required minimal configuration for use with an ELB
generate_secret: true,
auth_flows: {
user_password: true,
},
o_auth: {
flows: {
authorization_code_grant: true,
},
scopes: [AWSCDK::Cognito::OAuthScope.EMAIL],
callback_urls: [
"https://#{lb.load_balancer_dns_name}/oauth2/idpresponse",
],
},
})
cfn_client = user_pool_client.node.default_child
cfn_client.add_property_override("RefreshTokenValidity", 1)
cfn_client.add_property_override("SupportedIdentityProviders", ["COGNITO"])
user_pool_domain = AWSCDK::Cognito::UserPoolDomain.new(self, "Domain", {
user_pool: user_pool,
cognito_domain: {
domain_prefix: "test-cdk-prefix",
},
})
lb.add_listener("Listener", {
port: 443,
certificates: [certificate],
default_action: AWSCDK::ElasticLoadBalancingv2Actions::AuthenticateCognitoAction.new({
user_pool: user_pool,
user_pool_client: user_pool_client,
user_pool_domain: user_pool_domain,
_next: AWSCDK::ElasticLoadBalancingv2::ListenerAction.fixed_response(200, {
content_type: "text/plain",
message_body: "Authenticated",
}),
}),
})
AWSCDK::CfnOutput.new(self, "DNS", {
value: lb.load_balancer_dns_name,
})