AWS SDK 예제 GitHub 리포지토리에 더 많은 AWS문서 SDK 예제
AWS SDK 또는 CLI와 함께 UnmonitorInstances 사용
다음 코드 예시는 UnmonitorInstances의 사용 방법을 보여 줍니다.
작업 예제는 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 다음 코드 예제에서는 컨텍스트 내에서 이 작업을 확인할 수 있습니다.
- C++
-
- SDK for C++
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. //! Disable monitoring for an EC2 instance. /*! \param instanceId: An EC2 instance ID. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::EC2::disableMonitoring(const Aws::String &instanceId, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::EC2::EC2Client ec2Client(clientConfiguration); Aws::EC2::Model::UnmonitorInstancesRequest unrequest; unrequest.AddInstanceIds(instanceId); unrequest.SetDryRun(true); Aws::EC2::Model::UnmonitorInstancesOutcome dryRunOutcome = ec2Client.UnmonitorInstances(unrequest); if (dryRunOutcome.IsSuccess()) { std::cerr << "Failed dry run to disable monitoring on instance. A dry run should trigger an error." << std::endl; return false; } else if (dryRunOutcome.GetError().GetErrorType() != Aws::EC2::EC2Errors::DRY_RUN_OPERATION) { std::cout << "Failed dry run to disable monitoring on instance " << instanceId << ": " << dryRunOutcome.GetError().GetMessage() << std::endl; return false; } unrequest.SetDryRun(false); Aws::EC2::Model::UnmonitorInstancesOutcome unmonitorInstancesOutcome = ec2Client.UnmonitorInstances(unrequest); if (!unmonitorInstancesOutcome.IsSuccess()) { std::cout << "Failed to disable monitoring on instance " << instanceId << ": " << unmonitorInstancesOutcome.GetError().GetMessage() << std::endl; } else { std::cout << "Successfully disable monitoring on instance " << instanceId << std::endl; } return unmonitorInstancesOutcome.IsSuccess(); }-
API 세부 정보는 AWS SDK for C++ API 참조의 UnmonitorInstances를 참조하십시오.
-
- CLI
-
- AWS CLI
-
인스턴스에 대한 세부 모니터링을 비활성화하는 방법
이 예제 명령은 지정된 인스턴스에 대한 세부 모니터링을 비활성화합니다.
명령:
aws ec2 unmonitor-instances --instance-idsi-1234567890abcdef0출력:
{ "InstanceMonitorings": [ { "InstanceId": "i-1234567890abcdef0", "Monitoring": { "State": "disabling" } } ] }-
API 세부 정보는 AWS CLI 명령 참조에서 UnmonitorInstances
를 참조하세요.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
참고
GitHub에 더 많은 내용이 있습니다. AWS 코드 예제 리포지토리
에서 전체 예제를 찾고 설정 및 실행하는 방법을 배워보세요. import { EC2Client, UnmonitorInstancesCommand } from "@aws-sdk/client-ec2"; import { fileURLToPath } from "node:url"; import { parseArgs } from "node:util"; /** * Turn off detailed monitoring for the selected instance. * @param {{ instanceIds: string[] }} options */ export const main = async ({ instanceIds }) => { const client = new EC2Client({}); const command = new UnmonitorInstancesCommand({ InstanceIds: instanceIds, }); try { const { InstanceMonitorings } = await client.send(command); const instanceMonitoringsList = InstanceMonitorings.map( (im) => ` • Detailed monitoring state for ${im.InstanceId} is ${im.Monitoring.State}.`, ); console.log("Monitoring status:"); console.log(instanceMonitoringsList.join("\n")); } catch (caught) { if ( caught instanceof Error && caught.name === "InvalidInstanceID.NotFound" ) { console.warn(`${caught.message}`); } else { throw caught; } } };-
API 세부 정보는 AWS SDK for JavaScript API 참조의 UnmonitorInstances를 참조하십시오.
-
- PowerShell
-
- Tools for PowerShell V4
-
예제 1: 이 예제에서는 지정된 인스턴스에 대한 세부 모니터링을 비활성화합니다.
Stop-EC2InstanceMonitoring -InstanceId i-12345678출력:
InstanceId Monitoring ---------- ---------- i-12345678 Amazon.EC2.Model.Monitoring-
API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조(V4)의 UnmonitorInstances를 참조하세요.
-
- Tools for PowerShell V5
-
예제 1: 이 예제에서는 지정된 인스턴스에 대한 세부 모니터링을 비활성화합니다.
Stop-EC2InstanceMonitoring -InstanceId i-12345678출력:
InstanceId Monitoring ---------- ---------- i-12345678 Amazon.EC2.Model.Monitoring-
API 세부 정보는 AWS Tools for PowerShell Cmdlet 참조(V5)의 UnmonitorInstances를 참조하세요.
-