Skip to content

Commit

Permalink
eliminated need for s3 parameter for performance improvement (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
eamonnfaherty authored Dec 17, 2024
1 parent a6dd61b commit 758f38c
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 108 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[tool.poetry]
name = "aws-service-catalog-puppet"
version = "0.254.2"
version = "0.254.3"
description = "Making it easier to deploy ServiceCatalog products"
classifiers = ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Programming Language :: Python :: 3", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Natural Language :: English"]
homepage = "https://service-catalog-tools-workshop.com/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def generate(puppet_account_id, manifest, output_file_directory_path):
parameter_task["dependencies_by_reference"].remove(task_reference)

# wire up dependencies for s3 parameters
s3_parameters = task.get("s3_parameters_tasks_references", {}).items()
s3_parameters = task.get("s3_object_task_reference", {}).items()
for parameter_name, parameter_task_reference in s3_parameters:
parameter_task = all_tasks.get(parameter_task_reference)
for dependency_task_reference in task.get("dependencies_by_reference"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def s3_parameter_handler(
.replace("${AWS::PuppetAccountId}", puppet_account_id)
)

parameter_task_reference = f"{constants.S3_PARAMETERS}-{key}-{jmespath}"
s3_object_task_reference = f"{constants.S3_GET_OBJECT}-{key}"

if not all_tasks.get(s3_object_task_reference):
Expand All @@ -49,41 +48,20 @@ def s3_parameter_handler(
"section_name": constants.S3_GET_OBJECT,
}

if all_tasks.get(parameter_task_reference):
s3_task_params = all_tasks.get(parameter_task_reference)
else:
s3_task_params = {
"task_reference": parameter_task_reference,
"account_id": puppet_account_id,
"region": home_region,
"s3_object_task_reference": s3_object_task_reference,
"key": key,
"jmespath": jmespath,
"default": default,
task_reference_constants.MANIFEST_SECTION_NAMES: dict(),
task_reference_constants.MANIFEST_ITEM_NAMES: dict(),
task_reference_constants.MANIFEST_ACCOUNT_IDS: dict(),
"dependencies": [],
"dependencies_by_reference": [s3_object_task_reference],
"execution": constants.EXECUTION_MODE_HUB,
"section_name": constants.S3_PARAMETERS,
}
new_tasks[parameter_task_reference] = s3_task_params

s3_task_params[task_reference_constants.MANIFEST_SECTION_NAMES].update(
**task.get(task_reference_constants.MANIFEST_SECTION_NAMES)
)
s3_task_params[task_reference_constants.MANIFEST_ITEM_NAMES].update(
**task.get(task_reference_constants.MANIFEST_ITEM_NAMES)
)
s3_task_params[task_reference_constants.MANIFEST_ACCOUNT_IDS].update(
**task.get(task_reference_constants.MANIFEST_ACCOUNT_IDS)
)
new_tasks[s3_object_task_reference][
task_reference_constants.MANIFEST_SECTION_NAMES
].update(**task.get(task_reference_constants.MANIFEST_SECTION_NAMES))
new_tasks[s3_object_task_reference][
task_reference_constants.MANIFEST_ITEM_NAMES
].update(**task.get(task_reference_constants.MANIFEST_ITEM_NAMES))
new_tasks[s3_object_task_reference][
task_reference_constants.MANIFEST_ACCOUNT_IDS
].update(**task.get(task_reference_constants.MANIFEST_ACCOUNT_IDS))

task["dependencies_by_reference"].append(parameter_task_reference)
task["dependencies_by_reference"].append(s3_object_task_reference)

if not task.get("s3_parameters_tasks_references"):
task["s3_parameters_tasks_references"] = dict()
if not task.get("s3_object_task_reference"):
task["s3_object_task_reference"] = dict()

parameter_name = (
str(s3_parameter_details.get("name"))
Expand All @@ -92,6 +70,4 @@ def s3_parameter_handler(
.replace("${AWS::PuppetAccountId}", puppet_account_id)
)

task["s3_parameters_tasks_references"][
parameter_name
] = parameter_task_reference
task["s3_object_task_reference"][parameter_name] = s3_object_task_reference
1 change: 0 additions & 1 deletion servicecatalog_puppet/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@

SSM_OUTPUTS = "ssm_outputs"
SSM_PARAMETERS = "ssm_parameters"
S3_PARAMETERS = "s3_parameters"
S3_GET_OBJECT = "s3_get_object"
BOTO3_PARAMETERS = "boto3_parameters"
SSM_PARAMETERS_WITH_A_PATH = "ssm_parameters_with_a_path"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,8 @@ def create(section_name, parameters_to_use, puppet_account_id):
elif section_name == constants.BOTO3_PARAMETERS:
resources = []

elif section_name == constants.S3_PARAMETERS:
resources = []

elif section_name == constants.S3_GET_OBJECT:
resources = [S3_GET_OBJECT_PER_REGION_OF_ACCOUNT]
resources = [] #

elif section_name == constants.SSM_PARAMETERS_WITH_A_PATH:
resources = [
Expand Down
11 changes: 0 additions & 11 deletions servicecatalog_puppet/workflow/dependencies/task_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,6 @@ def create(
jmespath_location=parameters_to_use.get("jmespath"),
)

elif section_name == constants.S3_PARAMETERS:
from servicecatalog_puppet.workflow.s3 import get_s3_parameter_task

return get_s3_parameter_task.GetS3ParameterTask(
**common_parameters,
s3_object_task_reference=parameters_to_use.get("s3_object_task_reference"),
key=parameters_to_use.get("key"),
jmespath_location=parameters_to_use.get("jmespath"),
default=parameters_to_use.get("default"),
)

elif section_name == constants.S3_GET_OBJECT:
from servicecatalog_puppet.workflow.s3 import get_s3_object_task

Expand Down
41 changes: 32 additions & 9 deletions servicecatalog_puppet/workflow/dependencies/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import functools
import logging

import jmespath
import luigi
from deepmerge import always_merger

Expand Down Expand Up @@ -233,24 +234,46 @@ def get_parameter_values(self):

if param_details.get("s3"):
requested_param_details = param_details.get("s3")
task_ref = (
f"{constants.S3_PARAMETERS}"
f"-{requested_param_details.get('key')}"
f"-{requested_param_details.get('jmespath')}"
)

task_ref = (
str(task_ref.replace("${AWS::AccountId}", self.account_id))
key = requested_param_details.get("key")
key = (
key.replace("${AWS::Region}", self.region)
.replace("${AWS::AccountId}", self.account_id)
.replace("${AWS::PuppetAccountId}", self.puppet_account_id)
.replace("${AWS::Region}", self.region)
)

task_ref = f"{constants.S3_GET_OBJECT}" f"-{key}"

print(
f"Getting output for task: {task_ref} within task {self.task_reference}"
)
parameter_task_output = self.get_output_from_reference_dependency(
task_ref
)
jmespath_location = requested_param_details.get("jmespath")
jmespath_location = (
jmespath_location.replace("${AWS::Region}", self.region)
.replace("${AWS::AccountId}", self.account_id)
.replace("${AWS::PuppetAccountId}", self.puppet_account_id)
)
default = requested_param_details.get("default")
default = (
default.replace("${AWS::Region}", self.region)
.replace("${AWS::AccountId}", self.account_id)
.replace("${AWS::PuppetAccountId}", self.puppet_account_id)
)

parameter_task_output = jmespath.search(
jmespath_location, parameter_task_output
)
if parameter_task_output is None:
if default is None:
raise Exception(
"Could not find value in the s3 JSON object and there is no default value."
"Check your JMESPath is correct."
)
else:
parameter_task_output = default

all_params[param_name] = parameter_task_output

if param_details.get("default"):
Expand Down
43 changes: 0 additions & 43 deletions servicecatalog_puppet/workflow/s3/get_s3_parameter_task.py

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@

setup_kwargs = {
'name': 'aws-service-catalog-puppet',
'version': '0.254.2',
'version': '0.254.3',
'description': 'Making it easier to deploy ServiceCatalog products',
'long_description': '# aws-service-catalog-puppet\n\n![logo](./docs/logo.png) \n\n## Badges\n\n[![codecov](https://codecov.io/gh/awslabs/aws-service-catalog-puppet/branch/master/graph/badge.svg?token=e8M7mdsmy0)](https://codecov.io/gh/awslabs/aws-service-catalog-puppet)\n\n\n## What is it?\nThis is a python3 framework that makes it easier to share multi region AWS Service Catalog portfolios and makes it \npossible to provision products into accounts declaratively using a metadata based rules engine.\n\nWith this framework you define your accounts in a YAML file. You give each account a set of tags, a default region and \na set of enabled regions.\n\nOnce you have done this you can define portfolios should be shared with each set of accounts using the tags and you \ncan specify which regions the shares occur in.\n\nIn addition to this, you can also define products that should be provisioned into accounts using the same tag based \napproach. The framework will assume role into the target account and provision the product on your behalf.\n\n\n## Getting started\n\nYou can read the [installation how to](https://service-catalog-tools-workshop.com/30-how-tos/10-installation/30-service-catalog-puppet.html)\nor you can read through the [every day use](https://service-catalog-tools-workshop.com/30-how-tos/50-every-day-use.html)\nguides.\n\nYou can read the [documentation](https://aws-service-catalog-puppet.readthedocs.io/en/latest/) to understand the inner \nworkings. \n\n\n## Going further\n\nThe framework is one of a pair. The other is [aws-service-catalog-factory](https://github.com/awslabs/aws-service-catalog-factory).\nWith Service Catalog Factory you can create pipelines that deploy multi region portfolios very easily. \n\n## License\n\nThis library is licensed under the Apache 2.0 License. \n \n',
'author': 'Eamonn Faherty',
Expand Down

0 comments on commit 758f38c

Please sign in to comment.