igor
igor

Reputation: 749

How to configure ElasticBeanstalk to store access logs for classic ELB

I'm using Terraform to provision ElasticBeanstalk application. EC2 instances are placed into auto scaling group and accessed via (classic) Elastic Load Balancer.

Now I need to store access the logs to that load balancer in S3. I see it is possible to do manually from web console (EC2/Load Balancers/Description/Attributes/Access logs). Also Terraform allows to configure access logs for aws_elb (if it is created not by ElasticBeanstalk). However, ElasticBeanstalk does not allow to configure access logs for classic load balancer (see docs) only for application load balancer.

So the question is: how can I configure ElasticBeanstalk to store access logs for classic load balancer?

I realize that I can change the balancer type but I'd like to avoid that.

Upvotes: 1

Views: 972

Answers (1)

guest
guest

Reputation: 46

You can do this by creating an .ebextensions directory in the root of your deployment bundle, and saving a configuration file there. Here's the file that we use, which configures the ELB to save logs every 5 minutes:

Resources:
  AWSEBLoadBalancer:
    Type: AWS::ElasticLoadBalancing::LoadBalancer
    Properties:
      AccessLoggingPolicy:
        EmitInterval: 5
        Enabled: true
        S3BucketName: "example-elb-logs"
        S3BucketPrefix: { "Fn::Sub" : "example/${AWSEBEnvironmentName}" }

If you're thinking "this looks a lot like a CloudFormation template" you're right: Beanstalk adds the fragments in this directory to its base template.

For more information on .ebextensions: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html

Upvotes: 3

Related Questions