Skip to content

Commit 3452e37

Browse files
Merge pull request #9 from maghirardelli/create-rstudio-bug-fixed
fix: rstudio create script bugs
2 parents 2fc150a + 4ce4001 commit 3452e37

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

RStudio/machine-images/config/infra/configuration.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"vpcId": "",
66
"subnetId": "",
77
"amiName": "",
8-
"awsProfile": ""
8+
"awsProfile": "",
9+
"stageName": ""
910
}

RStudio/machine-images/config/infra/create-rstudio.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,22 @@ def formRoleName():
4646
extension = ''
4747
stageFileFound = False
4848
path = os.getcwd()
49+
# Make use of the configuration.json file to get proper stage file
50+
with open("configuration.json", "r") as file:
51+
jsonFile = json.load(file)
52+
stageName = jsonFile["stageName"]
53+
4954
for file in os.listdir(path):
50-
if file.endswith(".yml") or file.endswith(".yaml"):
55+
if file.endswith(".yml") or file.endswith(".yaml") and not stageFileFound:
5156
fileSplit = os.path.splitext(file)
5257
fileName = fileSplit[0]
5358
extension = fileSplit[1]
54-
stageFileFound = True
59+
# Stop traversal when stagefile is found
60+
if stageName == fileName:
61+
stageFileFound = True
62+
break
5563

56-
print('looking for the stage file '+ fileName + extension + ' in the current working directory')
64+
print('looking for the stage file '+ stageName + extension + ' in the current working directory')
5765
if not stageFileFound:
5866
raise Exception('Stage file is not found in the current working directory. Please add the stage file into the specified directory')
5967
else:
@@ -73,6 +81,8 @@ def formRoleName():
7381
raise Exception('AWS region does not exist in your stage file. Please add aws region into your stage file')
7482
if configuration['awsRegion'] is None:
7583
raise Exception('AWS Region value does not exist in your stage file. Please add region name that you have used during SWB installation into your stage file')
84+
# Setting boto3 to use provided awsProfile and awsRegion from stage file
85+
boto3.setup_default_session(profile_name=configuration['awsProfile'], region_name=configuration['awsRegion'])
7686
print('Checking for the key awsRegion and its value in the stage file')
7787
checkIfRegionisValid(configuration['awsRegion'])
7888
regionShortName = regionShortNamesMap.get(configuration['awsRegion'])
@@ -241,7 +251,7 @@ def describeStack(stackName):
241251
if(stackStatus == 'CREATE_COMPLETE'):
242252
print('-------------------------Stack created successfully----------------------------------')
243253
return
244-
if(stackStatus == 'CREATE_FAILED' or 'IMPORT_FAILED' or 'IMPORT_ROLLBACK_IN_PROGRESS' or 'IMPORT_ROLLBACK_FAILED' or 'IMPORT_ROLLBACK_COMPLETE' or 'ROLLBACK_IN_PROGRESS'):
254+
if(stackStatus in ['CREATE_FAILED', 'IMPORT_FAILED', 'IMPORT_ROLLBACK_IN_PROGRESS', 'IMPORT_ROLLBACK_FAILED', 'IMPORT_ROLLBACK_COMPLETE', 'ROLLBACK_IN_PROGRESS']):
245255
print('Stack ' + stackName + ' is with status ' + stackStatus + ', so deleting the stack')
246256
print('Please check the input parameters and try again')
247257
print('-------------------------Deleting the stack----------------------------------')

0 commit comments

Comments
 (0)