Skip to content

Commit cb8bc65

Browse files
fix: update sagemaker.serverless integration test (#2533)
Co-authored-by: Shreya Pandit <[email protected]>
1 parent bd43571 commit cb8bc65

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

tests/conftest.py

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def boto_session(request):
9797
return boto3.Session(region_name=DEFAULT_REGION)
9898

9999

100+
@pytest.fixture(scope="session")
101+
def account(boto_session):
102+
return boto_session.client("sts").get_caller_identity()["Account"]
103+
104+
105+
@pytest.fixture(scope="session")
106+
def region(boto_session):
107+
return boto_session.region_name
108+
109+
100110
@pytest.fixture(scope="session")
101111
def sagemaker_session(sagemaker_client_config, sagemaker_runtime_config, boto_session):
102112
sagemaker_client_config.setdefault("config", Config(retries=dict(max_attempts=10)))

tests/integ/test_serverless.py

+36-14
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,47 @@
1212
# language governing permissions and limitations under the License.
1313
from __future__ import absolute_import
1414

15-
import os
16-
1715
import pytest
1816

1917
from sagemaker.serverless import LambdaModel
2018
from sagemaker.utils import unique_name_from_base
2119

22-
# See tests/data/serverless for the image source code.
23-
IMAGE_URI = "142577830533.dkr.ecr.us-west-2.amazonaws.com/serverless-integ-test:latest"
24-
ROLE = "arn:aws:iam::142577830533:role/lambda_basic_execution"
25-
URL = "https://c.files.bbci.co.uk/12A9B/production/_111434467_gettyimages-1143489763.jpg"
20+
URL = "https://sagemaker-integ-tests-data.s3.us-east-1.amazonaws.com/cat.jpeg"
21+
22+
REPOSITORY_NAME = "serverless-integ-test"
23+
ROLE_NAME = "LambdaExecutionRole"
24+
25+
26+
@pytest.fixture(name="image_uri", scope="module")
27+
def fixture_image_uri(account, region):
28+
return f"{account}.dkr.ecr.{region}.amazonaws.com/{REPOSITORY_NAME}:latest"
29+
30+
31+
@pytest.fixture(name="role", scope="module")
32+
def fixture_role(account):
33+
return f"arn:aws:iam::{account}:role/{ROLE_NAME}"
34+
35+
36+
@pytest.fixture(name="client", scope="module")
37+
def fixture_client(boto_session):
38+
return boto_session.client("lambda")
39+
40+
41+
@pytest.fixture(name="repository_exists", scope="module")
42+
def fixture_repository_exists(boto_session):
43+
client = boto_session.client("ecr")
44+
try:
45+
client.describe_repositories(repositoryNames=[REPOSITORY_NAME])
46+
return True
47+
except client.exceptions.RepositoryNotFoundException:
48+
return False
49+
2650

51+
def test_lambda(image_uri, role, client, repository_exists):
52+
if not repository_exists:
53+
pytest.skip("The container image required to run this test does not exist.")
2754

28-
@pytest.mark.skipif(
29-
"CODEBUILD_BUILD_ID" not in os.environ,
30-
reason="The container image is private to the CI account.",
31-
)
32-
def test_lambda():
33-
model = LambdaModel(image_uri=IMAGE_URI, role=ROLE)
55+
model = LambdaModel(image_uri=image_uri, role=role, client=client)
3456

3557
predictor = model.deploy(
3658
unique_name_from_base("my-lambda-function"), timeout=60, memory_size=4092
@@ -39,5 +61,5 @@ def test_lambda():
3961

4062
assert prediction == {"class": "tabby"}
4163

42-
model.destroy()
43-
predictor.destroy()
64+
model.delete_model()
65+
predictor.delete_predictor()

0 commit comments

Comments
 (0)