Amazon ELB不能打破双向TLS身份验证,但是要实现该功能需要进行适当的配置。可以使用AWS Certificate Manager (ACM)配置证书或自己提供证书,并在ELB上启用TLS监听器。以下是使用Python和Boto3 SDK创建ELB以实现TLS身份验证的示例代码:
import boto3
# Create ELB client
elb = boto3.client('elbv2')
# Configure the certificate
certificate_arn = 'arn:aws:acm:us-east-1:123456789012:certificate/01234567-89ab-cdef-0123-456789abcdef'
# Define target groups and listeners
target_groups = [
{
'TargetType': 'instance',
'Protocol': 'HTTP',
'Port': 80
}
]
listeners = [
{
'Protocol': 'HTTPS',
'Port': 443,
'TLSCertificate': certificate_arn,
'DefaultActions': [
{
'Type': 'forward',
'TargetGroupArn': target_groups[0]['Arn']
}
]
}
]
# Create the ELB
response = elb.create_load_balancer(
Name='my-elb',
Scheme='internet-facing',
Type='application',
IpAddressType='ipv4',
SubnetMappings=[
{
'SubnetId': 'subnet-12345678',
'AllocationId': 'eipalloc-0123456789abcdef0'
}
],
SecurityGroups=[
'sg-0123456789abcdef0'
],
Tags=[
{
'Key': 'Name',
'Value': 'my-elb'
}
]
)
# Add target groups and listeners to the ELB
elb.create_target_group(
Name='my-target-group',
Protocol=target_groups[0]['Protocol'],
Port=target_groups[0]['Port'],
TargetType=target_groups[0]['TargetType'],
VpcId='vpc-0123456789abcdef0'
)
elb.create_listener(
LoadBalancerArn=response['LoadBalancers'][0]['LoadBalancerArn'],
Protocol=listeners[0]['Protocol'],
Port=listeners[0]['Port'],
Certificates=[
{
'CertificateArn': listeners[0]['TLSCertificate']
}
],
DefaultActions=listeners[0]['DefaultActions']
)