Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 131 additions & 0 deletions enhanced_integ_test.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can keep the integration test in one file. We have another integration test file integ.endpoint-config. We can put all the necessary integration-test related code in that file and remove this one.

Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import * as path from 'path';
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import * as sagemaker from '../lib';

/*
* Stack verification steps:
* aws sagemaker describe-endpoint-config --endpoint-config-name <endpoint config name>
*
* For instance-based endpoint config, the above command will result in the following output:
* {
* "EndpointConfigName": "EndpointConfig...",
* "EndpointConfigArn": "arn:aws:sagemaker:...",
* "ProductionVariants": [
* {
* "VariantName": "firstVariant",
* "ModelName": "ModelWithArtifactAndVpcModel...",
* "InitialInstanceCount": 1,
* "InstanceType": "ml.m5.large",
* "InitialVariantWeight": 1.0
* },
* {
* "VariantName": "secondVariant",
* "ModelName": "ModelWithArtifactAndVpcModel...",
* "InitialInstanceCount": 1,
* "InstanceType": "ml.t2.medium",
* "InitialVariantWeight": 1.0
* },
* {
* "VariantName": "thirdVariant",
* "ModelName": "ModelWithoutArtifactAndVpcModel...",
* "InitialInstanceCount": 1,
* "InstanceType": "ml.t2.medium",
* "InitialVariantWeight": 2.0
* }
* ],
* "CreationTime": "..."
* }
*
* For serverless endpoint config, the command will show:
* {
* "EndpointConfigName": "ServerlessEndpointConfig...",
* "EndpointConfigArn": "arn:aws:sagemaker:...",
* "ProductionVariants": [
* {
* "VariantName": "serverlessVariant",
* "ModelName": "ModelWithoutArtifactAndVpcModel...",
* "InitialVariantWeight": 1.0,
* "ServerlessConfig": {
* "MaxConcurrency": 10,
* "MemorySizeInMB": 2048,
* "ProvisionedConcurrency": 5
* }
* }
* ],
* "CreationTime": "..."
* }
*/

const app = new cdk.App();
const stack = new cdk.Stack(app, 'aws-cdk-sagemaker-endpointconfig');

const image = sagemaker.ContainerImage.fromAsset(path.join(__dirname, 'test-image'));
const modelData = sagemaker.ModelData.fromAsset(path.join(__dirname, 'test-artifacts', 'valid-artifact.tar.gz'));

const modelWithArtifactAndVpc = new sagemaker.Model(stack, 'ModelWithArtifactAndVpc', {
containers: [{ image, modelData }],
vpc: new ec2.Vpc(stack, 'VPC', { restrictDefaultSecurityGroup: false }),
});
const modelWithoutArtifactAndVpc = new sagemaker.Model(stack, 'ModelWithoutArtifactAndVpc', {
containers: [{ image }],
});

// Test instance-based endpoint configuration
const endpointConfig = new sagemaker.EndpointConfig(stack, 'EndpointConfig', {
instanceProductionVariants: [
{
model: modelWithArtifactAndVpc,
variantName: 'firstVariant',
instanceType: sagemaker.InstanceType.M5_LARGE,
},
{
model: modelWithArtifactAndVpc,
variantName: 'secondVariant',
},
],
});
endpointConfig.addInstanceProductionVariant({
model: modelWithoutArtifactAndVpc,
variantName: 'thirdVariant',
initialVariantWeight: 2.0,
});

// Test serverless endpoint configuration with all properties
new sagemaker.EndpointConfig(stack, 'ServerlessEndpointConfig', {
serverlessProductionVariant: {
model: modelWithoutArtifactAndVpc,
variantName: 'serverlessVariant',
maxConcurrency: 10,
memorySizeInMB: 2048,
provisionedConcurrency: 5,
initialVariantWeight: 1.0,
},
});

// Test serverless endpoint configuration with minimal properties
new sagemaker.EndpointConfig(stack, 'MinimalServerlessEndpointConfig', {
serverlessProductionVariant: {
model: modelWithoutArtifactAndVpc,
variantName: 'minimalServerlessVariant',
maxConcurrency: 1,
memorySizeInMB: 1024,
// No provisionedConcurrency - testing optional property
},
});

// Test serverless endpoint configuration with boundary values
new sagemaker.EndpointConfig(stack, 'BoundaryServerlessEndpointConfig', {
serverlessProductionVariant: {
model: modelWithoutArtifactAndVpc,
variantName: 'boundaryServerlessVariant',
maxConcurrency: 200, // Maximum allowed
memorySizeInMB: 6144, // Maximum allowed
provisionedConcurrency: 200, // Maximum allowed (equal to maxConcurrency)
},
});

new IntegTest(app, 'integtest-endpointconfig', {
testCases: [stack],
});
32 changes: 32 additions & 0 deletions packages/@aws-cdk/aws-sagemaker-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,38 @@ const endpointConfig = new sagemaker.EndpointConfig(this, 'EndpointConfig', {
});
```

### Serverless Inference

Amazon SageMaker Serverless Inference is a purpose-built inference option that makes it easy for you to deploy and scale ML models. Serverless endpoints automatically launch compute resources and scale them in and out depending on traffic, eliminating the need to choose instance types or manage scaling policies.

To create a serverless endpoint configuration, use the `serverlessProductionVariant` property:

```typescript
import * as sagemaker from '@aws-cdk/aws-sagemaker-alpha';

declare const model: sagemaker.Model;

const endpointConfig = new sagemaker.EndpointConfig(this, 'ServerlessEndpointConfig', {
serverlessProductionVariant: {
model: model,
variantName: 'serverlessVariant',
maxConcurrency: 10,
memorySizeInMB: 2048,
provisionedConcurrency: 5, // optional
},
});
```

Serverless inference is ideal for workloads with intermittent or unpredictable traffic patterns. You can configure:

- `maxConcurrency`: Maximum concurrent invocations (1-200)
- `memorySizeInMB`: Memory allocation in 1GB increments (1024, 2048, 3072, 4096, 5120, or 6144 MB)
- `provisionedConcurrency`: Optional pre-warmed capacity to reduce cold starts

**Note**: Provisioned concurrency incurs charges even when the endpoint is not processing requests. Use it only when you need to minimize cold start latency.

You cannot mix serverless and instance-based variants in the same endpoint configuration.

### Endpoint

When you create an endpoint from an `EndpointConfig`, Amazon SageMaker launches the ML compute
Expand Down
Loading
Loading