-
Notifications
You must be signed in to change notification settings - Fork 0
/
Resource_Creation.py
41 lines (28 loc) · 1.07 KB
/
Resource_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
40
41
import sys
import boto3
def find_resource_id(client,RestAPIId,ParentId,ResourceName):
rootResource = client.get_resources(
restApiId = RestAPIId,
limit = 500
)
if ResourceName == '/':
for res in rootResource['items'] :
if res['path'] == '/' :
return res['id']
else:
for res in rootResource['items']:
if res['path'] != '/' :
if res['pathPart'] == ResourceName and res['parentId'] == ParentId:
return res['id']
return None
def create_resource(client,RestAPIId,ParentId,ResourceName):
ResourceId = find_resource_id(client,RestAPIId,ParentId,ResourceName)
if ResourceId is None:
ResourceResponse = client.create_resource(
restApiId = RestAPIId,
parentId = ParentId,
pathPart= ResourceName
)
ResourceId = ResourceResponse['id']
print('Root Resource ' , ResourceName , ' Created with ID: ', ResourceId)
return ResourceId