文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DeleteScalingPolicy
搭配 a AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DeleteScalingPolicy
。
- CLI
-
- AWS CLI
-
若要刪除擴展政策
此範例會刪除在預設叢集中執行的 Amazon ECS 服務 Web 應用程式擴展政策。
命令:
aws application-autoscaling delete-scaling-policy --policy-name
web-app-cpu-lt-25
--scalable-dimensionecs:service:DesiredCount
--resource-idservice/default/web-app
--service-namespaceecs
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DeleteScalingPolicy
。
-
- Java
-
- Java 2.x 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.applicationautoscaling.ApplicationAutoScalingClient; import software.amazon.awssdk.services.applicationautoscaling.model.ApplicationAutoScalingException; import software.amazon.awssdk.services.applicationautoscaling.model.DeleteScalingPolicyRequest; import software.amazon.awssdk.services.applicationautoscaling.model.DeregisterScalableTargetRequest; import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalableTargetsRequest; import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalableTargetsResponse; import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalingPoliciesRequest; import software.amazon.awssdk.services.applicationautoscaling.model.DescribeScalingPoliciesResponse; import software.amazon.awssdk.services.applicationautoscaling.model.ScalableDimension; import software.amazon.awssdk.services.applicationautoscaling.model.ServiceNamespace; /** * Before running this Java V2 code example, set up your development environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DisableDynamoDBAutoscaling { public static void main(String[] args) { final String usage = """ Usage: <tableId> <policyName>\s Where: tableId - The table Id value (for example, table/Music).\s policyName - The name of the policy (for example, $Music5-scaling-policy). """; if (args.length != 2) { System.out.println(usage); System.exit(1); } ApplicationAutoScalingClient appAutoScalingClient = ApplicationAutoScalingClient.builder() .region(Region.US_EAST_1) .build(); ServiceNamespace ns = ServiceNamespace.DYNAMODB; ScalableDimension tableWCUs = ScalableDimension.DYNAMODB_TABLE_WRITE_CAPACITY_UNITS; String tableId = args[0]; String policyName = args[1]; deletePolicy(appAutoScalingClient, policyName, tableWCUs, ns, tableId); verifyScalingPolicies(appAutoScalingClient, tableId, ns, tableWCUs); deregisterScalableTarget(appAutoScalingClient, tableId, ns, tableWCUs); verifyTarget(appAutoScalingClient, tableId, ns, tableWCUs); } public static void deletePolicy(ApplicationAutoScalingClient appAutoScalingClient, String policyName, ScalableDimension tableWCUs, ServiceNamespace ns, String tableId) { try { DeleteScalingPolicyRequest delSPRequest = DeleteScalingPolicyRequest.builder() .policyName(policyName) .scalableDimension(tableWCUs) .serviceNamespace(ns) .resourceId(tableId) .build(); appAutoScalingClient.deleteScalingPolicy(delSPRequest); System.out.println(policyName +" was deleted successfully."); } catch (ApplicationAutoScalingException e) { System.err.println(e.awsErrorDetails().errorMessage()); } } // Verify that the scaling policy was deleted public static void verifyScalingPolicies(ApplicationAutoScalingClient appAutoScalingClient, String tableId, ServiceNamespace ns, ScalableDimension tableWCUs) { DescribeScalingPoliciesRequest dscRequest = DescribeScalingPoliciesRequest.builder() .scalableDimension(tableWCUs) .serviceNamespace(ns) .resourceId(tableId) .build(); DescribeScalingPoliciesResponse response = appAutoScalingClient.describeScalingPolicies(dscRequest); System.out.println("DescribeScalableTargets result: "); System.out.println(response); } public static void deregisterScalableTarget(ApplicationAutoScalingClient appAutoScalingClient, String tableId, ServiceNamespace ns, ScalableDimension tableWCUs) { try { DeregisterScalableTargetRequest targetRequest = DeregisterScalableTargetRequest.builder() .scalableDimension(tableWCUs) .serviceNamespace(ns) .resourceId(tableId) .build(); appAutoScalingClient.deregisterScalableTarget(targetRequest); System.out.println("The scalable target was deregistered."); } catch (ApplicationAutoScalingException e) { System.err.println(e.awsErrorDetails().errorMessage()); } } public static void verifyTarget(ApplicationAutoScalingClient appAutoScalingClient, String tableId, ServiceNamespace ns, ScalableDimension tableWCUs) { DescribeScalableTargetsRequest dscRequest = DescribeScalableTargetsRequest.builder() .scalableDimension(tableWCUs) .serviceNamespace(ns) .resourceIds(tableId) .build(); DescribeScalableTargetsResponse response = appAutoScalingClient.describeScalableTargets(dscRequest); System.out.println("DescribeScalableTargets result: "); System.out.println(response); } }
-
如需 API 詳細資訊,請參閱 DeleteScalingPolicy AWS SDK for Java 2.x 參考中的 API。
-
- PowerShell
-
- for PowerShell 工具
-
範例 1:此 cmdlet 會刪除 Application Auto Scaling 可擴展目標的指定擴展政策。
Remove-AASScalingPolicy -ServiceNamespace AppStream -PolicyName "default-scale-out" -ResourceId fleet/Test -ScalableDimension appstream:fleet:DesiredCapacity
-
如需 API 詳細資訊,請參閱 AWS Tools for PowerShell Cmdlet 參考中的 DeleteScalingPolicy。
-
動作
DeleteScheduledAction