Search in sources :

Example 1 with PredefinedMetricSpecification

use of com.amazonaws.services.applicationautoscaling.model.PredefinedMetricSpecification in project aws-doc-sdk-examples by awsdocs.

the class EnableDynamoDBAutoscaling method main.

public static void main(String[] args) {
    ServiceNamespace ns = ServiceNamespace.Dynamodb;
    ScalableDimension tableWCUs = ScalableDimension.DynamodbTableWriteCapacityUnits;
    String resourceID = "table/TestTable";
    // Define the scalable target
    RegisterScalableTargetRequest rstRequest = new RegisterScalableTargetRequest().withServiceNamespace(ns).withResourceId(resourceID).withScalableDimension(tableWCUs).withMinCapacity(5).withMaxCapacity(10).withRoleARN("SERVICE_ROLE_ARN_GOES_HERE");
    try {
        aaClient.registerScalableTarget(rstRequest);
    } catch (Exception e) {
        System.err.println("Unable to register scalable target: ");
        System.err.println(e.getMessage());
    }
    // Verify that the target was created
    DescribeScalableTargetsRequest dscRequest = new DescribeScalableTargetsRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceIds(resourceID);
    try {
        DescribeScalableTargetsResult dsaResult = aaClient.describeScalableTargets(dscRequest);
        System.out.println("DescribeScalableTargets result: ");
        System.out.println(dsaResult);
        System.out.println();
    } catch (Exception e) {
        System.err.println("Unable to describe scalable target: ");
        System.err.println(e.getMessage());
    }
    System.out.println();
    // Configure a scaling policy
    TargetTrackingScalingPolicyConfiguration targetTrackingScalingPolicyConfiguration = new TargetTrackingScalingPolicyConfiguration().withPredefinedMetricSpecification(new PredefinedMetricSpecification().withPredefinedMetricType(MetricType.DynamoDBWriteCapacityUtilization)).withTargetValue(50.0).withScaleInCooldown(60).withScaleOutCooldown(60);
    // Create the scaling policy, based on your configuration
    PutScalingPolicyRequest pspRequest = new PutScalingPolicyRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID).withPolicyName("MyScalingPolicy").withPolicyType(PolicyType.TargetTrackingScaling).withTargetTrackingScalingPolicyConfiguration(targetTrackingScalingPolicyConfiguration);
    try {
        aaClient.putScalingPolicy(pspRequest);
    } catch (Exception e) {
        System.err.println("Unable to put scaling policy: ");
        System.err.println(e.getMessage());
    }
    // Verify that the scaling policy was created
    DescribeScalingPoliciesRequest dspRequest = new DescribeScalingPoliciesRequest().withServiceNamespace(ns).withScalableDimension(tableWCUs).withResourceId(resourceID);
    try {
        DescribeScalingPoliciesResult dspResult = aaClient.describeScalingPolicies(dspRequest);
        System.out.println("DescribeScalingPolicies result: ");
        System.out.println(dspResult);
    } catch (Exception e) {
        e.printStackTrace();
        System.err.println("Unable to describe scaling policy: ");
        System.err.println(e.getMessage());
    }
}
Also used : RegisterScalableTargetRequest(com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetRequest) ServiceNamespace(com.amazonaws.services.applicationautoscaling.model.ServiceNamespace) PutScalingPolicyRequest(com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyRequest) ScalableDimension(com.amazonaws.services.applicationautoscaling.model.ScalableDimension) DescribeScalingPoliciesRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesRequest) DescribeScalingPoliciesResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesResult) DescribeScalableTargetsRequest(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest) TargetTrackingScalingPolicyConfiguration(com.amazonaws.services.applicationautoscaling.model.TargetTrackingScalingPolicyConfiguration) DescribeScalableTargetsResult(com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult) PredefinedMetricSpecification(com.amazonaws.services.applicationautoscaling.model.PredefinedMetricSpecification)

Aggregations

DescribeScalableTargetsRequest (com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsRequest)1 DescribeScalableTargetsResult (com.amazonaws.services.applicationautoscaling.model.DescribeScalableTargetsResult)1 DescribeScalingPoliciesRequest (com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesRequest)1 DescribeScalingPoliciesResult (com.amazonaws.services.applicationautoscaling.model.DescribeScalingPoliciesResult)1 PredefinedMetricSpecification (com.amazonaws.services.applicationautoscaling.model.PredefinedMetricSpecification)1 PutScalingPolicyRequest (com.amazonaws.services.applicationautoscaling.model.PutScalingPolicyRequest)1 RegisterScalableTargetRequest (com.amazonaws.services.applicationautoscaling.model.RegisterScalableTargetRequest)1 ScalableDimension (com.amazonaws.services.applicationautoscaling.model.ScalableDimension)1 ServiceNamespace (com.amazonaws.services.applicationautoscaling.model.ServiceNamespace)1 TargetTrackingScalingPolicyConfiguration (com.amazonaws.services.applicationautoscaling.model.TargetTrackingScalingPolicyConfiguration)1