-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc_flowlogs_conf
51 lines (40 loc) · 1.24 KB
/
vpc_flowlogs_conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
import boto3
client = boto3.client('ec2')
list1 = []
list2 = []
#response = client.describe_volumes()
response = client.describe_vpcs()
response1 = client.describe_flow_logs()
#print response1
for VIds in response[u'Vpcs']:
vpc = VIds[u'VpcId']
#print " all VPCIds: ",VIds[u'VpcId']
list1.append(vpc)
VPCIds = set(list1)
#print " all VPCIds: ", VPCIds
for i in response1[u'FlowLogs']:
#print " FlowLog VPCIds: ", i[u'ResourceId']
FLVIds = i[u'ResourceId']
list2.append(FLVIds)
FlowlogVPCIds = set(list2)
#print " all Flowlogs VPCIds : ", FlowlogVPCIds
VPC_without_FlowLogs = VPCIds - FlowlogVPCIds
#print VPC_without_FlowLogs
val1 = list(VPC_without_FlowLogs)
#val2 = len(VPC_without_FlowLogs)
va2 = list(VPCIds)
#print val
for y in val1:
response = client.create_flow_logs(
ClientToken='NewFlowLog',
DeliverLogsPermissionArn='arn:aws:iam::xxxxxxxxxxxxxxxxxxx:role/cloudwatchagent',
LogGroupName='FlowlogGroup',
ResourceIds=[
y,
],
ResourceType='VPC',
TrafficType='ALL',
LogDestinationType='cloud-watch-logs',
)
#print response