-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_tunnels_state.py
37 lines (27 loc) · 1.03 KB
/
aws_tunnels_state.py
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
### AWS VPN Tunnel States: 'State': 'pending'|'available'|'deleting'|'deleted'
### AWS credentions are available on the machine
#!/usr/bin/env python3
import sys
import boto3
import json
import pprint
REGION = 'us-east-2'
def main():
if len(sys.argv) < 2:
print("Please supply a VPN status as an argument")
else:
state = sys.argv[1]
print("VPN connection state:", state)
# Display VPN instances in VPC
client = boto3.client('ec2', region_name=REGION)
responce = client.describe_vpn_connections()
# Use lambda to filter VPN instances that are in our VPC
vpn_connections = list( lambda x: x["State"] ==state, response["VPNConnections"] ) )
if len(vpn_connections) > 0:
print("\nVPN Tunnels info:")
for vpn in vpn_connections:
pprint.pprint(vpn["VgwTelemetry"])
else:
print("There is no Vpn Conenctions in this VPC!")
if __name__ == "__main__":
main()