12
12
# language governing permissions and limitations under the License.
13
13
from __future__ import absolute_import
14
14
15
- import os
16
-
17
15
import pytest
18
16
19
17
from sagemaker .serverless import LambdaModel
20
18
from sagemaker .utils import unique_name_from_base
21
19
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
+
26
50
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." )
27
54
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 )
34
56
35
57
predictor = model .deploy (
36
58
unique_name_from_base ("my-lambda-function" ), timeout = 60 , memory_size = 4092
@@ -39,5 +61,5 @@ def test_lambda():
39
61
40
62
assert prediction == {"class" : "tabby" }
41
63
42
- model .destroy ()
43
- predictor .destroy ()
64
+ model .delete_model ()
65
+ predictor .delete_predictor ()
0 commit comments