Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit 9e0cd56

Browse files
authored
Updates for version v2.1.2
Updates for version v2.1.2
2 parents 2227526 + 1829a4f commit 9e0cd56

File tree

12 files changed

+310
-150
lines changed

12 files changed

+310
-150
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.1.2] - 2023-04-17
9+
10+
### Updated
11+
12+
- The S3 bucket policy on the logging S3 bucket to grant access to the logging service principal (logging.s3.amazonaws.com) for access log delivery.
13+
- Python libraries.
14+
815

916
## [2.1.1] - 2023-01-11
1017

1118
### Updated
1219

13-
- Python runtime 3.10.
20+
- Python runtime 3.9.
1421
- Python libraries.
1522

1623
## [2.1.0] - 2022-11-30

deployment/build-s3-dist.sh

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ echo "cd $source_dir"
6969
cd $source_dir
7070

7171
# setup lambda layers (building sagemaker layer using lambda build environment for python 3.8)
72-
echo 'docker run -v "$source_dir"/lib/blueprints/byom/lambdas/sagemaker_layer:/var/task lambci/lambda:build-python3.8 /bin/bash -c "cat requirements.txt; pip3 install -r requirements.txt -t ./python; exit"'
73-
docker run -v "$source_dir"/lib/blueprints/byom/lambdas/sagemaker_layer:/var/task lambci/lambda:build-python3.8 /bin/bash -c "cat requirements.txt; pip3 install -r requirements.txt -t ./python; exit"
72+
echo 'docker run --entrypoint /bin/bash -v "$source_dir"/lib/blueprints/byom/lambdas/sagemaker_layer:/var/task public.ecr.aws/lambda/python:3.9 -c "cat requirements.txt; pip3 install -r requirements.txt -t ./python; exit"'
73+
docker run --entrypoint /bin/bash -v "$source_dir"/lib/blueprints/byom/lambdas/sagemaker_layer:/var/task public.ecr.aws/lambda/python:3.9 -c "cat requirements.txt; pip3 install -r requirements.txt -t ./python; exit"
7474

7575
# Remove tests and cache stuff (to reduce size)
7676
find "$source_dir"/lib/blueprints/byom/lambdas/sagemaker_layer/python -type d -name "tests" -exec rm -rfv {} +
@@ -115,30 +115,30 @@ echo "npm install -g aws-cdk@$cdk_version"
115115
npm install -g aws-cdk@$cdk_version
116116

117117
#Run 'cdk synth for BYOM blueprints
118-
echo "cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false"
119-
cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false
120-
echo "cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false"
121-
cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false
122-
echo "cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false"
123-
cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false
124-
echo "cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false"
125-
cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false
126-
echo "cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false"
127-
cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false
128-
echo "cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false"
129-
cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false
130-
echo "cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false"
131-
cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false
132-
echo "cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false"
133-
cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false
134-
echo "cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false"
135-
cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false
136-
echo "cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false"
137-
cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false
138-
echo "cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false"
139-
cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false
140-
echo "cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false"
141-
cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false
118+
echo "cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
119+
cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
120+
echo "cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
121+
cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
122+
echo "cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
123+
cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
124+
echo "cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
125+
cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
126+
echo "cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
127+
cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
128+
echo "cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
129+
cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
130+
echo "cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
131+
cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
132+
echo "cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
133+
cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
134+
echo "cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
135+
cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
136+
echo "cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
137+
cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
138+
echo "cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
139+
cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
140+
echo "cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
141+
cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
142142

143143
# Replace %%VERSION%% in other templates
144144
replace="s/%%VERSION%%/$3/g"
@@ -168,10 +168,10 @@ echo "sed -i -e $replace lib/blueprints/byom/model_hyperparameter_tunning_pipeli
168168
sed -i -e $replace lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml
169169

170170
# Run 'cdk synth' for main templates to generate raw solution outputs
171-
echo "cdk synth mlops-workload-orchestrator-single-account --path-metadata false --version-reporting false --output=$staging_dist_dir"
172-
cdk synth mlops-workload-orchestrator-single-account --path-metadata false --version-reporting false --output=$staging_dist_dir
173-
echo "cdk synth mlops-workload-orchestrator-multi-account --path-metadata false --version-reporting false --output=$staging_dist_dir"
174-
cdk synth mlops-workload-orchestrator-multi-account --path-metadata false --version-reporting false --output=$staging_dist_dir
171+
echo "cdk synth mlops-workload-orchestrator-single-account --path-metadata false --version-reporting false --generate-bootstrap-version-rule false --output=$staging_dist_dir"
172+
cdk synth mlops-workload-orchestrator-single-account --path-metadata false --version-reporting false --generate-bootstrap-version-rule false --output=$staging_dist_dir
173+
echo "cdk synth mlops-workload-orchestrator-multi-account --path-metadata false --version-reporting false --generate-bootstrap-version-rule false --output=$staging_dist_dir"
174+
cdk synth mlops-workload-orchestrator-multi-account --path-metadata false --version-reporting false --generate-bootstrap-version-rule false --output=$staging_dist_dir
175175

176176
# Remove unnecessary output files
177177
echo "cd $staging_dist_dir"

source/lambdas/solution_helper/lambda_function.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
logger = logging.getLogger(__name__)
2020
helper = CfnResource(json_logging=True, log_level="INFO")
2121

22+
# requests.post timeout in seconds
23+
REQUST_TIMEOUT = 60
24+
2225

2326
def _sanitize_data(resource_properties):
2427
# Define allowed keys. You need to update this list with new metrics
@@ -42,7 +45,11 @@ def _sanitize_data(resource_properties):
4245
resource_properties.pop("UUID", None)
4346

4447
# send only allowed metrics
45-
sanitized_data = {key: resource_properties[key] for key in allowed_keys if key in resource_properties}
48+
sanitized_data = {
49+
key: resource_properties[key]
50+
for key in allowed_keys
51+
if key in resource_properties
52+
}
4653

4754
return sanitized_data
4855

@@ -63,9 +70,16 @@ def _send_anonymous_metrics(request_type, resource_properties):
6370
}
6471

6572
logger.info(f"Sending payload: {payload}")
66-
response = requests.post("https://metrics.awssolutionsbuilder.com/generic", json=payload, headers=headers)
73+
response = requests.post(
74+
"https://metrics.awssolutionsbuilder.com/generic",
75+
json=payload,
76+
headers=headers,
77+
timeout=REQUST_TIMEOUT,
78+
)
6779
# log the response
68-
logger.info(f"Response from the metrics endpoint: {response.status_code} {response.reason}")
80+
logger.info(
81+
f"Response from the metrics endpoint: {response.status_code} {response.reason}"
82+
)
6983
# raise error if response is an 404, 503, 500, 403 etc.
7084
response.raise_for_status()
7185
return response

source/lib/blueprints/byom/lambdas/create_model_training_job/tests/fixtures/training_fixtures.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ def mocked_common_env_vars():
3535
"CONTENT_TYPE": "csv",
3636
"USE_SPOT_INSTANCES": "True",
3737
"HYPERPARAMETERS": json.dumps(
38-
dict(eval_metric="auc", objective="binary:logistic", num_round=400, rate_drop=0.3)
38+
dict(
39+
eval_metric="auc",
40+
objective="binary:logistic",
41+
num_round=400,
42+
rate_drop=0.3,
43+
)
3944
),
4045
"TAGS": json.dumps([{"pipeline": "training"}]),
4146
}
@@ -87,25 +92,44 @@ def mocked_hyperparameters(mocked_training_job_env_vars):
8792

8893

8994
@pytest.fixture()
90-
def mocked_estimator_config(mocked_training_job_env_vars):
95+
def mocked_sagemaker_session():
96+
region = "us-east-1"
97+
boto_mock = Mock(name="boto_session", region_name=region)
98+
sms = Mock(
99+
name="sagemaker_session",
100+
boto_session=boto_mock,
101+
boto_region_name=region,
102+
config=None,
103+
local_mode=False,
104+
s3_resource=None,
105+
s3_client=None,
106+
)
107+
sms.sagemaker_config = {}
108+
return sms
109+
110+
111+
@pytest.fixture()
112+
def mocked_estimator_config(mocked_training_job_env_vars, mocked_sagemaker_session):
91113
return dict(
92114
image_uri=os.environ["IMAGE_URI"],
93115
role=os.environ["ROLE_ARN"],
94116
instance_count=int(os.environ["INSTANCE_COUNT"]),
95117
instance_type=os.environ["INSTANCE_TYPE"],
96118
volume_size=int(os.environ["INSTANCE_VOLUME_SIZE"]),
97119
output_path=f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['JOB_OUTPUT_LOCATION']}",
98-
sagemaker_session=Mock(),
120+
sagemaker_session=mocked_sagemaker_session,
99121
)
100122

101123

102124
@pytest.fixture()
103125
def mocked_data_channels(mocked_training_job_env_vars):
104126
train_input = TrainingInput(
105-
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}", content_type=os.environ["CONTENT_TYPE"]
127+
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}",
128+
content_type=os.environ["CONTENT_TYPE"],
106129
)
107130
validation_input = TrainingInput(
108-
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}", content_type=os.environ["CONTENT_TYPE"]
131+
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}",
132+
content_type=os.environ["CONTENT_TYPE"],
109133
)
110134

111135
data_channels = {"train": train_input, "validation": validation_input}

source/lib/blueprints/byom/lambdas/create_model_training_job/tests/test_create_model_training.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,16 @@
2424
mocked_job_name,
2525
mocked_raw_search_grid,
2626
mocked_hyperparameter_ranges,
27+
mocked_sagemaker_session,
2728
)
2829

2930

30-
def test_create_estimator(mocked_estimator_config, mocked_hyperparameters, mocked_data_channels, mocked_job_name):
31+
def test_create_estimator(
32+
mocked_estimator_config,
33+
mocked_hyperparameters,
34+
mocked_data_channels,
35+
mocked_job_name,
36+
):
3137
job = SolutionModelTraining(
3238
job_name=mocked_job_name,
3339
estimator_config=mocked_estimator_config,
@@ -69,22 +75,27 @@ def test_create_hyperparameter_tuner(
6975
assert tuner.max_jobs == 10
7076
assert tuner.strategy == "Bayesian"
7177
assert tuner.objective_type == "Maximize"
72-
TestCase().assertDictEqual(tuner._hyperparameter_ranges, mocked_hyperparameter_ranges)
78+
TestCase().assertDictEqual(
79+
tuner._hyperparameter_ranges, mocked_hyperparameter_ranges
80+
)
7381

7482

7583
def test_format_search_grid(mocked_raw_search_grid):
7684
formeated_grid = SolutionModelTraining.format_search_grid(mocked_raw_search_grid)
7785
# assert a Continuous parameter
7886
TestCase().assertListEqual(
79-
mocked_raw_search_grid["eta"][1], [formeated_grid["eta"].min_value, formeated_grid["eta"].max_value]
87+
mocked_raw_search_grid["eta"][1],
88+
[formeated_grid["eta"].min_value, formeated_grid["eta"].max_value],
8089
)
8190
# assert an Integer parameter
8291
TestCase().assertListEqual(
8392
mocked_raw_search_grid["max_depth"][1],
8493
[formeated_grid["max_depth"].min_value, formeated_grid["max_depth"].max_value],
8594
)
8695
# assert a Categorical parameter
87-
TestCase().assertListEqual(mocked_raw_search_grid["optimizer"][1], formeated_grid["optimizer"].values)
96+
TestCase().assertListEqual(
97+
mocked_raw_search_grid["optimizer"][1], formeated_grid["optimizer"].values
98+
)
8899

89100

90101
@patch("model_training_helper.SolutionModelTraining._create_hyperparameter_tuner")
@@ -127,7 +138,9 @@ def test_create_training_job(
127138
@patch("model_training_helper.SolutionModelTraining._create_estimator")
128139
@patch("main.Session")
129140
@patch("main.get_client")
130-
def test_handler_training_job(mocked_client, mocked_session, mocked_create_estimator, mocked_training_job_env_vars):
141+
def test_handler_training_job(
142+
mocked_client, mocked_session, mocked_create_estimator, mocked_training_job_env_vars
143+
):
131144
mocked_client.boto_region_name = "us-east-1"
132145
from main import handler
133146

source/lib/blueprints/byom/lambdas/create_update_cf_stackset/tests/fixtures/stackset_fixtures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ def mocked_cp_success_message():
4848
def mocked_cp_failure_message():
4949
return "StackSet Job Failed"
5050

51+
@pytest.fixture()
52+
def mocked_describe_response():
53+
return {'StackInstance':{"StackInstanceStatus": {"DetailedStatus": "SUCCEEDED"}}}
5154

5255
@pytest.fixture()
5356
def mocked_cp_continuation_message():

0 commit comments

Comments
 (0)