Skip to content

Instantly share code, notes, and snippets.

@dukelion
Last active March 13, 2018 08:01
Show Gist options
  • Save dukelion/7e1d582b6a5d05496c20d11e3804d25d to your computer and use it in GitHub Desktop.
Save dukelion/7e1d582b6a5d05496c20d11e3804d25d to your computer and use it in GitHub Desktop.
Make sure ELB access logs enabled for MQ
#!/usr/bin/env python
import boto3
from os import getenv
region = getenv('AWS_REGION','us-east-1')
ec2 = boto3.client('elbv2', region_name=region)
response = ec2.describe_load_balancers()
grepAccessLogParam = lambda x: x['Key'] == 'access_logs.s3.enabled'
grepAccessLogBucket = lambda x: x['Key'] == 'access_logs.s3.bucket'
logsBucket = {
'us-east-1': 'iron-alb-logs',
'eu-west-1': 'iron-alb-logs-eu',
'us-west-2': 'iron-alb-logs-us-west-2',
}
attrTemplate = [
{
'Key': 'access_logs.s3.bucket',
'Value': logsBucket[region]
},
{
'Key': 'access_logs.s3.enabled',
'Value': 'true'
},
{
'Key': 'access_logs.s3.prefix',
'Value': ''
},
]
for elb in response['LoadBalancers']:
if elb['LoadBalancerName'][:3] == 'mq-':
attr = ec2.describe_load_balancer_attributes(LoadBalancerArn=elb['LoadBalancerArn'])['Attributes']
accessLogEnabled = filter(grepAccessLogParam,attr)[0]['Value']
if accessLogEnabled == 'true':
print ("%s: %s\n"%(elb['LoadBalancerName'], filter(grepAccessLogBucket,attr)[0]['Value']))
else:
print (elb['LoadBalancerName'])
setAttr = attrTemplate
setAttr[2]['Value'] = elb['LoadBalancerName']
ec2.modify_load_balancer_attributes(LoadBalancerArn=elb['LoadBalancerArn'],Attributes=setAttr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment