Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to /tmp and supports MPEID #149

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Running this tool is free as it is covered under the AWS Free Tier. If you have

In the AWS CloudShell terminal, run this script this to install the dependencies:
```bash
cd /tmp
python3 -m venv .
source bin/activate
python3 -m pip install --upgrade pip
Expand Down
21 changes: 19 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,25 @@ def number_format(num, places=2):

oo = Config.get('_AWS_OPTIONS')

## Added mpeid to CFStack
mpeid = None
otherParams = _cli_options.get('others', None)
if otherParams is not None:
try:
oparams = json.loads(otherParams)
mpeInfo = oparams.get('mpe', None)
if mpeInfo is not None:
mpeid = mpeInfo.get('id', None)
except json.JSONDecodeError as e:
print("Unable to read --others parameters, invalid JSON format provided")
print(f"Error decoding JSON: {e}")
exit()

if testmode == False:
CfnTrailObj.boto3init()
cfnAdditionalStr = None
if mpeid is not None:
cfnAdditionalStr = " --mpeid:{}".format(mpeid)
CfnTrailObj.boto3init(cfnAdditionalStr)
CfnTrailObj.createStack()

overallTimeStart = time.time()
Expand Down Expand Up @@ -318,7 +335,7 @@ def number_format(num, places=2):
shutil.rmtree(apiFolder)

print("Pages generated, download \033[1;42moutput.zip\033[0m to view")
print("CloudShell user, you may use this path: \033[1;42m =====> \033[0m ~/service-screener-v2/output.zip \033[1;42m <===== \033[0m")
print("CloudShell user, you may use this path: \033[1;42m =====> \033[0m /tmp/service-screener-v2/output.zip \033[1;42m <===== \033[0m")

scriptTimeSpent = round(time.time() - scriptStartTime, 3)
print("@ Thank you for using {}, script spent {}s to complete @".format(Config.ADVISOR['TITLE'], scriptTimeSpent))
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## First installation
cd /tmp
python -m venv .
source bin/activate
git clone https://github.com/aws-samples/service-screener-v2.git
Expand Down
13 changes: 9 additions & 4 deletions utils/CfnTrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@

## Class name decided by Sarika
class CfnTrail():
additionalDesc = None
def __init__(self):
self.stackName = None
self.cfnTemplate = "zNullResourcesCfn.yml"
self.stackPrefix = "ssv2-"
self.defaultRegion = "us-east-1"
self.ymlBody='''
AWSTemplateFormatVersion: '2010-09-09'
Description: '[aws-gh-ss-v2] Service Screener V2'
Description: '[aws-gh-ss-v2] Service Screener V2{}'

Conditions:
HasNot: !Equals [ 'true', 'false' ]
Expand All @@ -27,7 +28,8 @@ def __init__(self):
NullResource:
Type: 'Custom::NullResource'
Condition: HasNot

'''
self.ymlBodyOutput='''
Outputs:
ExportsStackName:
Value: !Ref 'AWS::StackName'
Expand All @@ -37,19 +39,22 @@ def __init__(self):

# self.boto3init()

def boto3init(self):
def boto3init(self, additionalDesc = None):
self.bConfig = bConfig(
region_name = self.getRegion()
)

ssBoto = Config.get('ssBoto', None)
self.cfClient = ssBoto.client('cloudformation', config=self.bConfig)

self.additionalDesc = additionalDesc

def createStack(self):
try:
yml = self.ymlBody.format(self.additionalDesc) + self.ymlBodyOutput
self.cfClient.create_stack(
StackName=self.getStackName(),
TemplateBody=self.ymlBody
TemplateBody=yml
)
msg = "Empty CF stacked created successfully, name:" + self.getStackName()
_info(msg, alwaysPrint=True)
Expand Down
Loading