대규모로 명령 실행 - AWS Systems Manager

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

대규모로 명령 실행

AWS Systems Manager의 기능인 Run Command에서는 targets을 사용하여 관리형 노드의 플릿에 대해 명령을 실행할 수 있습니다. targets 파라미터는 관리형 노드에 대해 지정한 태그를 바탕으로 Key,Value 조합을 허용합니다. 명령을 실행하면 시스템에서 지정된 태그와 일치하는 모든 관리형 노드를 찾아 이러한 인스턴스에 대해 명령 실행을 시도합니다. 관리형 인스턴스의 태그 지정에 대한 자세한 내용은 AWS 리소스 태그 지정 사용 설명서의 AWS 리소스 태그 지정을 참조하세요. 관리형 IoT 디바이스 태그 지정에 대한 자세한 내용은 AWS IoT Greengrass Version 2개발자 안내서AWS IoT Greengrass Version 2 리소스 태그하기 섹션을 참조하세요.

다음 섹션에 설명된 대로 targets 파라미터를 사용하여 특정 관리형 노드 ID 목록을 대상으로 지정할 수도 있습니다.

수백 또는 수천 개의 관리형 노드에 걸쳐 명령 실행을 제어할 수 있도록 Run Command에는 하나의 요청을 동시에 처리할 수 있는 노드의 수와 명령이 취소되기 전에 명령에서 발생시킬 수 있는 오류의 수를 제한하기 위한 파라미터가 포함되어 있습니다.

다중 관리형 노드 대상 지정

태그, AWS 리소스 그룹 이름, 또는 관리형 노드 ID를 지정하여 명령 및 대상 관리 노드를 실행할 수 있습니다.

다음 예시에서는 AWS Command Line Interface(AWS CLI)에서 Run Command를 사용할 경우의 명령 형식을 보여줍니다. example resource placeholder를 사용자의 정보로 바꿉니다. 이번 단원의 샘플 명령은 [...]를 사용해 잘립니다.

예제 1: 태그를 대상으로 지정

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:tag-name,Values=tag-value \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:tag-name,Values=tag-value ^ [...]

예제 2: AWS 리소스 그룹을 대상으로 지정

명령 한 번마다 지정할 수 있는 리소스 그룹 이름은 최대 1개입니다. 리소스 그룹을 생성할 때는 그룹화 기준에서 AWS::SSM:ManagedInstanceAWS::EC2::Instance를 리소스 유형으로 추가하는 것이 좋습니다.

참고

리소스 그룹을 대상으로 지정하는 명령을 전송하려면 먼저 해당 그룹에 속한 리소스를 나열하거나 볼 수 있는 AWS Identity and Access Management(IAM) 권한을 부여해야 합니다. 자세한 내용은 AWS Resource Groups 사용 설명서권한 설정을 참조하세요.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=resource-groups:Name,Values=resource-group-name \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=resource-groups:Name,Values=resource-group-name ^ [...]

예제 3: 리소스 유형별로 AWS 리소스 그룹 태그 지정

명령 한 번마다 지정할 수 있는 리소스 그룹 유형은 최대 5개입니다. 리소스 그룹을 생성할 때는 그룹화 기준에서 AWS::SSM:ManagedInstanceAWS::EC2::Instance를 리소스 유형으로 추가하는 것이 좋습니다.

참고

리소스 그룹을 대상으로 지정하는 명령을 전송하려면 먼저 해당 그룹에 속한 리소스를 나열하거나 볼 수 있는 IAM 권한을 부여해야 합니다. 자세한 내용은 AWS Resource Groups 사용 설명서권한 설정을 참조하세요.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=resource-groups:ResourceTypeFilters,Values=resource-type-1,resource-type-2 \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=resource-groups:ResourceTypeFilters,Values=resource-type-1,resource-type-2 ^ [...]

예제 4: 인스턴스 ID를 대상으로 지정

다음 예에서는 instanceids 키와 targets 파라미터를 사용하여 관리형 노드를 대상으로 지정하는 방법을 보여줍니다. 각 디바이스에 mi-ID_number가 지정되어 있기 때문에 이 키를 사용하여 관리형 AWS IoT Greengrass 코어 디바이스를 대상으로 지정할 수 있습니다. AWS Systems Manager의 기능인 Fleet Manager에서 디바이스 ID를 확인할 수 있습니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=instanceids,Values=instance-ID-1,instance-ID-2,instance-ID-3 \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=instanceids,Values=instance-ID-1,instance-ID-2,instance-ID-3 ^ [...]

Environment라는 KeyDevelopment, Test, Pre-productionProductionValues를 사용하여 다양한 환경에 대해 관리형 노드에 태그를 지정한 경우에는 다음 구문과 함께 targets 파라미터를 사용해 이러한 환경 중 하나의 모든 관리형 노드로 명령을 보낼 수 있습니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:Environment,Values=Development \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:Environment,Values=Development ^ [...]

Values 목록에 추가하여 다른 환경의 추가 관리형 노드를 대상으로 지정할 수 있습니다. 쉼표를 사용하여 항목을 구분합니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:Environment,Values=Development,Test,Pre-production \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:Environment,Values=Development,Test,Pre-production ^ [...]

번형: Key 기준을 여러 개 사용하여 대상 세분화

Key 조건을 여러 개 포함시켜 명령의 대상 수를 세분화할 수 있습니다. Key 조건을 두 개 이상 포함시키면 시스템에서 모든 조건을 충족하는 관리형 노드를 대상으로 지정합니다. 다음 명령은 재무 부서에 대해 태그가 지정되고 또한 데이터베이스 서버 역할에 대해 태그가 지정된 모든 관리형 노드를 대상으로 지정합니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:Department,Values=Finance Key=tag:ServerRole,Values=Database \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:Department,Values=Finance Key=tag:ServerRole,Values=Database ^ [...]

번형: 여러 KeyValue 기준 사용

앞의 예제를 확장해 Values 조건에 항목을 추가로 포함시켜 여러 부서 및 여러 서버 역할을 대상으로 지정할 수 있습니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database ^ [...]

번형: 여러 Values 기준을 사용하여 태그가 지정된 관리형 노드를 대상으로 지정

Department라는 KeySales, FinanceValues를 사용하여 다양한 환경에 대해 관리형 노드에 태그를 지정한 경우에는 다음 구문과 함께 targets 파라미터를 사용해 이러한 환경의 모든 노드로 명령을 보낼 수 있습니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:Department,Values=Sales,Finance \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:Department,Values=Sales,Finance ^ [...]

최대 5개의 키와 각 키에 대해 5개의 값을 지정할 수 있습니다.

태그 키(태그 이름) 또는 태그 값에 공백이 포함된 경우 다음 예와 같이 태그 키 또는 값을 인용 부호로 묶습니다.

: Value 태그의 공백

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:OS,Values="Windows Server 2016 Nano" \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:OS,Values="Windows Server 2016 Nano" ^ [...]

: tag 키 및 Value의 공백

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key="tag:Operating System",Values="Windows Server 2016 Nano" \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key="tag:Operating System",Values="Windows Server 2016 Nano" ^ [...]

: Values 목록에서 한 항목의 공백

Linux & macOS
aws ssm send-command \ --document-name document-name \ --targets Key=tag:Department,Values="Sales","Finance","Systems Mgmt" \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --targets Key=tag:Department,Values="Sales","Finance","Systems Mgmt" ^ [...]

비율 제어 사용

동시성 제어오류 제어를 사용하여 그룹의 관리형 노드로 명령이 전송되는 비율을 제어할 수 있습니다.

동시성 제어 사용

max-concurrency 파라미터(Run a command(명령 실행) 페이지의 Concurrency(동시성) 옵션))로 명령을 동시에 실행하는 관리형 노드의 수를 제어할 수 있습니다. 관리형 노드의 절대 개수(예: 10)를 지정하거나 대상 집합의 비율(예: 10%)을 지정할 수 있습니다. 대기 중인 시스템은 단일 노드에 명령을 전송하고 시스템이 초기 호출을 승인할 때까지 기다렸다가 명령을 2개 더 많은 노드에 보냅니다. 시스템은 시스템이 max-concurrency 값을 충족할 때까지 기하급수적으로 더 많은 노드에 명령을 보냅니다. max-concurrency의 기본값은 50입니다. 다음 예는 max-concurrency 파라미터에 대한 값을 지정하는 방법을 보여줍니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --max-concurrency 10 \ --targets Key=tag:Environment,Values=Development \ [...]
aws ssm send-command \ --document-name document-name \ --max-concurrency 10% \ --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --max-concurrency 10 ^ --targets Key=tag:Environment,Values=Development ^ [...]
aws ssm send-command ^ --document-name document-name ^ --max-concurrency 10% ^ --targets Key=tag:Department,Values=Finance,Marketing Key=tag:ServerRole,Values=WebServer,Database ^ [...]

오류 제어 사용

max-errors 파라미터(명령 실행 페이지의 오류 임계값(Error threshold) 필드)로 오류 제한을 설정하여 수백 또는 수천 개의 관리형 노드에 대한 명령 실행을 제어할 수도 있습니다. 이 파라미터는 시스템이 추가 관리형 노드로의 명령 전송을 중지하기까지 허용되는 오류 횟수를 지정합니다. 오류의 절대 개수(예: 10)를 지정하거나 대상 집합의 비율(예: 10%)을 지정할 수 있습니다. 예를 들어 3을 지정하면 네 번째 오류를 받았을 때 명령 전송이 중지됩니다. 0을 지정하면 첫 번째 오류 결과가 반환된 후 추가 관리형 노드로의 명령 전송이 중지됩니다. 50개의관리형 노드로 명령을 보내고 max-errors10%로 설정하면 여섯 번째 오류를 받았을 때 추가 노드로의 명령 전송이 중지됩니다.

max-errors에 도달할 때 이미 명령을 실행 중인 호출은 완료될 수 있지만, 이런 호출 중 일부는 실패할 수도 있습니다. 실패한 호출 수가 max-errors보다 많지 않도록 해야 할 경우에는 호출이 한 번에 한 개를 초과하지 않도록 max-concurrency1로 설정하십시오. max-errors의 기본값은 0입니다. 다음 예는 max-errors 파라미터에 대한 값을 지정하는 방법을 보여줍니다.

Linux & macOS
aws ssm send-command \ --document-name document-name \ --max-errors 10 \ --targets Key=tag:Database,Values=Development \ [...]
aws ssm send-command \ --document-name document-name \ --max-errors 10% \ --targets Key=tag:Environment,Values=Development \ [...]
aws ssm send-command \ --document-name document-name \ --max-concurrency 1 \ --max-errors 1 \ --targets Key=tag:Environment,Values=Production \ [...]
Windows
aws ssm send-command ^ --document-name document-name ^ --max-errors 10 ^ --targets Key=tag:Database,Values=Development ^ [...]
aws ssm send-command ^ --document-name document-name ^ --max-errors 10% ^ --targets Key=tag:Environment,Values=Development ^ [...]
aws ssm send-command ^ --document-name document-name ^ --max-concurrency 1 ^ --max-errors 1 ^ --targets Key=tag:Environment,Values=Production ^ [...]