Skip to content

Commit

Permalink
Update to vesrion v2.1.2
Browse files Browse the repository at this point in the history
Update to vesrion v2.1.2
  • Loading branch information
knihit committed Apr 18, 2023
2 parents 92b7b05 + 766d573 commit 1829a4f
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 150 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.2] - 2023-04-17

### Updated

- 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.
- Python libraries.


## [2.1.1] - 2023-01-11

### Updated

- Python runtime 3.10.
- Python runtime 3.9.
- Python libraries.

## [2.1.0] - 2022-11-30
Expand Down
60 changes: 30 additions & 30 deletions deployment/build-s3-dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ echo "cd $source_dir"
cd $source_dir

# setup lambda layers (building sagemaker layer using lambda build environment for python 3.8)
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"'
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"
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"'
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"

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

#Run 'cdk synth for BYOM blueprints
echo "cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false"
cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false
echo "cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false"
cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false
echo "cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false"
cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false
echo "cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false"
cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false
echo "cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false"
cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false"
cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false"
cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false"
cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false
echo "cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false"
cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false"
cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false"
cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false"
cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false
echo "cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth DataQualityModelMonitorStack > lib/blueprints/byom/byom_data_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth ModelQualityModelMonitorStack > lib/blueprints/byom/byom_model_quality_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth ModelBiasModelMonitorStack > lib/blueprints/byom/byom_model_bias_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth ModelExplainabilityModelMonitorStack > lib/blueprints/byom/byom_model_explainability_monitor.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth SingleAccountCodePipelineStack > lib/blueprints/byom/single_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth MultiAccountCodePipelineStack > lib/blueprints/byom/multi_account_codepipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth BYOMRealtimePipelineStack > lib/blueprints/byom/byom_realtime_inference_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth BYOMCustomAlgorithmImageBuilderStack > lib/blueprints/byom/byom_custom_algorithm_image_builder.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth BYOMBatchStack > lib/blueprints/byom/byom_batch_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth AutopilotJobStack > lib/blueprints/byom/autopilot_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth TrainingJobStack > lib/blueprints/byom/model_training_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false
echo "cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false"
cdk synth HyperparamaterTunningJobStack > lib/blueprints/byom/model_hyperparameter_tunning_pipeline.yaml --path-metadata false --version-reporting false --generate-bootstrap-version-rule false

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

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

# Remove unnecessary output files
echo "cd $staging_dist_dir"
Expand Down
20 changes: 17 additions & 3 deletions source/lambdas/solution_helper/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
logger = logging.getLogger(__name__)
helper = CfnResource(json_logging=True, log_level="INFO")

# requests.post timeout in seconds
REQUST_TIMEOUT = 60


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

# send only allowed metrics
sanitized_data = {key: resource_properties[key] for key in allowed_keys if key in resource_properties}
sanitized_data = {
key: resource_properties[key]
for key in allowed_keys
if key in resource_properties
}

return sanitized_data

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

logger.info(f"Sending payload: {payload}")
response = requests.post("https://metrics.awssolutionsbuilder.com/generic", json=payload, headers=headers)
response = requests.post(
"https://metrics.awssolutionsbuilder.com/generic",
json=payload,
headers=headers,
timeout=REQUST_TIMEOUT,
)
# log the response
logger.info(f"Response from the metrics endpoint: {response.status_code} {response.reason}")
logger.info(
f"Response from the metrics endpoint: {response.status_code} {response.reason}"
)
# raise error if response is an 404, 503, 500, 403 etc.
response.raise_for_status()
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def mocked_common_env_vars():
"CONTENT_TYPE": "csv",
"USE_SPOT_INSTANCES": "True",
"HYPERPARAMETERS": json.dumps(
dict(eval_metric="auc", objective="binary:logistic", num_round=400, rate_drop=0.3)
dict(
eval_metric="auc",
objective="binary:logistic",
num_round=400,
rate_drop=0.3,
)
),
"TAGS": json.dumps([{"pipeline": "training"}]),
}
Expand Down Expand Up @@ -87,25 +92,44 @@ def mocked_hyperparameters(mocked_training_job_env_vars):


@pytest.fixture()
def mocked_estimator_config(mocked_training_job_env_vars):
def mocked_sagemaker_session():
region = "us-east-1"
boto_mock = Mock(name="boto_session", region_name=region)
sms = Mock(
name="sagemaker_session",
boto_session=boto_mock,
boto_region_name=region,
config=None,
local_mode=False,
s3_resource=None,
s3_client=None,
)
sms.sagemaker_config = {}
return sms


@pytest.fixture()
def mocked_estimator_config(mocked_training_job_env_vars, mocked_sagemaker_session):
return dict(
image_uri=os.environ["IMAGE_URI"],
role=os.environ["ROLE_ARN"],
instance_count=int(os.environ["INSTANCE_COUNT"]),
instance_type=os.environ["INSTANCE_TYPE"],
volume_size=int(os.environ["INSTANCE_VOLUME_SIZE"]),
output_path=f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['JOB_OUTPUT_LOCATION']}",
sagemaker_session=Mock(),
sagemaker_session=mocked_sagemaker_session,
)


@pytest.fixture()
def mocked_data_channels(mocked_training_job_env_vars):
train_input = TrainingInput(
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}", content_type=os.environ["CONTENT_TYPE"]
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}",
content_type=os.environ["CONTENT_TYPE"],
)
validation_input = TrainingInput(
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}", content_type=os.environ["CONTENT_TYPE"]
f"s3://{os.environ['ASSETS_BUCKET']}/{os.environ['TRAINING_DATA_KEY']}",
content_type=os.environ["CONTENT_TYPE"],
)

data_channels = {"train": train_input, "validation": validation_input}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,16 @@
mocked_job_name,
mocked_raw_search_grid,
mocked_hyperparameter_ranges,
mocked_sagemaker_session,
)


def test_create_estimator(mocked_estimator_config, mocked_hyperparameters, mocked_data_channels, mocked_job_name):
def test_create_estimator(
mocked_estimator_config,
mocked_hyperparameters,
mocked_data_channels,
mocked_job_name,
):
job = SolutionModelTraining(
job_name=mocked_job_name,
estimator_config=mocked_estimator_config,
Expand Down Expand Up @@ -69,22 +75,27 @@ def test_create_hyperparameter_tuner(
assert tuner.max_jobs == 10
assert tuner.strategy == "Bayesian"
assert tuner.objective_type == "Maximize"
TestCase().assertDictEqual(tuner._hyperparameter_ranges, mocked_hyperparameter_ranges)
TestCase().assertDictEqual(
tuner._hyperparameter_ranges, mocked_hyperparameter_ranges
)


def test_format_search_grid(mocked_raw_search_grid):
formeated_grid = SolutionModelTraining.format_search_grid(mocked_raw_search_grid)
# assert a Continuous parameter
TestCase().assertListEqual(
mocked_raw_search_grid["eta"][1], [formeated_grid["eta"].min_value, formeated_grid["eta"].max_value]
mocked_raw_search_grid["eta"][1],
[formeated_grid["eta"].min_value, formeated_grid["eta"].max_value],
)
# assert an Integer parameter
TestCase().assertListEqual(
mocked_raw_search_grid["max_depth"][1],
[formeated_grid["max_depth"].min_value, formeated_grid["max_depth"].max_value],
)
# assert a Categorical parameter
TestCase().assertListEqual(mocked_raw_search_grid["optimizer"][1], formeated_grid["optimizer"].values)
TestCase().assertListEqual(
mocked_raw_search_grid["optimizer"][1], formeated_grid["optimizer"].values
)


@patch("model_training_helper.SolutionModelTraining._create_hyperparameter_tuner")
Expand Down Expand Up @@ -127,7 +138,9 @@ def test_create_training_job(
@patch("model_training_helper.SolutionModelTraining._create_estimator")
@patch("main.Session")
@patch("main.get_client")
def test_handler_training_job(mocked_client, mocked_session, mocked_create_estimator, mocked_training_job_env_vars):
def test_handler_training_job(
mocked_client, mocked_session, mocked_create_estimator, mocked_training_job_env_vars
):
mocked_client.boto_region_name = "us-east-1"
from main import handler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def mocked_cp_success_message():
def mocked_cp_failure_message():
return "StackSet Job Failed"

@pytest.fixture()
def mocked_describe_response():
return {'StackInstance':{"StackInstanceStatus": {"DetailedStatus": "SUCCEEDED"}}}

@pytest.fixture()
def mocked_cp_continuation_message():
Expand Down
Loading

0 comments on commit 1829a4f

Please sign in to comment.