

# 使用 AWS CLI 的 GuardDuty 示例
<a name="cli_guardduty_code_examples"></a>

以下代码示例演示如何通过将 AWS Command Line Interface与 GuardDuty 结合使用，来执行操作和实现常见场景。

*操作是大型程序的代码摘录*，必须在上下文中运行。您可以通过操作了解如何调用单个服务函数，还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接，您可以从中找到有关如何在上下文中设置和运行代码的说明。

**Topics**
+ [操作](#actions)

## 操作
<a name="actions"></a>

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

以下代码示例演示了如何使用 `accept-invitation`。

**AWS CLI**  
**接受成为当前区域中 GuardDuty 成员账户的邀请**  
以下 `accept-invitation` 示例演示如何接受成为当前区域中 GuardDuty 成员账户的邀请。  

```
aws guardduty accept-invitation  \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --master-id 123456789111 \
    --invitation-id d6b94fb03a66ff665f7db8764example
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》中的[通过邀请管理 GuardDuty 账户](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_invitations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [AcceptInvitation](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/accept-invitation.html)。

### `archive-findings`
<a name="guardduty_ArchiveFindings_cli_topic"></a>

以下代码示例演示了如何使用 `archive-findings`。

**AWS CLI**  
**将调查结果存档到当前区域中**  
此 `archive-findings` 示例演示如何将调查发现存档到当前区域中。  

```
aws guardduty archive-findings \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --finding-ids d6b94fb03a66ff665f7db8764example 3eb970e0de00c16ec14e6910fexample
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Creating suppression rules](https://docs.aws.amazon.com/guardduty/latest/ug/findings_suppression-rules-console.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ArchiveFindings](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/archive-findings.html)。

### `create-detector`
<a name="guardduty_CreateDetector_cli_topic"></a>

以下代码示例演示了如何使用 `create-detector`。

**AWS CLI**  
**在当前区域中启用 GuardDuty**  
此示例演示如何在当前区域中创建一个启用 GuardDuty 的新检测器。  

```
aws guardduty create-detector \
    --enable
```
输出：  

```
{
    "DetectorId": "b6b992d6d2f48e64bc59180bfexample"
}
```
有关更多信息，请参阅《GuardDuty 用户指南》**中的[启用 Amazon GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_settingup.html#guardduty_enable-gd)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-detector.html)。

### `create-filter`
<a name="guardduty_CreateFilter_cli_topic"></a>

以下代码示例演示了如何使用 `create-filter`。

**AWS CLI**  
**示例 1：在当前区域中创建新筛选条件**  
以下 `create-filter` 示例创建一个筛选条件，该筛选条件与从特定映像中创建的实例的所有 Portscan 调查发现相匹配。这不会隐藏这些调查发现。  

```
aws guardduty create-filter \
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --name myFilterExample \
    --finding-criteria '{"Criterion": {"type": {"Eq": ["Recon:EC2/Portscan"]},"resource.instanceDetails.imageId": {"Eq": ["ami-0a7a207083example"]}}}'
```
输出：  

```
{
    "Name": "myFilterExample"
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Filtering GuardDuty findings](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_filter-findings.html)。  
**示例 2：在当前区域中创建新筛选条件并隐藏调查发现**  
以下 `create-filter` 示例创建一个筛选条件，该筛选条件与从特定映像中创建的实例的所有 Portscan 调查发现相匹配。此筛选条件归档这些调查发现，这样它们就不会出现在当前的调查发现中。  

```
aws guardduty create-filter \
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --action ARCHIVE \
    --name myFilterSecondExample \
    --finding-criteria '{"Criterion": {"type": {"Eq": ["Recon:EC2/Portscan"]},"resource.instanceDetails.imageId": {"Eq": ["ami-0a7a207083example"]}}}'
```
输出：  

```
{
    "Name": "myFilterSecondExample"
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Filtering GuardDuty findings](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_filter-findings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateFilter](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-filter.html)。

### `create-ip-set`
<a name="guardduty_CreateIpSet_cli_topic"></a>

以下代码示例演示了如何使用 `create-ip-set`。

**AWS CLI**  
**创建并激活可信 IP 集**  
以下 `create-ip-set` 示例在当前区域中创建并激活可信 IP 集。  

```
aws guardduty create-ip-set \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --name new-ip-set-example \
    --format TXT \
    --location s3://amzn-s3-demo-bucket/customtrustlist.csv \
    --activate
```
输出：  

```
{
    "IpSetId": "d4b94fc952d6912b8f3060768example"
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Working with Trusted IP Lists and Threat Lists](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_upload_lists.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateIpSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-ip-set.html)。

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

以下代码示例演示了如何使用 `create-members`。

**AWS CLI**  
**将新成员与您在当前区域中的 GuardDuty 主账户相关联**  
此示例演示如何关联成员账户，使其由当前账户作为 GuardDuty 主账户进行托管。  

```
aws guardduty create-members
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --account-details AccountId=111122223333,Email=first+member@example.com AccountId=111111111111 ,Email=another+member@example.com
```
输出：  

```
{
   "UnprocessedAccounts": []
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[管理多个账户](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_accounts.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateMembers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-members.html)。

### `create-publishing-destination`
<a name="guardduty_CreatePublishingDestination_cli_topic"></a>

以下代码示例演示了如何使用 `create-publishing-destination`。

**AWS CLI**  
**创建发布目标以将当前区域中的 GuardDuty 调查结果导出到其中**  
以下 `create-publishing-destination` 示例演示如何设置发布目标以导出当前（未归档）的 GuardDuty 调查发现，从而跟踪历史调查发现数据。  

```
aws guardduty create-publishing-destination \
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --destination-type S3 \
    --destination-properties 'DestinationArn=arn:aws:s3:::amzn-s3-demo-bucket,KmsKeyArn=arn:aws:kms:us-west-1:111122223333:key/84cee9c5-dea1-401a-ab6d-e1de7example'
```
输出：  

```
{
    "DestinationId": "46b99823849e1bbc242dfbe3cexample"
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Exporting generated GuardDuty findings to Amazon S3 buckets](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_exportfindings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreatePublishingDestination](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-publishing-destination.html)。

### `create-sample-findings`
<a name="guardduty_CreateSampleFindings_cli_topic"></a>

以下代码示例演示了如何使用 `create-sample-findings`。

**AWS CLI**  
**在当前区域中创建示例 GuardDuty 调查结果**  
此示例演示如何创建所提供类型的示例调查结果。  

```
aws guardduty create-sample-findings \
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --finding-types UnauthorizedAccess:EC2/TorClient UnauthorizedAccess:EC2/TorRelay
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》**中的[示例调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/sample_findings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateSampleFindings](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-sample-findings.html)。

### `create-threat-intel-set`
<a name="guardduty_CreateThreatIntelSet_cli_topic"></a>

以下代码示例演示了如何使用 `create-threat-intel-set`。

**AWS CLI**  
**创建并激活新的威胁情报集**  
以下 `create-threat-intel-set` 示例在当前区域中创建并激活威胁情报集。  

```
aws guardduty create-threat-intel-set \
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --name myThreatSet-example \
    --format TXT \
    --location s3://amzn-s3-demo-bucket/threatlist.csv \
    --activate
```
输出：  

```
{
    "ThreatIntelSetId": "20b9a4691aeb33506b808878cexample"
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Working with Trusted IP Lists and Threat Lists](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_upload_lists.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [CreateThreatIntelSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/create-threat-intel-set.html)。

### `decline-invitations`
<a name="guardduty_DeclineInvitations_cli_topic"></a>

以下代码示例演示了如何使用 `decline-invitations`。

**AWS CLI**  
**拒绝由当前区域中的另一账户托管 GuardDuty 的邀请**  
此示例演示如何拒绝成员资格邀请。  

```
aws guardduty decline-invitations \
    --account-ids 111122223333
```
输出：  

```
{
    "UnprocessedAccounts": []
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[通过邀请管理 GuardDuty 账户](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_invitations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeclineInvitations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/decline-invitations.html)。

### `delete-detector`
<a name="guardduty_DeleteDetector_cli_topic"></a>

以下代码示例演示了如何使用 `delete-detector`。

**AWS CLI**  
**删除当前区域中的检测器并禁用 GuardDuty**  
此示例演示如何删除检测器，如果成功，则将在与该检测器关联的区域中禁用 GuardDuty。  

```
aws guardduty delete-detector \
    --detector-id b6b992d6d2f48e64bc59180bfexample
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》**中的[暂停或禁用 GuardDuty](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_suspend-disable.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/delete-detector.html)。

### `delete-filter`
<a name="guardduty_DeleteFilter_cli_topic"></a>

以下代码示例演示了如何使用 `delete-filter`。

**AWS CLI**  
**删除当前区域中的现有筛选条件**  
此示例演示如何删除筛选条件。  

```
aws guardduty delete-filter \
    --detector-id b6b992d6d2f48e64bc59180bfexample \
    --filter-name byebyeFilter
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》中的[筛选调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_filter-findings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DeleteFilter](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/delete-filter.html)。

### `disable-organization-admin-account`
<a name="guardduty_DisableOrganizationAdminAccount_cli_topic"></a>

以下代码示例演示了如何使用 `disable-organization-admin-account`。

**AWS CLI**  
**删除组织内作为 GuardDuty 委派管理员的账户**  
此示例演示如何删除作为 GuardDuty 委派管理员的账户。  

```
aws guardduty disable-organization-admin-account \
    --admin-account-id 111122223333
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》**中的[使用 AWS Organizations 管理账户](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_organizations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DisableOrganizationAdminAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/disable-organization-admin-account.html)。

### `disassociate-from-master-account`
<a name="guardduty_DisassociateFromMasterAccount_cli_topic"></a>

以下代码示例演示了如何使用 `disassociate-from-master-account`。

**AWS CLI**  
**取消与当前区域中的当前管理员账户的关联**  
以下 `disassociate-from-master-account` 示例取消您的账户与当前 AWS 区域中的当前 GuardDuty 管理员账户的关联。  

```
aws guardduty disassociate-from-master-account \
    --detector-id d4b040365221be2b54a6264dcexample
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Understanding the relationship between GuardDuty administrator account and member accounts](https://docs.aws.amazon.com/guardduty/latest/ug/administrator_member_relationships.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [DisassociateFromMasterAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/disassociate-from-master-account.html)。

### `get-detector`
<a name="guardduty_GetDetector_cli_topic"></a>

以下代码示例演示了如何使用 `get-detector`。

**AWS CLI**  
**检索特定检测器的详细信息**  
以下 `get-detector` 示例显示指定检测器的配置详细信息。  

```
aws guardduty get-detector \
    --detector-id 12abc34d567e8fa901bc2d34eexample
```
输出：  

```
{
    "Status": "ENABLED",
    "ServiceRole": "arn:aws:iam::111122223333:role/aws-service-role/guardduty.amazonaws.com/AWSServiceRoleForAmazonGuardDuty",
    "Tags": {},
    "FindingPublishingFrequency": "SIX_HOURS",
    "UpdatedAt": "2018-11-07T03:24:22.938Z",
    "CreatedAt": "2017-12-22T22:51:31.940Z"
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[概念和术语](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_concepts.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/get-detector.html)。

### `get-findings`
<a name="guardduty_GetFindings_cli_topic"></a>

以下代码示例演示了如何使用 `get-findings`。

**AWS CLI**  
**示例 1：检索特定调查结果的详细信息**  
以下 `get-findings` 示例检索指定调查结果的完整 JSON 调查结果详细信息。  

```
aws guardduty get-findings \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --finding-id 1ab92989eaf0e742df4a014d5example
```
输出：  

```
{
    "Findings": [
        {
            "Resource": {
                "ResourceType": "AccessKey",
                "AccessKeyDetails": {
                    "UserName": "testuser",
                    "UserType": "IAMUser",
                    "PrincipalId": "AIDACKCEVSQ6C2EXAMPLE",
                    "AccessKeyId": "ASIASZ4SI7REEEXAMPLE"
                }
            },
            "Description": "APIs commonly used to discover the users, groups, policies and permissions in an account, was invoked by IAM principal testuser under unusual circumstances. Such activity is not typically seen from this principal.",
            "Service": {
                "Count": 5,
                "Archived": false,
                "ServiceName": "guardduty",
                "EventFirstSeen": "2020-05-26T22:02:24Z",
                "ResourceRole": "TARGET",
                "EventLastSeen": "2020-05-26T22:33:55Z",
                "DetectorId": "d4b040365221be2b54a6264dcexample",
                "Action": {
                    "ActionType": "AWS_API_CALL",
                    "AwsApiCallAction": {
                        "RemoteIpDetails": {
                            "GeoLocation": {
                                "Lat": 51.5164,
                                "Lon": -0.093
                            },
                            "City": {
                                "CityName": "London"
                            },
                            "IpAddressV4": "52.94.36.7",
                            "Organization": {
                                "Org": "Amazon.com",
                                "Isp": "Amazon.com",
                                "Asn": "16509",
                                "AsnOrg": "AMAZON-02"
                            },
                            "Country": {
                                "CountryName": "United Kingdom"
                            }
                        },
                        "Api": "ListPolicyVersions",
                        "ServiceName": "iam.amazonaws.com",
                        "CallerType": "Remote IP"
                    }
                }
            },
            "Title": "Unusual user permission reconnaissance activity by testuser.",
            "Type": "Recon:IAMUser/UserPermissions",
            "Region": "us-east-1",
            "Partition": "aws",
            "Arn": "arn:aws:guardduty:us-east-1:111122223333:detector/d4b040365221be2b54a6264dcexample/finding/1ab92989eaf0e742df4a014d5example",
            "UpdatedAt": "2020-05-26T22:55:21.703Z",
            "SchemaVersion": "2.0",
            "Severity": 5,
            "Id": "1ab92989eaf0e742df4a014d5example",
            "CreatedAt": "2020-05-26T22:21:48.385Z",
            "AccountId": "111122223333"
        }
    ]
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_findings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetFindings](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/get-findings.html)。

### `get-ip-set`
<a name="guardduty_GetIpSet_cli_topic"></a>

以下代码示例演示了如何使用 `get-ip-set`。

**AWS CLI**  
**列出指定可信 IP 集的详细信息**  
以下 `get-ip-set` 示例显示指定可信 IP 集的状态和详细信息。  

```
aws guardduty get-ip-set \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --ip-set-id d4b94fc952d6912b8f3060768example
```
输出：  

```
{
    "Status": "ACTIVE",
    "Location": "s3://amzn-s3-demo-bucket.s3-us-west-2.amazonaws.com/customlist.csv",
    "Tags": {},
    "Format": "TXT",
    "Name": "test-ip-set-example"
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Working with Trusted IP Lists and Threat Lists](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_upload_lists.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetIpSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/get-ip-set.html)。

### `get-master-account`
<a name="guardduty_GetMasterAccount_cli_topic"></a>

以下代码示例演示了如何使用 `get-master-account`。

**AWS CLI**  
**检索有关当前区域中主账户的详细信息**  
以下 `get-master-account` 示例显示与当前区域中您的检测器关联的主账户的状态和详细信息。  

```
aws guardduty get-master-account \
    --detector-id 12abc34d567e8fa901bc2d34eexample
```
输出：  

```
{
    "Master": {
        "InvitationId": "04b94d9704854a73f94e061e8example",
        "InvitedAt": "2020-06-09T22:23:04.970Z",
        "RelationshipStatus": "Enabled",
        "AccountId": "111122223333"
    }
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Understanding the relationship between GuardDuty administrator account and member account](https://docs.aws.amazon.com/guardduty/latest/ug/administrator_member_relationships.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [GetMasterAccount](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/get-master-account.html)。

### `list-detectors`
<a name="guardduty_ListDetectors_cli_topic"></a>

以下代码示例演示了如何使用 `list-detectors`。

**AWS CLI**  
**列出当前区域中的可用检测器**  
以下 `list-detectors` 示例列出了您当前 AWS 区域中的可用检测器。  

```
aws guardduty list-detectors
```
输出：  

```
{
    "DetectorIds": [
        "12abc34d567e8fa901bc2d34eexample"
    ]
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[概念和术语](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_concepts.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListDetectors](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/list-detectors.html)。

### `list-findings`
<a name="guardduty_ListFindings_cli_topic"></a>

以下代码示例演示了如何使用 `list-findings`。

**AWS CLI**  
**示例 1：列出当前区域的所有调查结果**  
以下 `list-findings` 示例显示了当前区域按严重性从最高到最低排序的所有 findingIds 的列表。  

```
aws guardduty list-findings \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --sort-criteria '{"AttributeName": "severity","OrderBy":"DESC"}'
```
输出：  

```
{
    "FindingIds": [
        "04b8ab50fd29c64fc771b232dexample",
        "5ab8ab50fd21373735c826d3aexample",
        "90b93de7aba69107f05bbe60bexample",
        ...
    ]
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_findings.html)。  
**示例 2：列出与当前区域特定调查结果标准相匹配的调查结果**  
以下 `list-findings` 示例显示了与指定调查结果类型相匹配的所有 findingIds 的列表。  

```
aws guardduty list-findings \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --finding-criteria  '{"Criterion":{"type": {"Eq":["UnauthorizedAccess:EC2/SSHBruteForce"]}}}'
```
输出：  

```
{
    "FindingIds": [
        "90b93de7aba69107f05bbe60bexample",
        "6eb9430d7023d30774d6f05e3example",
        "2eb91a2d060ac9a21963a5848example",
        "44b8ab50fd2b0039a9e48f570example",
        "9eb8ab4cd2b7e5b66ba4f5e96example",
        "e0b8ab3a38e9b0312cc390ceeexample"
    ]
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_findings.html)。  
**示例 3：列出与 JSON 文件中定义的一组特定调查结果标准相匹配的当前区域的调查结果**  
以下 `list-findings` 示例显示了未存档的所有 findingIds 的列表，其中涉及 JSON 文件中指定的名为“testuser”的 IAM 用户。  

```
aws guardduty list-findings \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --finding-criteria  file://myfile.json
```
 的内容`myfile.json`：  

```
{"Criterion": {
    "resource.accessKeyDetails.userName":{
                "Eq":[
                    "testuser"
                    ]
                },
    "service.archived": {
                "Eq": [
                    "false"
                ]
            }
        }
}
```
输出：  

```
{
    "FindingIds": [
        "1ab92989eaf0e742df4a014d5example"
    ]
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_findings.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListFindings](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/list-findings.html)。

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

以下代码示例演示了如何使用 `list-invitations`。

**AWS CLI**  
**列出有关您成为当前区域中的成员账户的邀请的详细信息**  
以下 `list-invitations` 示例列出了有关您成为当前区域中 GuardDuty 成员账户的邀请的详细信息和状态。  

```
aws guardduty list-invitations
```
输出：  

```
{
    "Invitations": [
        {
            "InvitationId": "d6b94fb03a66ff665f7db8764example",
            "InvitedAt": "2020-06-10T17:56:38.221Z",
            "RelationshipStatus": "Invited",
            "AccountId": "123456789111"
        }
    ]
}
```
有关更多信息，请参阅《GuardDuty 用户指南》中的[通过邀请管理 GuardDuty 账户](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_invitations.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListInvitations](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/list-invitations.html)。

### `list-ip-sets`
<a name="guardduty_ListIpSets_cli_topic"></a>

以下代码示例演示了如何使用 `list-ip-sets`。

**AWS CLI**  
**列出当前区域中的可信 IP 集**  
以下 `list-ip-sets` 示例列出了您当前 AWS 区域中的可信 IP 集。  

```
aws guardduty list-ip-sets \
    --detector-id 12abc34d567e8fa901bc2d34eexample
```
输出：  

```
{
    "IpSetIds": [
        "d4b94fc952d6912b8f3060768example"
    ]
}
```
有关更多信息，请参阅《GuardDuty User Guide》中的 [Working with Trusted IP Lists and Threat Lists](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_upload_lists.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListIpSets](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/list-ip-sets.html)。

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

以下代码示例演示了如何使用 `list-members`。

**AWS CLI**  
**示例 1：仅列出当前区域中的当前成员**  
以下 `list-members` 示例仅列出当前区域中与 GuardDuty 管理员账户关联的当前成员账户并提供其详细信息。  

```
aws guardduty list-members \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --only-associated="true"
```
输出：  

```
{
    "Members": [
        {
            "RelationshipStatus": "Enabled",
            "InvitedAt": "2020-06-09T22:49:00.910Z",
            "MasterId": "111122223333",
            "DetectorId": "7ab8b2f61b256c87f793f6a86example",
            "UpdatedAt": "2020-06-09T23:08:22.512Z",
            "Email": "your+member@example.com",
            "AccountId": "123456789012"
        }
    ]
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Understanding the relationship between GuardDuty administrator account and member accounts](https://docs.aws.amazon.com/guardduty/latest/ug/administrator_member_relationships.html)。  
**示例 2：列出当前区域中的所有成员**  
以下 `list-members` 示例列出当前区域中的所有成员账户（包括那些已取消关联或尚未接受来自 GuardDuty 管理员的邀请的成员账户）并提供其详细信息。  

```
aws guardduty list-members \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --only-associated="false"
```
输出：  

```
{
    "Members": [
        {
            "RelationshipStatus": "Enabled",
            "InvitedAt": "2020-06-09T22:49:00.910Z",
            "MasterId": "111122223333",
            "DetectorId": "7ab8b2f61b256c87f793f6a86example",
            "UpdatedAt": "2020-06-09T23:08:22.512Z",
            "Email": "your+other+member@example.com",
            "AccountId": "555555555555"
        }
    ]
}
```
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Understanding the relationship between GuardDuty administrator account and member accounts](https://docs.aws.amazon.com/guardduty/latest/ug/administrator_member_relationships.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [ListMembers](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/list-members.html)。

### `update-detector`
<a name="guardduty_UpdateDetector_cli_topic"></a>

以下代码示例演示了如何使用 `update-detector`。

**AWS CLI**  
**示例 1：在 GuardDuty 中启用运行时监控**  
以下 `update-detector` 示例无需额外配置即可启用运行时监控。  

```
aws guardduty update-detector \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --features 'Name=RUNTIME_MONITORING,Status=ENABLED'
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》**中的[运行时监控](https://docs.aws.amazon.com/guardduty/latest/ug/runtime-monitoring.html)。  
**示例 2：使用额外配置启用运行时监控**  
以下 `update-detector` 示例通过 EC2、ECS Fargate 和 EKS 的额外配置启用运行时监控。  

```
aws guardduty update-detector \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --features 'Name=RUNTIME_MONITORING,Status=ENABLED,AdditionalConfiguration=[{Name=EC2_AGENT_MANAGEMENT,Status=ENABLED},{Name=ECS_FARGATE_AGENT_MANAGEMENT,Status=ENABLED},{Name=EKS_ADDON_MANAGEMENT,Status=ENABLED}]'
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty 用户指南》**中的[运行时监控](https://docs.aws.amazon.com/guardduty/latest/ug/runtime-monitoring.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateDetector](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/update-detector.html)。

### `update-ip-set`
<a name="guardduty_UpdateIpSet_cli_topic"></a>

以下代码示例演示了如何使用 `update-ip-set`。

**AWS CLI**  
**更新可信 IP 集**  
以下 `update-ip-set` 示例演示如何更新可信 IP 集的详细信息。  

```
aws guardduty update-ip-set \
    --detector-id 12abc34d567e8fa901bc2d34eexample \
    --ip-set-id d4b94fc952d6912b8f3060768example \
    --location https://amzn-s3-demo-bucket.s3-us-west-2.amazonaws.com/customtrustlist2.csv
```
此命令不生成任何输出。  
有关更多信息，请参阅《GuardDuty User Guide》**中的 [Working with Trusted IP Lists and Threat Lists](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_upload_lists.html)。  
+  有关 API 详细信息，请参阅《AWS CLI 命令参考》**中的 [UpdateIpSet](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/guardduty/update-ip-set.html)。