文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 AWS SDK 範例。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
UpdateComputeEnvironment
搭配 AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 UpdateComputeEnvironment
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- CLI
-
- AWS CLI
-
更新運算環境
此範例會停用 P2OnDemand 運算環境,以便將其刪除。
命令:
aws batch update-compute-environment --compute-environment P2OnDemand
--state DISABLED
輸出:
{
"computeEnvironmentName": "P2OnDemand",
"computeEnvironmentArn": "arn:aws:batch:us-east-1:012345678910:compute-environment/P2OnDemand"
}
- Java
-
- SDK for Java 2.x
-
/**
* Disables the specified compute environment asynchronously.
*
* @param computeEnvironmentName the name of the compute environment to disable
* @return a CompletableFuture that completes when the compute environment is disabled
*/
public CompletableFuture<UpdateComputeEnvironmentResponse> disableComputeEnvironmentAsync(String computeEnvironmentName) {
UpdateComputeEnvironmentRequest updateRequest = UpdateComputeEnvironmentRequest.builder()
.computeEnvironment(computeEnvironmentName)
.state(CEState.DISABLED)
.build();
CompletableFuture<UpdateComputeEnvironmentResponse> responseFuture = getAsyncClient().updateComputeEnvironment(updateRequest);
responseFuture.whenComplete((response, ex) -> {
if (ex != null) {
throw new RuntimeException("Failed to disable compute environment: " + ex.getMessage(), ex);
}
});
return responseFuture;
}