-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInternetGateway_Creation.py
39 lines (24 loc) · 1.1 KB
/
InternetGateway_Creation.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
38
39
from Taging import attach_tag
def create_internetgateway(client,ig_name,vpc_id):
# Check whether IG is already created or not
internetGatewayId = find_internetgateway(client,ig_name)
if internetGatewayId is None:
response = client.create_internet_gateway()
print(response)
internetGatewayId = response['InternetGateway']['InternetGatewayId']
response = client.attach_internet_gateway(
InternetGatewayId=internetGatewayId,
VpcId=vpc_id
)
print('Internet Gateway Created with ID: ', internetGatewayId)
attach_tag(client,internetGatewayId,ig_name)
return internetGatewayId
else:
return internetGatewayId
def find_internetgateway(client,ig_name):
filters = [{'Name': 'tag:Name', 'Values': [ig_name] }]
response = client.describe_internet_gateways(Filters = filters)
if len(response['InternetGateways']) > 0:
return response['InternetGateways'][0]['InternetGatewayId']
else:
return None