문서 작업 - AWS Systems Manager

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

문서 작업

이 섹션에는 SSM 문서 사용 및 작업 방법에 대한 정보가 포함되어 있습니다.

State Manager 연결에서 SSM 문서 사용

AWS Systems Manager의 기능인 State Manager용 SSM 문서를 생성하는 경우 문서를 시스템에 추가한 후 관리형 인스턴스에 연결해야 합니다. 자세한 내용은 Systems Manager에서 연결 작업 섹션을 참조하세요.

State Manager 연결에서 SSM 문서를 사용할 때는 다음 세부 사항에 유의하세요.

  • 다양한 문서를 사용하는 서로 다른 State Manager 연결을 생성하여 대상에 여러 문서를 할당할 수 있습니다.

  • 서로 충돌하는 플러그인(예: 도메인 조인과 도메인으로부터 제거) 문서를 생성하면 마지막으로 실행된 플러그인이 최종 상태가 됩니다. State Manager는 문서 내에서 명령이나 플러그인의 논리적 순서나 무결성을 확인하지 않습니다.

  • 문서를 처리할 때 인스턴스 연결이 먼저 적용된 다음 태그 지정된 그룹 연결이 적용됩니다. 인스턴스가 여러 태그 지정된 그룹의 일부인 경우 태그 지정된 그룹의 일부인 문서는 특정 순서로 실행되지 않습니다. 인스턴스가 인스턴스 ID별로 여러 문서를 통해 직접 대상으로 지정되면 특정한 실행 순서가 없습니다.

  • State Manager에 대한 SSM Policy 문서의 기본 버전을 변경할 경우 이 문서를 사용하는 연결은 다음 번에 Systems Manager가 인스턴스에 연결을 적용할 때 새로운 기본 버전을 사용하기 시작합니다.

  • 공유되는 SSM 문서를 사용하여 연결을 생성하고, 소유자가 문서 공유를 중지한 경우 연결에서 해당 문서에 더 이상 액세스할 수 없습니다. 하지만 소유자가 나중에 동일한 SSM 문서를 공유하는 경우 연결이 자동으로 다시 매핑됩니다.

SSM 문서 버전 비교

Systems Manager Documents 콘솔에서 AWS Systems Manager(SSM) 문서 버전 간의 내용 차이를 비교할 수 있습니다. SSM 문서의 버전을 비교할 때 버전 내용 간의 차이가 강조 표시됩니다.

SSM 문서 내용을 비교하려면(콘솔)
  1. AWS Systems Manager 콘솔(https://console.aws.amazon.com/systems-manager/)을 엽니다.

  2. 탐색 창에서 Documents를 선택합니다.

    -또는-

    AWS Systems Manager 홈 페이지가 처음 열리면 메뉴 아이콘( 
    The menu icon
  )을 선택하여 탐색 창을 연 다음 탐색 창에서 [Documents]를 선택합니다.

  3. 문서 목록에서 내용을 비교하려는 문서를 선택합니다.

  4. [콘텐츠(Content)] 탭에서 [버전 비교(Compare versions)]를 선택하고 콘텐츠를 비교하려는 문서의 버전을 선택합니다.

SSM 문서 생성(콘솔)

SSM 문서 콘텐츠 작성 섹션에 설명된 대로 사용자 정의 SSM 문서에 대한 콘텐츠를 생성한 후 Systems Manager 콘솔을 통해 콘텐츠를 사용하는 SSM 문서를 생성할 수 있습니다.

SSM 문서를 생성하려면(콘솔)
  1. AWS Systems Manager 콘솔(https://console.aws.amazon.com/systems-manager/)을 엽니다.

  2. 탐색 창에서 Documents를 선택합니다.

    -또는-

    AWS Systems Manager 홈 페이지가 처음 열리면 메뉴 아이콘( 
    The menu icon
  )을 선택하여 탐색 창을 연 다음 탐색 창에서 [Documents]를 선택합니다.

  3. 명령 또는 세션 생성을 선택합니다.

  4. 문서 이름을 서술식으로 입력합니다.

  5. (선택 사항) Target type(대상 유형)에는 문서를 실행할 수 있는 리소스 유형을 지정합니다.

  6. 문서 유형 목록에서 생성할 문서의 유형을 선택합니다.

  7. 콘텐츠 필드에서 괄호를 삭제한 후 앞서 생성한 문서 콘텐츠를 붙여 넣습니다.

  8. (선택 사항) Document tags(문서 태그) 섹션에서 문서에 적용할 하나 이상의 태그 키 이름/값 페어를 입력합니다.

    태그는 리소스에 할당하는 선택적 메타데이터입니다. 태그를 사용하면 용도, 소유자 또는 환경을 기준으로 하는 등 리소스를 다양한 방식으로 분류할 수 있습니다. 예를 들어 문서에 태그를 지정하여 실행하는 작업 유형, 대상 운영 체제 유형 및 실행 환경을 식별할 수 있습니다. 다음 키 이름/값 페어를 지정할 수 있습니다.

    • Key=TaskType,Value=MyConfigurationUpdate

    • Key=OS,Value=AMAZON_LINUX_2

    • Key=Environment,Value=Production

    Systems Manager 리소스 태그 지정에 대한 자세한 내용은 Systems Manager 리소스에 태그 지정 섹션을 참조하세요.

  9. 문서 생성을 선택하여 문서를 저장합니다.

SSM 문서 생성(명령줄)

SSM 문서 콘텐츠 작성 섹션에 설명된 대로 사용자 정의 AWS Systems Manager(SSM) 문서에 대한 콘텐츠를 생성한 후 AWS Command Line Interface(AWS CLI) 또는 AWS Tools for PowerShell을 통해 콘텐츠를 사용하는 SSM 문서를 생성할 수 있습니다. 다음 명령을 참조하십시오.

시작하기 전에

아직 하지 않은 경우 AWS CLI 또는 AWS Tools for PowerShell을 설치하고 구성합니다. 자세한 내용은 최신 버전의 AWS CLI 설치 또는 업데이트AWS Tools for PowerShell 설치를 참조하세요.

다음 명령을 실행합니다. 각 example resource placeholder를 사용자의 정보로 바꿉니다.

Linux & macOS
aws ssm create-document \ --content file://path/to/file/documentContent.json \ --name "document-name" \ --document-type "Command" \ --tags "Key=tag-key,Value=tag-value"
Windows
aws ssm create-document ^ --content file://C:\path\to\file\documentContent.json ^ --name "document-name" ^ --document-type "Command" ^ --tags "Key=tag-key,Value=tag-value"
PowerShell
$json = Get-Content -Path "C:\path\to\file\documentContent.json" | Out-String New-SSMDocument ` -Content $json ` -Name "document-name" ` -DocumentType "Command" ` -Tags "Key=tag-key,Value=tag-value"

이 작업이 성공하면 명령에서 다음과 비슷한 응답이 반환됩니다.

{
"DocumentDescription":{
  "CreatedDate":1.585061751738E9,
  "DefaultVersion":"1",
  "Description":"MyCustomDocument",
  "DocumentFormat":"JSON",
  "DocumentType":"Command",
  "DocumentVersion":"1",
  "Hash":"0d3d879b3ca072e03c12638d0255ebd004d2c65bd318f8354fcde820dEXAMPLE",
  "HashType":"Sha256",
  "LatestVersion":"1",
  "Name":"Example",
  "Owner":"111122223333",
  "Parameters":[
     --truncated--
  ],
  "PlatformTypes":[
     "Windows",
     "Linux"
  ],
  "SchemaVersion":"0.3",
  "Status":"Creating",
  "Tags": [
        {
            "Key": "Purpose",
            "Value": "Test"
        }
    ]
}
}

SSM 문서 생성(API)

SSM 문서 콘텐츠 작성 섹션에 설명된 대로 사용자 정의 AWS Systems Manager(SSM) 문서에 대한 콘텐츠를 생성한 후 원하는 SDK를 통해 AWS Systems Manager CreateDocument API 작업을 호출하여 콘텐츠를 사용하는 SSM 문서를 생성할 수 있습니다. Content 요청 파라미터에 대한 JSON 또는 YAML 문자열은 일반적으로 파일에서 읽어옵니다. 다음 샘플 함수는 SDK for Python, SDK for Go 및 SDK for Java를 사용하여 SSM 문서를 생성합니다.

Python
import boto3 ssm = boto3.client('ssm') filepath = '/path/to/file/documentContent.yaml' def createDocumentApiExample(): with open(filepath) as openFile: documentContent = openFile.read() createDocRequest = ssm.create_document( Content = documentContent, Name = 'createDocumentApiExample', DocumentType = 'Automation', DocumentFormat = 'YAML' ) print(createDocRequest) createDocumentApiExample()
Go
package main import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ssm" "fmt" "io/ioutil" "log" ) func main() { openFile, err := ioutil.ReadFile("/path/to/file/documentContent.yaml") if err != nil { log.Fatal(err) } documentContent := string(openFile) sesh := session.Must(session.NewSessionWithOptions(session.Options{ SharedConfigState: session.SharedConfigEnable})) ssmClient := ssm.New(sesh) createDocRequest, err := ssmClient.CreateDocument(&ssm.CreateDocumentInput{ Content: &documentContent, Name: aws.String("createDocumentApiExample"), DocumentType: aws.String("Automation"), DocumentFormat: aws.String("YAML"), }) result := *createDocRequest fmt.Println(result) }
Java
import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.profile.ProfileCredentialsProvider; import com.amazonaws.regions.Regions; import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagement; import com.amazonaws.services.simplesystemsmanagement.AWSSimpleSystemsManagementClientBuilder; import com.amazonaws.services.simplesystemsmanagement.model.*; public class createDocumentApiExample { public static void main(String[] args) { try { createDocumentMethod(getDocumentContent()); } catch (IOException e) { e.printStackTrace(); } } public static String getDocumentContent() throws IOException { String filepath = new String("/path/to/file/documentContent.yaml"); byte[] encoded = Files.readAllBytes(Paths.get(filepath)); String documentContent = new String(encoded, StandardCharsets.UTF_8); return documentContent; } public static void createDocumentMethod (final String documentContent) { AWSSimpleSystemsManagement ssm = AWSSimpleSystemsManagementClientBuilder.defaultClient(); final CreateDocumentRequest createDocRequest = new CreateDocumentRequest() .withContent(documentContent) .withName("createDocumentApiExample") .withDocumentType("Automation") .withDocumentFormat("YAML"); final CreateDocumentResult result = ssm.createDocument(createDocRequest); } }

사용자 정의 문서 콘텐츠 생성에 대한 자세한 내용은 데이터 요소 및 파마미터 섹션을 참조하세요.

사용자 지정 SSM 문서 삭제 중

사용자 지정 SSM 문서를 더 이상 사용하지 않을 경우 AWS Command Line Interface(AWS CLI) 또는 AWS Systems Manager 콘솔을 사용하여 삭제할 수 있습니다.

SSM 문서를 삭제하려면(AWS CLI)
  1. 문서를 삭제하기 전에 문서와 연결된 모든 인스턴스의 연결을 해제하는 것이 좋습니다.

    다음 명령을 실행하여 문서에서 인스턴스의 연결을 해제합니다.

    aws ssm delete-association --instance-id "123456789012" --name "documentName"

    명령이 성공해도 결과는 없습니다.

  2. 다음 명령을 실행합니다. 각 example resource placeholder를 사용자의 정보로 바꿉니다.

    Linux
    aws ssm delete-document \ --name "document-name" \ --document-version "document-version" \ --version-name "version-name"
    Windows
    aws ssm delete-document ^ --name "document-name" ^ --document-version "document-version" ^ --version-name "version-name"
    PowerShell
    Delete-SSMDocument ` -Name "document-name" ` -DocumentVersion 'document-version' ` -VersionName 'version-name'

    명령이 성공해도 결과는 없습니다.

    중요

    만약 document-version 또는 version-name이 제공되지 않으면 문서의 모든 버전이 삭제됩니다.

SSM 문서를 삭제하려면(콘솔)
  1. AWS Systems Manager 콘솔(https://console.aws.amazon.com/systems-manager/)을 엽니다.

  2. 탐색 창에서 Documents를 선택합니다.

    -또는-

    AWS Systems Manager 홈 페이지가 처음 열리면 메뉴 아이콘( 
    The menu icon
  )을 선택하여 탐색 창을 연 다음 탐색 창에서 Documents를 선택합니다.

  3. 삭제할 문서를 선택합니다.

  4. 삭제(Delete)를 선택합니다. 문서를 삭제할 것인지 묻는 메시지가 나타나면 삭제(Delete)를 선택합니다.