gpt4 book ai didi

aws-cdk - 为通过 CDK 实例化的 Elastic Beanstalk 环境获取 Application Load Balancer 的句柄

转载 作者:行者123 更新时间:2023-12-04 04:17:03 25 4
gpt4 key购买 nike

我像这样创建了一个 Elastic Beanstalk 环境:

    const certificate = new certificatemanager.Certificate(this, 'Certificate', {
domainName: props.domainName,
subjectAlternativeNames: [],
validationMethod: certificatemanager.ValidationMethod.EMAIL,
});

const optionSettings = {
'aws:autoscaling:asg': {
MinSize: '2',
MaxSize: '2',
},
'aws:ec2:vpc': {
VPCId: vpc.vpcId,
Subnets: vpc.privateSubnets.map((subnet) => subnet.subnetId).join(','),
ElbSubnets: vpc.publicSubnets.map((subnet) => subnet.subnetId).join(','),
},
'aws:elasticbeanstalk:environment': {
EnvironmentType: 'LoadBalanced',
LoadBalancerType: 'application',
},
'aws:elbv2:listener:443': {
ListenerEnabled: 'true',
Protocol: 'HTTPS',
SSLCertificateArns: certificate.certificateArn,
},
'aws:autoscaling:launchconfiguration': {
IamInstanceProfile: 'aws-elasticbeanstalk-ec2-role',
InstanceType: 't3.medium',
},
'aws:elasticbeanstalk:application:environment': {
CORS_ORIGIN_ALLOW_ALL: 'False',
},
};

const environment = new elasticbeanstalk.CfnEnvironment(this, 'Environment', {
environmentName: `env`,
description: 'My Environment Description',
applicationName: application.applicationName || 'Error',
versionLabel: applicationVersion.ref,
solutionStackName: '64bit Amazon Linux 2018.03 v2.9.5 running Python 3.6',
optionSettings: OptionSettingsUtil.flatten(optionSettings),
});

其中 OptionSettingsUtil.flatten 是我编写的用于展平配置选项的自定义函数。

如何获取将由此 Elastic Beanstalk 环境生成的 Application Load Balancer 资源的句柄?我需要它将 WAF ACL 与其相关联。

最佳答案

在实际创建之前你不能,然后你可以按如下方式查找它:

const loadBalancer = elbv2.ApplicationLoadBalancer.fromLookup(this, 'ALB', {
loadBalancerTags: {
'elasticbeanstalk:environment-name': environmentName
},
})

文档:https://docs.aws.amazon.com/cdk/api/latest/docs/aws-elasticloadbalancingv2-readme.html#looking-up-load-balancers-and-listeners

关于aws-cdk - 为通过 CDK 实例化的 Elastic Beanstalk 环境获取 Application Load Balancer 的句柄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60532956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com