Skip to main content

Integration actions for AWS ElasticLoadBalancingV2

Project description

Actions for AWS Elastic Load Balancing V2

---

cdk-constructs: Stable


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:

import aws_cdk.aws_cognito as cognito
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_elasticloadbalancingv2 as elbv2
from aws_cdk.core import App, CfnOutput, Stack
from constructs import Construct
import aws_cdk.aws_elasticloadbalancingv2_actions as actions

Stack): lb = elbv2.ApplicationLoadBalancer(self, "LB",
    vpc=vpc,
    internet_facing=True
)

user_pool = cognito.UserPool(self, "UserPool")
user_pool_client = cognito.UserPoolClient(self, "Client",
    user_pool=user_pool,

    # Required minimal configuration for use with an ELB
    generate_secret=True,
    auth_flows=cognito.AuthFlow(
        user_password=True
    ),
    o_auth=cognito.OAuthSettings(
        flows=cognito.OAuthFlows(
            authorization_code_grant=True
        ),
        scopes=[cognito.OAuthScope.EMAIL],
        callback_urls=[f"https://{lb.loadBalancerDnsName}/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 = cognito.UserPoolDomain(self, "Domain",
    user_pool=user_pool,
    cognito_domain=cognito.CognitoDomainOptions(
        domain_prefix="test-cdk-prefix"
    )
)

lb.add_listener("Listener",
    port=443,
    certificates=[certificate],
    default_action=actions.AuthenticateCognitoAction(
        user_pool=user_pool,
        user_pool_client=user_pool_client,
        user_pool_domain=user_pool_domain,
        next=elbv2.ListenerAction.fixed_response(200,
            content_type="text/plain",
            message_body="Authenticated"
        )
    )
)

CfnOutput(self, "DNS",
    value=lb.load_balancer_dns_name
)

app = App()
CognitoStack(app, "integ-cognito")
app.synth()

NOTE: this example seems incomplete, I was not able to get the redirect back to the Load Balancer after authentication working. Would love some pointers on what a full working setup actually looks like!

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file aws-cdk.aws-elasticloadbalancingv2-actions-1.187.0.tar.gz.

File metadata

File hashes

Hashes for aws-cdk.aws-elasticloadbalancingv2-actions-1.187.0.tar.gz
Algorithm Hash digest
SHA256 9a916106cce573151cc27cb607d2c49088aa97e0113d2da6f247ca27832ab485
MD5 f13f6811ecd3d0c59bab82836706b58a
BLAKE2b-256 ac5c31e80b03390659e3770048a7616e9164a300f99a54d13e800305399a5a75

See more details on using hashes here.

File details

Details for the file aws_cdk.aws_elasticloadbalancingv2_actions-1.187.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_cdk.aws_elasticloadbalancingv2_actions-1.187.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9e7e14ce3d4794ac99982ef631b370514e14e845e84e091c8f07679c2d67078f
MD5 dfd24e017762d09a73e86ea4a85c4710
BLAKE2b-256 737cb7469af18ea6b7d3cc238537581c6598eb0a36dd2fd61e6846de0b8089af

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page