amazon-web-services - AWS CDK : enabling access logging for classical load balancer

标签 amazon-web-services aws-cdk amazon-elb

我们在通过 CDK 部署的基础设施中使用经典负载均衡器。为了部署负载均衡器,我们使用 2 级构造。代码是这样的:

const lb = new elb.LoadBalancer(this, 'LB', {
            vpc: vpcRef,
            
            internetFacing: true,
            healthCheck: {
                port: 80
            },
        
        });
        
        
        lb.addListener({
            externalPort: 80,
        });
    }

我们无法找到任何可以启用访问日志记录的属性。有人建议我使用 AccessLoggingPolicyProperty。我检查了一下,发现该属性只能与 1 级构造一起使用。请指导我如何使用 2 级结构在经典负载均衡器上通过 CDK 启用访问日志。

最佳答案

根据 the documentation您需要配置正确权限的 S3 存储桶。这样您就可以关注aws-cdk documentation on how to get access to L1构造。

它看起来大致像下面的代码

const lbLogs = new Bucket(this, 'LB Logs');

const elbAccountId = 'TODO: find right account for you region in docs';

lbLogs.grantPut(new AccountPrincipal(elbAccountId));

lbLogs.grantPut(
  new ServicePrincipal('delivery.logs.amazonaws.com', {
    conditions: {
      StringEquals: {
        's3:x-amz-acl': 'bucket-owner-full-control',
      },
    },
  })
);

lbLogs.grantRead(new ServicePrincipal('delivery.logs.amazonaws.com'));

const cfnLoadBalancer = lb.node.defaultChild as CfnLoadBalancer;
cfnLoadBalancer.accessLoggingPolicy = {
  enabled: true,
  s3BucketName: lbLogs.bucketName,
};

关于amazon-web-services - AWS CDK : enabling access logging for classical load balancer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67821495/

相关文章:

aws-cloudformation - ECS TaskDefinition 创建失败,出现 "Invalid request provided: Create TaskDefinition: Unknown volume ' null'。”

Terraform如何获取aws_lb的IP地址

amazon-web-services - 无服务器错误,当自定义命名资源需要替换时,CloudFormation 无法更新堆栈

amazon-web-services - Elasticsearch 6.1 EC2 集群发现不工作

amazon-web-services - AWS Fargate无法删除集群

amazon-web-services - 有没有办法使用AWS CDK指定cloudformation堆栈删除策略?

aws-cdk - 与现有代码管道一起使用的 AWS CDK 管道

django.request : Forbidden (Referer checking failed - no Referer. )

amazon-web-services - ELB 监听器协议(protocol)和证书正在重置

node.js - 适用于 Node.js 的 AWS S3 SDK V3 - GetObjectCommand v/s getSignedUrl