Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Kukushkin <kukushkin.anton@gmail.com>
  • Loading branch information
kukushking committed Feb 5, 2024
1 parent da3c0a4 commit 5744b8c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 46 deletions.
13 changes: 7 additions & 6 deletions modules/sagemaker/sagemaker-endpoint/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os

import aws_cdk

from stack import DeployEndpointStack


Expand Down Expand Up @@ -69,12 +70,12 @@ def _param(name: str) -> str:
subnet_ids=subnet_ids,
model_bucket_arn=model_bucket_arn,
ecr_repo_arn=ecr_repo_arn,
endpoint_config_prod_variant=dict(
initial_instance_count=initial_instance_count,
initial_variant_weight=initial_variant_weight,
instance_type=instance_type,
variant_name=variant_name,
),
endpoint_config_prod_variant={
"initial_instance_count": initial_instance_count,
"initial_variant_weight": initial_variant_weight,
"instance_type": instance_type,
"variant_name": variant_name,
},
env=environment,
)

Expand Down
9 changes: 7 additions & 2 deletions modules/sagemaker/sagemaker-endpoint/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 120
src_paths = ["sagemaker-model-deploy"]
py_version = 36
skip_gitignore = false
skip_gitignore = false

[tool.pytest.ini_options]
addopts = "-v --cov=. --cov-report term --cov-config=coverage.ini --cov-fail-under=80"
pythonpath = [
"."
]
24 changes: 0 additions & 24 deletions modules/sagemaker/sagemaker-endpoint/setup.py

This file was deleted.

8 changes: 6 additions & 2 deletions modules/sagemaker/sagemaker-endpoint/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
from aws_cdk import aws_s3 as s3
from aws_cdk import aws_sagemaker as sagemaker
from cdk_nag import AwsSolutionsChecks, NagPackSuppression, NagSuppressions
from scripts.get_approved_package import get_approved_package
from typing_extensions import NotRequired, Required

from scripts.get_approved_package import get_approved_package


class EndpointConfigProductionVariant(TypedDict):
variant_name: Required[str]
Expand Down Expand Up @@ -56,7 +57,10 @@ def __init__(
# Import VPC, create security group, and add ingress rule
vpc = ec2.Vpc.from_lookup(self, f"{app_prefix}-vpc", vpc_id=vpc_id)
security_group = ec2.SecurityGroup(self, f"{app_prefix}-sg", vpc=vpc, allow_all_outbound=True)
security_group.add_ingress_rule(peer=ec2.Peer.ipv4(vpc.vpc_cidr_block), connection=ec2.Port.all_tcp())
security_group.add_ingress_rule(
peer=ec2.Peer.ipv4(vpc.vpc_cidr_block),
connection=ec2.Port.all_tcp(),
)

if not model_execution_role_arn:
# Create model execution role
Expand Down
22 changes: 10 additions & 12 deletions modules/sagemaker/sagemaker-endpoint/tests/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import aws_cdk as cdk
import botocore.session
import pytest
from aws_cdk.assertions import Template
from botocore.stub import Stubber

Expand All @@ -19,7 +18,7 @@ def stack_defaults() -> None:
del sys.modules["stack"]


def test_synthesize_stack_model_package_input(stack_defaults) -> None:
def test_synthesize_stack_model_package_input() -> None:
import stack

app = cdk.App()
Expand Down Expand Up @@ -52,10 +51,10 @@ def test_synthesize_stack_model_package_input(stack_defaults) -> None:
account=os.environ["CDK_DEFAULT_ACCOUNT"],
region=os.environ["CDK_DEFAULT_REGION"],
),
endpoint_config_prod_variant=dict(
variant_name="AllTraffic",
initial_variant_weight=1,
),
endpoint_config_prod_variant={
"initial_variant_weight": 1,
"variant_name": "AllTraffic",
},
)

template = Template.from_stack(endpoint_stack)
Expand All @@ -78,7 +77,6 @@ def test_synthesize_stack_latest_approved_model_package(mock_s3_client, stack_de
vpc_id = "vpc-12345"
model_package_group_name = "example-group"
model_bucket_arn = "arn:aws:s3:::test-bucket"
dev_account = "111111111111"

sagemaker_client = botocore.session.get_session().create_client("sagemaker", region_name="us-east-1")
mock_s3_client.return_value = sagemaker_client
Expand All @@ -93,7 +91,7 @@ def test_synthesize_stack_latest_approved_model_package(mock_s3_client, stack_de
response = {
"ModelPackageSummaryList": [
{
"ModelPackageArn": f"arn:aws:sagemaker:us-east-1:{dev_account}:model-package/{model_package_group_name}/1",
"ModelPackageArn": f"arn:aws:sagemaker:us-east-1:111:model-package/{model_package_group_name}/1",
"ModelPackageStatus": "Completed",
"ModelPackageName": model_package_group_name,
"CreationTime": "2021-01-01T00:00:00Z",
Expand All @@ -119,10 +117,10 @@ def test_synthesize_stack_latest_approved_model_package(mock_s3_client, stack_de
account=os.environ["CDK_DEFAULT_ACCOUNT"],
region=os.environ["CDK_DEFAULT_REGION"],
),
endpoint_config_prod_variant=dict(
variant_name="AllTraffic",
initial_variant_weight=1,
),
endpoint_config_prod_variant={
"initial_variant_weight": 1,
"variant_name": "AllTraffic",
},
)

template = Template.from_stack(endpoint_stack)
Expand Down

0 comments on commit 5744b8c

Please sign in to comment.