in subfunctions/ALE_cleanup_single.py [0:0]
def vpcflow_cleanup():
"""Function to clean up VPC Flow Logs"""
logging.info("Cleaning up VPC Flow Logs created by Assisted Log Enabler for AWS.")
for aws_region in region_list:
try:
logging.info("---- LINE BREAK BETWEEN REGIONS ----")
logging.info("Cleaning up VPC Flow Logs created by Assisted Log Enabler for AWS in region " + aws_region + ".")
removal_list: list = []
ec2 = boto3.client('ec2', region_name=aws_region)
logging.info("DescribeFlowLogs API Call")
vpc_flow_logs = ec2.describe_flow_logs(
Filter=[
{
'Name': 'tag:workflow',
'Values': [
'assisted-log-enabler'
]
},
]
)
for flow_log_id in vpc_flow_logs['FlowLogs']:
print(flow_log_id['FlowLogId'])
removal_list.append(flow_log_id['FlowLogId'])
print(removal_list)
logging.info("DeleteFlowLogs API Call")
delete_logs = ec2.delete_flow_logs(
FlowLogIds=removal_list
)
logging.info("Deleted Flow Logs that were created by Assisted Log Enabler for AWS.")
time.sleep(1)
except Exception as exception_handle:
logging.error(exception_handle)