/
create-endpoint-config.test.ts
149 lines (138 loc) · 4.14 KB
/
create-endpoint-config.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import '@aws-cdk/assert-internal/jest';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as kms from '@aws-cdk/aws-kms';
import * as sfn from '@aws-cdk/aws-stepfunctions';
import * as cdk from '@aws-cdk/core';
import * as tasks from '../../lib';
let stack: cdk.Stack;
beforeEach(() => {
// GIVEN
stack = new cdk.Stack();
});
test('create basic endpoint config', () => {
// WHEN
const task = new tasks.SageMakerCreateEndpointConfig(stack, 'SagemakerEndpointConfig', {
endpointConfigName: 'MyEndpointConfig',
productionVariants: [{
initialInstanceCount: 2,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.XLARGE),
modelName: 'MyModel',
variantName: 'awesome-variant',
}],
});
// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::sagemaker:createEndpointConfig',
],
],
},
End: true,
Parameters: {
EndpointConfigName: 'MyEndpointConfig',
ProductionVariants: [{
InitialInstanceCount: 2,
InstanceType: 'ml.m5.xlarge',
ModelName: 'MyModel',
VariantName: 'awesome-variant',
}],
},
});
});
test('create complex endpoint config', () => {
// WHEN
const key = new kms.Key(stack, 'Key');
const task = new tasks.SageMakerCreateEndpointConfig(stack, 'SagemakerEndpointConfig', {
endpointConfigName: sfn.JsonPath.stringAt('$.Endpoint.EndpointConfig'),
kmsKey: key,
productionVariants: [{
initialInstanceCount: 1,
initialVariantWeight: 0.8,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.XLARGE),
modelName: 'MyModel',
variantName: 'awesome-variant',
},
{
initialInstanceCount: 1,
initialVariantWeight: 0.2,
instanceType: new ec2.InstanceType(sfn.JsonPath.stringAt('$.Endpoint.InstanceType')),
modelName: sfn.JsonPath.stringAt('$.Endpoint.Model'),
variantName: 'awesome-variant-2',
}],
tags: sfn.TaskInput.fromObject([{
Key: 'Project',
Value: 'ML',
}]),
});
// THEN
expect(stack.resolve(task.toStateJson())).toEqual({
Type: 'Task',
Resource: {
'Fn::Join': [
'',
[
'arn:',
{
Ref: 'AWS::Partition',
},
':states:::sagemaker:createEndpointConfig',
],
],
},
End: true,
Parameters: {
'EndpointConfigName.$': '$.Endpoint.EndpointConfig',
'KmsKeyId': {
Ref: 'Key961B73FD',
},
'ProductionVariants': [{
InitialInstanceCount: 1,
InitialVariantWeight: 0.8,
InstanceType: 'ml.m5.xlarge',
ModelName: 'MyModel',
VariantName: 'awesome-variant',
},
{
'InitialInstanceCount': 1,
'InitialVariantWeight': 0.2,
'InstanceType.$': '$.Endpoint.InstanceType',
'ModelName.$': '$.Endpoint.Model',
'VariantName': 'awesome-variant-2',
}],
'Tags': [
{
Key: 'Project',
Value: 'ML',
},
],
},
});
});
test('Cannot create a SageMaker create enpoint config task with empty production variant', () => {
expect(() => new tasks.SageMakerCreateEndpointConfig(stack, 'EndpointConfig', {
endpointConfigName: 'MyEndpointConfig',
productionVariants: [],
}))
.toThrowError(/Must specify from 1 to 10 production variants per endpoint configuration/);
});
test('Task throws if WAIT_FOR_TASK_TOKEN is supplied as service integration pattern', () => {
expect(() => new tasks.SageMakerCreateEndpointConfig(stack, 'EndpointConfig', {
endpointConfigName: 'MyEndpointConfig',
integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN,
productionVariants: [{
initialInstanceCount: 2,
instanceType: ec2.InstanceType.of(ec2.InstanceClass.M5, ec2.InstanceSize.XLARGE),
modelName: 'MyModel',
variantName: 'awesome-variant',
}],
}))
.toThrowError(/Unsupported service integration pattern. Supported Patterns: REQUEST_RESPONSE. Received: WAIT_FOR_TASK_TOKEN/i);
});