Skip to content
v2.274.0

Experimental

@aws-cdk/aws-sagemaker-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

ScalableInstanceCount ​

A scalable sagemaker endpoint attribute.

Example ​

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

declare const model: sagemaker.Model;

const variantName = 'my-variant';
const endpointConfig = new sagemaker.EndpointConfig(this, 'EndpointConfig', {
  instanceProductionVariants: [
    {
      model: model,
      variantName: variantName,
    },
  ]
});

const endpoint = new sagemaker.Endpoint(this, 'Endpoint', { endpointConfig });
const productionVariant = endpoint.findInstanceProductionVariant(variantName);
const instanceCount = productionVariant.autoScaleInstanceCount({
  maxCapacity: 3
});
instanceCount.scaleOnInvocations('LimitRPS', {
  maxRequestsPerSecond: 30,
});
python
import aws_cdk.aws_sagemaker_alpha as sagemaker

# model: sagemaker.Model


variant_name = "my-variant"
endpoint_config = sagemaker.EndpointConfig(self, "EndpointConfig",
    instance_production_variants=[sagemaker.InstanceProductionVariantProps(
        model=model,
        variant_name=variant_name
    )
    ]
)

endpoint = sagemaker.Endpoint(self, "Endpoint", endpoint_config=endpoint_config)
production_variant = endpoint.find_instance_production_variant(variant_name)
instance_count = production_variant.auto_scale_instance_count(
    max_capacity=3
)
instance_count.scale_on_invocations("LimitRPS",
    max_requests_per_second=30
)
java
import software.amazon.awscdk.services.sagemaker.alpha.*;

Model model;


String variantName = "my-variant";
EndpointConfig endpointConfig = EndpointConfig.Builder.create(this, "EndpointConfig")
        .instanceProductionVariants(List.of(InstanceProductionVariantProps.builder()
                .model(model)
                .variantName(variantName)
                .build()))
        .build();

Endpoint endpoint = Endpoint.Builder.create(this, "Endpoint").endpointConfig(endpointConfig).build();
IEndpointInstanceProductionVariant productionVariant = endpoint.findInstanceProductionVariant(variantName);
ScalableInstanceCount instanceCount = productionVariant.autoScaleInstanceCount(EnableScalingProps.builder()
        .maxCapacity(3)
        .build());
instanceCount.scaleOnInvocations("LimitRPS", InvocationsScalingProps.builder()
        .maxRequestsPerSecond(30)
        .build());
csharp
// Install: dotnet add package Amazon.CDK.AWS.Sagemaker.Alpha
using Amazon.CDK.AWS.Sagemaker.Alpha;

Model model;


var variantName = "my-variant";
var endpointConfig = new EndpointConfig(this, "EndpointConfig", new EndpointConfigProps {
    InstanceProductionVariants = new [] { new InstanceProductionVariantProps {
        Model = model,
        VariantName = variantName
    } }
});

var endpoint = new Endpoint(this, "Endpoint", new EndpointProps { EndpointConfig = endpointConfig });
var productionVariant = endpoint.FindInstanceProductionVariant(variantName);
var instanceCount = productionVariant.AutoScaleInstanceCount(new EnableScalingProps {
    MaxCapacity = 3
});
instanceCount.ScaleOnInvocations("LimitRPS", new InvocationsScalingProps {
    MaxRequestsPerSecond = 30
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdksagemakeralpha/v2
import "github.com/aws/aws-cdk-go/awscdksagemakeralpha"

var model Model


variantName := "my-variant"
endpointConfig := sagemaker.NewEndpointConfig(this, jsii.String("EndpointConfig"), &EndpointConfigProps{
	InstanceProductionVariants: []InstanceProductionVariantProps{
		&InstanceProductionVariantProps{
			Model: model,
			VariantName: variantName,
		},
	},
})

endpoint := sagemaker.NewEndpoint(this, jsii.String("Endpoint"), &EndpointProps{
	EndpointConfig: EndpointConfig,
})
productionVariant := endpoint.FindInstanceProductionVariant(variantName)
instanceCount := productionVariant.AutoScaleInstanceCount(&EnableScalingProps{
	MaxCapacity: jsii.Number(3),
})
instanceCount.ScaleOnInvocations(jsii.String("LimitRPS"), &InvocationsScalingProps{
	MaxRequestsPerSecond: jsii.Number(30),
})

Initializer ​

ts
new ScalableInstanceCount(scope: Construct, id: string, props: ScalableInstanceCountProps)
python
ScalableInstanceCount(scope: Construct, id: str, props: ScalableInstanceCountProps)
java
new ScalableInstanceCount(Construct scope, String id, ScalableInstanceCountProps props)
csharp
new ScalableInstanceCount(Construct scope, string id, ScalableInstanceCountProps props)
go
NewScalableInstanceCount(Scope Construct, Id *string, Props ScalableInstanceCountProps)

Construct Props ​

dimensionstringdimensionstrdimensionStringDimensionstringDimension*stringrequired#
Scalable dimension of the attribute.
maxCapacitynumbermax_capacityint | floatmaxCapacityNumberMaxCapacitydoubleMaxCapacity*float64required#
Maximum capacity to scale to.
minCapacitynumbermin_capacityint | floatminCapacityNumberMinCapacitydoubleMinCapacity*float64= 1#
Minimum capacity to scale to.
resourceIdstringresource_idstrresourceIdStringResourceIdstringResourceId*stringrequired#
Resource ID of the attribute.
roleIRoleroleIRoleroleIRoleRoleIRoleRoleIRolerequired#
Role to use for scaling.
serviceNamespaceServiceNamespaceservice_namespaceServiceNamespaceserviceNamespaceServiceNamespaceServiceNamespaceServiceNamespaceServiceNamespaceServiceNamespacerequired#
Service namespace of the scalable attribute.

Properties ​

The environment this resource belongs to.
notes

For resources that are created and managed in a Stack (those created by creating new class instances like new Role(), new Bucket(), etc.), this is always the same as the environment of the stack they belong to.

For referenced resources (those obtained from referencing methods like Role.fromRoleArn(), Bucket.fromBucketName(), etc.), they might be different than the stack they were imported into.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
scalableTargetRefScalableTargetReferencescalable_target_refScalableTargetReferencescalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferenceScalableTargetRefScalableTargetReferencerequired#
A reference to a ScalableTarget resource.

Methods ​

isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

Parameters

  • xxxxX — Any object.

Returns: true if x is an object created from a class which extends Construct.

scaleOnInvocations(id: string, props: InvocationsScalingProps): voiddef scale_on_invocations(self, id: str, props: InvocationsScalingProps) -> Nonepublic void scaleOnInvocations(String id, InvocationsScalingProps props)public void ScaleOnInvocations(string id, InvocationsScalingProps props)func ScaleOnInvocations(Id *string, Props InvocationsScalingProps)#
Scales in or out to achieve a target requests per second per instance.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining