

# AWS CLI를 사용한 Detective 예제
<a name="cli_detective_code_examples"></a>

다음 코드 예제에서는 Detective에서 AWS Command Line Interface를 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다.

*작업*은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

각 예시에는 전체 소스 코드에 대한 링크가 포함되어 있으며, 여기에서 컨텍스트에 맞춰 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있습니다.

**Topics**
+ [작업](#actions)

## 작업
<a name="actions"></a>

### `accept-invitation`
<a name="detective_AcceptInvitation_cli_topic"></a>

다음 코드 예제에서는 `accept-invitation`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에서 멤버 계정이 되기 위한 초대를 수락하려면**  
다음 `accept-invitation` 예제에서는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 멤버 계정이 되기 위한 초대를 수락합니다.  

```
aws detective accept-invitation \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *Amazon Detective 관리 안내서*의 [동작 그래프 초대에 대한 응답](https://docs.aws.amazon.com/detective/latest/adminguide/member-invitation-response.html)을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [AcceptInvitation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/accept-invitation.html)을 참조하세요.

### `create-graph`
<a name="detective_CreateGraph_cli_topic"></a>

다음 코드 예제에서는 `create-graph`의 사용 방법을 보여줍니다.

**AWS CLI**  
**Amazon Detective를 활성화하고 새 동작 그래프를 생성하려면**  
다음 `create-graph` 예제에서는 명령이 실행되는 리전에서 명령을 실행하는 AWS 계정에 대해 Detective를 활성화합니다. 해당 계정이 관리자 계정인 새 동작 그래프가 생성됩니다. 명령은 또한 Finance 값을 Department 태그에 할당합니다.  

```
aws detective create-graph \
    --tags '{"Department": "Finance"}'
```
출력:  

```
{
    "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:027c7c4610ea4aacaf0b883093cab899"
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 [Amazon Detective 활성화](https://docs.aws.amazon.com/detective/latest/adminguide/detective-enabling.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateGraph](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/create-graph.html)를 참조하세요.

### `create-members`
<a name="detective_CreateMembers_cli_topic"></a>

다음 코드 예제에서는 `create-members`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에 멤버 계정을 초대하려면**  
다음 `create-members` 예제에서는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 두 AWS 계정을 멤버 계정으로 초대합니다. 각 계정에 대해 요청은 AWS 계정 ID와 계정 루트 사용자 이메일 주소를 제공합니다. 요청에 초대 이메일에 삽입할 사용자 지정 메시지가 포함되어 있습니다.  

```
aws detective create-members \
    --accounts AccountId=444455556666,EmailAddress=mmajor@example.com AccountId=123456789012,EmailAddress=jstiles@example.com \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 \
    --message "This is Paul Santos. I need to add your account to the data we use for security investigation in Amazon Detective. If you have any questions, contact me at psantos@example.com."
```
출력:  

```
{
    "Members": [
    {
        "AccountId": "444455556666",
        "AdministratorId": "111122223333",
        "EmailAddress": "mmajor@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "INVITED",
        "UpdatedTime": 1579826107000
   },
   {
        "AccountId": "123456789012",
        "AdministratorId": "111122223333",
        "EmailAddress": "jstiles@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "VERIFICATION_IN_PROGRESS",
        "UpdatedTime": 1579826107000
     }
    ],
    "UnprocessedAccounts": [ ]
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프에 멤버 계정 초대 <https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-add-member-accounts.html>를 참조하세요.  
**초대 이메일을 보내지 않고 멤버 계정을 초대하려면**  
다음 `create-members` 예제에서는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 두 AWS 계정을 멤버 계정으로 초대합니다. 각 계정에 대해 요청은 AWS 계정 ID와 계정 루트 사용자 이메일 주소를 제공합니다. 멤버 계정은 초대 이메일을 수신하지 않습니다.  

```
aws detective create-members \
    --accounts AccountId=444455556666,EmailAddress=mmajor@example.com AccountId=123456789012,EmailAddress=jstiles@example.com \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 \
    --disable-email-notification
```
출력:  

```
{
    "Members": [
    {
        "AccountId": "444455556666",
        "AdministratorId": "111122223333",
        "EmailAddress": "mmajor@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "INVITED",
        "UpdatedTime": 1579826107000
   },
   {
        "AccountId": "123456789012",
        "AdministratorId": "111122223333",
        "EmailAddress": "jstiles@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "VERIFICATION_IN_PROGRESS",
        "UpdatedTime": 1579826107000
     }
    ],
    "UnprocessedAccounts": [ ]
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프에 멤버 계정 초대 <https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-add-member-accounts.html>를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [CreateMembers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/create-members.html)를 참조하세요.

### `delete-graph`
<a name="detective_DeleteGraph_cli_topic"></a>

다음 코드 예제에서는 `delete-graph`의 사용 방법을 보여줍니다.

**AWS CLI**  
**Detective를 비활성화하고 동작 그래프를 삭제하려면**  
다음 `delete-graph` 예제에서는 Detective를 비활성화하고 지정된 동작 그래프를 삭제합니다.  

```
aws detective delete-graph \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *Amazon Detective 관리 안내서*의 [Amazon Detective 비활성화](https://docs.aws.amazon.com/detective/latest/adminguide/detective-disabling.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteGraph](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/delete-graph.html)를 참조하세요.

### `delete-members`
<a name="detective_DeleteMembers_cli_topic"></a>

다음 코드 예제에서는 `delete-members`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에서 멤버 계정을 제거하려면**  
다음 `delete-members` 예제에서는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 두 멤버 계정을 제거합니다. 계정을 식별하기 위해 요청은 AWS개의 계정 ID를 제공합니다.  

```
aws detective delete-members \
    --account-ids 444455556666 123456789012 \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
출력:  

```
 {
    "AccountIds": [ "444455556666", "123456789012" ],
    "UnprocessedAccounts": [ ]
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프에서 멤버 계정 제거 <https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-remove-member-accounts.html>를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DeleteMembers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/delete-members.html)를 참조하세요.

### `disassociate-membership`
<a name="detective_DisassociateMembership_cli_topic"></a>

다음 코드 예제에서는 `disassociate-membership`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에서 멤버십을 사임하려면**  
다음 연결 해제-멤버십 예제는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 명령을 실행하는 AWS 계정을 제거합니다.  

```
aws detective disassociate-membership \
     --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프에서 계정 삭제 <https://docs.aws.amazon.com/detective/latest/adminguide/member-remove-self-from-graph.html>를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [DisassociateMembership](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/disassociate-membership.html)을 참조하세요.

### `get-members`
<a name="detective_GetMembers_cli_topic"></a>

다음 코드 예제에서는 `get-members`의 사용 방법을 보여줍니다.

**AWS CLI**  
**선택한 동작 그래프 멤버 계정에 대한 정보를 검색하려면**  
다음 `get-members` 예제에서는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 두 멤버 계정에 대한 정보를 검색합니다. 두 계정의 경우 요청은 AWS개의 계정 ID를 제공합니다.  

```
aws detective get-members \
    --account-ids 444455556666 123456789012 \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
출력:  

```
{
    "MemberDetails": [
    {
        "AccountId": "444455556666",
        "AdministratorId": "111122223333",
        "EmailAddress": "mmajor@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "INVITED",
        "UpdatedTime": 1579826107000
    }
    {
        "AccountId": "123456789012",
        "AdministratorId": "111122223333",
        "EmailAddress": "jstiles@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "INVITED",
        "UpdatedTime": 1579826107000
    }
],
    "UnprocessedAccounts": [ ]
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프에서 계정 목록 보기 <https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-view-accounts.html>를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [GetMembers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/get-members.html)를 참조하세요.

### `list-graphs`
<a name="detective_ListGraphs_cli_topic"></a>

다음 코드 예제에서는 `list-graphs`의 사용 방법을 보여줍니다.

**AWS CLI**  
**계정이 관리자인 동작 그래프 목록을 보려면**  
다음 `list-graphs` 예제에서는 현재 리전 내에서 호출 계정이 관리자인 동작 그래프를 검색합니다.  

```
aws detective list-graphs
```
출력:  

```
{
    "GraphList": [
        {
            "Arn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
            "CreatedTime": 1579736111000
        }
    ]
}
```
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListGraphs](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/list-graphs.html)를 참조하세요.

### `list-invitations`
<a name="detective_ListInvitations_cli_topic"></a>

다음 코드 예제에서는 `list-invitations`의 사용 방법을 보여줍니다.

**AWS CLI**  
**계정이 멤버이거나 초대된 동작 그래프 목록을 보려면**  
다음 `list-invitations` 예제에서는 호출 계정이 초대된 동작 그래프를 검색합니다. 결과에는 열린 초대와 수락된 초대만 포함됩니다. 거부된 초대 또는 제거된 멤버십은 포함되지 않습니다.  

```
aws detective list-invitations
```
출력:  

```
{
    "Invitations": [
    {
        "AccountId": "444455556666",
        "AdministratorId": "111122223333",
        "EmailAddress": "mmajor@example.com",
        "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
        "InvitedTime": 1579826107000,
        "MasterId": "111122223333",
        "Status": "INVITED",
        "UpdatedTime": 1579826107000
    }
]
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프 초대 목록 보기 <https://docs.aws.amazon.com/detective/latest/adminguide/member-view-graph-invitations.html>를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListInvitations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/list-invitations.html)를 참조하세요.

### `list-members`
<a name="detective_ListMembers_cli_topic"></a>

다음 코드 예제에서는 `list-members`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에 멤버 계정을 나열하려면**  
다음 `list-members` 예제에서는 동작 그래프 `arn:aws:detective:us-east-1:111122223333:graph:123412341234`에 대해 초대되고 활성화된 멤버 계정을 검색합니다. 결과에는 제거된 멤버 계정이 포함되지 않습니다.  

```
aws detective list-members \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
출력:  

```
{
    "MemberDetails": [
        {
            "AccountId": "444455556666",
            "AdministratorId": "111122223333",
            "EmailAddress": "mmajor@example.com",
            "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
            "InvitedTime": 1579826107000,
            "MasterId": "111122223333",
            "Status": "INVITED",
            "UpdatedTime": 1579826107000
        },
        {
            "AccountId": "123456789012",
            "AdministratorId": "111122223333",
            "EmailAddress": "jstiles@example.com",
            "GraphArn": "arn:aws:detective:us-east-1:111122223333:graph:123412341234",
            "InvitedTime": 1579826107000,
            "MasterId": "111122223333",
            "PercentOfGraphUtilization": 2,
            "PercentOfGraphUtilizationUpdatedTime": 1586287843,
            "Status": "ENABLED",
            "UpdatedTime": 1579973711000,
            "VolumeUsageInBytes": 200,
            "VolumeUsageUpdatedTime": 1586287843
        }
    ]
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 [동작 그래프에서 계정 목록 보기](https://docs.aws.amazon.com/detective/latest/adminguide/graph-admin-view-accounts.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListMembers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/list-members.html)를 참조하세요.

### `list-tags-for-resource`
<a name="detective_ListTagsForResource_cli_topic"></a>

다음 코드 예제에서는 `list-tags-for-resource`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에 할당된 태그를 검색하려면**  
다음 `list-tags-for-resource` 예제에서는 지정된 동작 그래프에 할당된 태그를 반환합니다.  

```
aws detective list-tags-for-resource \
    --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
출력:  

```
{
    "Tags": {
        "Department" : "Finance"
    }
}
```
자세한 내용은 *Amazon Detective 관리 안내서*의 [동작 그래프에 대한 태그 관리](https://docs.aws.amazon.com/detective/latest/adminguide/graph-tags.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [ListTagsForResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/list-tags-for-resource.html)를 참조하세요.

### `reject-invitation`
<a name="detective_RejectInvitation_cli_topic"></a>

다음 코드 예제에서는 `reject-invitation`의 사용 방법을 보여줍니다.

**AWS CLI**  
**동작 그래프에서 멤버 계정이 되기 위한 초대를 거부하려면**  
다음 `reject-invitation` 예제에서는 동작 그래프 arn:aws:detective:us-east-1:111122223333:graph:123412341234에서 멤버 계정이 되기 위한 초대를 거부합니다.  

```
aws detective reject-invitation \
    --graph-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *Amazon Detective 관리 안내서*의 동작 그래프 초대에 대한 응답 <https://docs.aws.amazon.com/detective/latest/adminguide/member-invitation-response.html>을 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [RejectInvitation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/reject-invitation.html)을 참조하세요.

### `tag-resource`
<a name="detective_TagResource_cli_topic"></a>

다음 코드 예제에서는 `tag-resource`의 사용 방법을 보여줍니다.

**AWS CLI**  
**리소스에 태그를 할당하려면**  
다음 `tag-resource` 예제에서는 부서 태그의 값을 지정된 동작 그래프에 할당합니다.  

```
aws detective tag-resource \
    --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 \
    --tags '{"Department":"Finance"}'
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *Amazon Detective 관리 안내서*의 [동작 그래프에 대한 태그 관리](https://docs.aws.amazon.com/detective/latest/adminguide/graph-tags.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [TagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/tag-resource.html)를 참조하세요.

### `untag-resource`
<a name="detective_UntagResource_cli_topic"></a>

다음 코드 예제에서는 `untag-resource`의 사용 방법을 보여줍니다.

**AWS CLI**  
**리소스에서 태그를 제거하려면**  
다음 `untag-resource` 예제에서는 지정된 동작 그래프에서 부서 태그를 제거합니다.  

```
aws detective untag-resource \
    --resource-arn arn:aws:detective:us-east-1:111122223333:graph:123412341234 \
    --tag-keys "Department"
```
이 명령은 출력을 생성하지 않습니다.  
자세한 내용은 *Amazon Detective 관리 안내서*의 [동작 그래프에 대한 태그 관리](https://docs.aws.amazon.com/detective/latest/adminguide/graph-tags.html)를 참조하세요.  
+  API 세부 정보는 *AWS CLI 명령 참조*의 [UntagResource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/detective/untag-resource.html)를 참조하세요.