

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 取得組織政策的相關資訊
<a name="orgs_manage_policies_info-operations"></a>

本主題說明各種取得組織中政策詳細資訊的方法。這些程序適用於*所有*政策類型。您必須在組織根上啟用政策類型，才能將該類型的政策連接至該組織根中的任何實體。

**Topics**
+ [列出所有政策](#list-all-pols-in-org)
+ [列出連接的政策](#list-all-pols-in-entity)
+ [列出所有連接](#list-all-entities-attached-to-pol)
+ [取得關於政策的詳細資訊](#get-details-about-pol)

## 列出所有政策
<a name="list-all-pols-in-org"></a>

**最低許可**  
若要列出您的組織內的政策，您必須擁有以下許可：  
`organizations:ListPolicies`

您可以在 中或使用 AWS Command Line Interface (AWS CLI) 命令 AWS 管理主控台 或 AWS SDK 操作來檢視組織中的政策。

### AWS 管理主控台
<a name="list-all-pols-in-org-console"></a><a name="proc-list-all-pols-in-org"></a>

**列出組織中的所有政策**

1. 登入 [AWS Organizations 主控台](https://console.aws.amazon.com/organizations/v2)。您必須以 IAM 使用者登入、擔任 IAM 角色，或是以組織管理帳戶中的根使用者 ([不建議](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#lock-away-credentials)) 身分登入。

1. 在 **[Policies](https://console.aws.amazon.com/organizations/v2/home/policies)** (政策) 頁面上，選擇您要列出的政策類型。

   如果已啟用指定的政策類型，主控台會顯示組織中目前可用的所有該類型政策的清單。

1. 返回 **[Policies](https://console.aws.amazon.com/organizations/v2/home/policies)** (政策) 頁面，然後針對每個政策類型重複執行此操作。

### AWS CLI & AWS SDKs
<a name="list-all-pols-in-org-cli-sdk"></a>

下列程式碼範例示範如何使用 `ListPolicies`。

------
#### [ .NET ]

**適用於 .NET 的 SDK**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/Organizations#code-examples)中設定和執行。

```
    using System;
    using System.Threading.Tasks;
    using Amazon.Organizations;
    using Amazon.Organizations.Model;

    /// <summary>
    /// Shows how to list the AWS Organizations policies associated with an
    /// organization.
    /// </summary>
    public class ListPolicies
    {
        /// <summary>
        /// Initializes an Organizations client object, and then calls its
        /// ListPoliciesAsync method.
        /// </summary>
        public static async Task Main()
        {
            // Create the client object using the default account.
            IAmazonOrganizations client = new AmazonOrganizationsClient();

            // The value for the Filter parameter is required and must must be
            // one of the following:
            //     AISERVICES_OPT_OUT_POLICY
            //     BACKUP_POLICY
            //     SERVICE_CONTROL_POLICY
            //     TAG_POLICY
            var request = new ListPoliciesRequest
            {
                Filter = "SERVICE_CONTROL_POLICY",
                MaxResults = 5,
            };

            var response = new ListPoliciesResponse();
            try
            {
                do
                {
                    response = await client.ListPoliciesAsync(request);
                    response.Policies.ForEach(p => DisplayPolicies(p));
                    if (response.NextToken is not null)
                    {
                        request.NextToken = response.NextToken;
                    }
                }
                while (response.NextToken is not null);
            }
            catch (AWSOrganizationsNotInUseException ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        /// <summary>
        /// Displays information about the Organizations policies associated
        /// with an organization.
        /// </summary>
        /// <param name="policy">An Organizations policy summary to display
        /// information on the console.</param>
        private static void DisplayPolicies(PolicySummary policy)
        {
            string policyInfo = $"{policy.Id} {policy.Name}\t{policy.Description}";

            Console.WriteLine(policyInfo);
        }
    }
```
+  如需 API 詳細資訊，請參閱 *適用於 .NET 的 AWS SDK API Reference* 中的 [ListPolicies](https://docs.aws.amazon.com/goto/DotNetSDKV3/organizations-2016-11-28/ListPolicies)。

------
#### [ CLI ]

**AWS CLI**  
**擷取特定類型組織中所有政策的清單**  
下列範例示範如何取得篩選條件參數所指定的 SCP 清單：  

```
aws organizations list-policies --filter {{SERVICE_CONTROL_POLICY}}
```
輸出包含具有摘要資訊的政策清單：  

```
{
        "Policies": [
                {
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Name": "AllowAllS3Actions",
                        "AwsManaged": false,
                        "Id": "p-examplepolicyid111",
                        "Arn": "arn:aws:organizations::111111111111:policy/service_control_policy/p-examplepolicyid111",
                        "Description": "Enables account admins to delegate permissions for any S3 actions to users and roles in their accounts."
                },
                {
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Name": "AllowAllEC2Actions",
                        "AwsManaged": false,
                        "Id": "p-examplepolicyid222",
                        "Arn": "arn:aws:organizations::111111111111:policy/service_control_policy/p-examplepolicyid222",
                        "Description": "Enables account admins to delegate permissions for any EC2 actions to users and roles in their accounts."
                },
                {
                        "AwsManaged": true,
                        "Description": "Allows access to every operation",
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Id": "p-FullAWSAccess",
                        "Arn": "arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccess",
                        "Name": "FullAWSAccess"
                }
        ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPolicies](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/list-policies.html)。

------
#### [ Python ]

**適用於 Python 的 SDK (Boto3)**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/organizations#code-examples)中設定和執行。

```
def list_policies(policy_filter, orgs_client):
    """
    Lists the policies for the account, limited to the specified filter.

    :param policy_filter: The kind of policies to return.
    :param orgs_client: The Boto3 Organizations client.
    :return: The list of policies found.
    """
    try:
        response = orgs_client.list_policies(Filter=policy_filter)
        policies = response["Policies"]
        logger.info("Found %s %s policies.", len(policies), policy_filter)
    except ClientError:
        logger.exception("Couldn't get %s policies.", policy_filter)
        raise
    else:
        return policies
```
+  如需 API 詳細資訊，請參閱 *AWS SDK for Python (Boto3) API Reference* 中的 [ListPolicies](https://docs.aws.amazon.com/goto/boto3/organizations-2016-11-28/ListPolicies)。

------
#### [ SAP ABAP ]

**適用於 SAP ABAP 的開發套件**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/sap-abap/services/org#code-examples)中設定和執行。

```
    TRY.
        oo_result = lo_org->listpolicies(       " oo_result is returned for testing purposes. "
          iv_filter = iv_filter ).
        DATA(lt_policies) = oo_result->get_policies( ).
        MESSAGE 'Retrieved list of policies.' TYPE 'I'.
      CATCH /aws1/cx_orgaccessdeniedex.
        MESSAGE 'You do not have permission to list policies.' TYPE 'E'.
      CATCH /aws1/cx_orgawsorgsnotinuseex.
        MESSAGE 'Your account is not a member of an organization.' TYPE 'E'.
    ENDTRY.
```
+  如需 API 詳細資訊，請參閱《適用於 *AWS SAP ABAP 的 SDK API 參考*》中的 [ListPolicies](https://docs.aws.amazon.com/sdk-for-sap-abap/v1/api/latest/index.html)。

------

## 列出連接到根、OU 或帳戶的政策
<a name="list-all-pols-in-entity"></a>

**最低許可**  
若要列出連接到您組織內的根、組織單位 (OU) 或帳戶的政策，您必須擁有以下許可：  
`organizations:ListPoliciesForTarget`，並在包含指定目標 (或 "\*") 的 Amazon 資源名稱 (ARN) 的相同政策陳述式中具有 `Resource` 元素

------
#### [ AWS 管理主控台 ]

**列出直接連接到指定的根、OU 或帳戶的所有政策**

1. 登入 [AWS Organizations 主控台](https://console.aws.amazon.com/organizations/v2)。您必須以 IAM 使用者登入、擔任 IAM 角色，或是以組織管理帳戶中的根使用者 ([不建議](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#lock-away-credentials)) 身分登入。

1. 在 **[AWS 帳戶](https://console.aws.amazon.com/organizations/v2/home/accounts)** 頁面上，選擇您要檢視其政策的根、OU 或帳戶的名稱。您可能需要展開 OU (選擇 ![Gray cloud icon representing cloud computing or storage services.](http://docs.aws.amazon.com/zh_tw/organizations/latest/userguide/images/console-expand.png))，以尋找您想要的 OU。

1. 在根、OU 或帳戶頁面上，選擇 **Policies** (政策) 索引標籤。

   **Policies** (政策) 索引標籤會顯示連接至該根、OU 或帳戶的所有政策，並依政策類型分組。

------
#### [ AWS CLI & AWS SDKs ]

**列出直接連接到指定的根、OU 或帳戶的所有政策**  
您可以使用下列其中一項命令來列出連接到實體的政策：
+ AWS CLI: [list-policies-for-target](https://docs.aws.amazon.com/cli/latest/reference/organizations/list-policies-for-target.html)

  下列範例會列出連接至指定 OU 的所有服務控制政策。您必須同時指定根、OU 或帳戶的 ID，以及您想要列出的政策類型。

  ```
  $ aws organizations list-policies-for-target \
      --target-id ou-a1b2-f6g7h222 \
      --filter SERVICE_CONTROL_POLICY
  {
      "Policies": [
          {
              "Id": "p-FullAWSAccess",
              "Arn": "arn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccess",
              "Name": "FullAWSAccess",
              "Description": "Allows access to every operation",
              "Type": "SERVICE_CONTROL_POLICY",
              "AwsManaged": true
          }
      ]
  }
  ```
+ AWS SDKs：[ListPoliciesForTarget](https://docs.aws.amazon.com/organizations/latest/APIReference/API_ListPoliciesForTarget.html)

------

## 列出政策連接的所有根帳戶、OU 和帳戶
<a name="list-all-entities-attached-to-pol"></a>

**最低許可**  
若要列出政策連接的實體，您必須擁有以下許可：  
`organizations:ListTargetsForPolicy`，並在包含指定政策 (或 "\*") 的 ARN 的相同政策陳述式中具有 `Resource` 元素

------
#### [ AWS 管理主控台 ]

**列出已連接指定政策的所有根、OU 和帳戶**

1. 登入 [AWS Organizations 主控台](https://console.aws.amazon.com/organizations/v2)。您必須以 IAM 使用者登入、擔任 IAM 角色，或是以組織管理帳戶中的根使用者 ([不建議](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#lock-away-credentials)) 身分登入。

1. 在**[政策](https://console.aws.amazon.com/organizations/v2/home/policies)**頁面上，選擇政策類型，然後選擇您要檢查其附件的政策名稱。

1. 選擇 **Targets** (目標)索引標籤，以顯示所選政策連接的每個根、OU 和帳戶的資料表。

------
#### [ AWS CLI & AWS SDKs ]

**列出已連接指定政策的所有根、OU 和帳戶**  
您可以使用下列其中一項命令來列出擁有政策的實體：
+ AWS CLI: [list-targets-for-policy](https://docs.aws.amazon.com/cli/latest/reference/organizations/list-targets-for-policy.html)

  下列範例顯示指定政策的根、OU 和帳戶的所有連接。

  ```
  $ aws organizations list-targets-for-policy \
      --policy-id p-FullAWSAccess
  {
      "Targets": [
          {
              "TargetId": "ou-a1b2-f6g7h111",
              "Arn": "arn:aws:organizations::123456789012:ou/o-aa111bb222/ou-a1b2-f6g7h111",
              "Name": "testou2",
              "Type": "ORGANIZATIONAL_UNIT"
          },
          {
              "TargetId": "ou-a1b2-f6g7h222",
              "Arn": "arn:aws:organizations::123456789012:ou/o-aa111bb222/ou-a1b2-f6g7h222",
              "Name": "testou1",
              "Type": "ORGANIZATIONAL_UNIT"
          },
          {
              "TargetId": "123456789012",
              "Arn": "arn:aws:organizations::123456789012:account/o-aa111bb222/123456789012",
              "Name": "My Management Account (bisdavid)",
              "Type": "ACCOUNT"
          },
          {
              "TargetId": "r-a1b2",
              "Arn": "arn:aws:organizations::123456789012:root/o-aa111bb222/r-a1b2",
              "Name": "Root",
              "Type": "ROOT"
          }
      ]
  }
  ```
+ AWS SDKs：[ListTargetsForPolicy](https://docs.aws.amazon.com/organizations/latest/APIReference/API_ListTargetsForPolicy.html)

------

## 取得關於政策的詳細資訊
<a name="get-details-about-pol"></a>

**最低許可**  
若要顯示政策的詳細資訊，您必須擁有以下許可：  
`organizations:DescribePolicy`，並在包含指定政策 (或 "\*") 的 ARN 的相同政策陳述式中具有 `Resource` 元素

### AWS 管理主控台
<a name="get-details-about-pol-console"></a>

**取得關於政策的詳細資訊**

1. 登入 [AWS Organizations 主控台](https://console.aws.amazon.com/organizations/v2)。您必須以 IAM 使用者登入、擔任 IAM 角色，或是以組織管理帳戶中的根使用者 ([不建議](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#lock-away-credentials)) 身分登入。

1. 在 **[Policies](https://console.aws.amazon.com/organizations/v2/home/policies)** (政策) 頁面上，選擇您要檢查的政策類型，然後選擇政策名稱。

   政策頁面顯示關於政策的可用資訊，包括其 ARN、描述和連接的目標。
   + **Content** (內容) 索引標籤會以 JSON 格式顯示政策的目前內容。
   + **Targets** (目標) 索引標籤會顯示政策連接的根、OU 和帳戶的清單。
   + **Tags** (標籤) 索引標籤會顯示附加至政策的標籤。注意：Tags (標籤) 索引標籤不適用於 AWS 受管政策。

   若要編輯政策，請選擇 **Edit policy** (編輯政策)。由於每個政策類型都有不同的編輯需求，因此，請參閱建立和更新指定政策類型之政策的指示。

### AWS CLI & AWS SDKs
<a name="orgs_manage_accounts_create-new-cli-sdk"></a>

下列程式碼範例示範如何使用 `DescribePolicy`。

------
#### [ CLI ]

**AWS CLI**  
**取得政策的相關資訊**  
下列範例示範如何請求政策的相關資訊：  

```
aws organizations describe-policy --policy-id {{p-examplepolicyid111}}
```
輸出包含政策物件，其中包含政策的詳細資訊：  

```
{
        "Policy": {
                "Content": "{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": \"*\",\n      \"Resource\": \"*\"\n    }\n  ]\n}",
                "PolicySummary": {
                        "Arn": "arn:aws:organizations::111111111111:policy/o-exampleorgid/service_control_policy/p-examplepolicyid111",
                        "Type": "SERVICE_CONTROL_POLICY",
                        "Id": "p-examplepolicyid111",
                        "AwsManaged": false,
                        "Name": "AllowAllS3Actions",
                        "Description": "Enables admins to delegate S3 permissions"
                }
        }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DescribePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/organizations/describe-policy.html)。

------
#### [ Python ]

**適用於 Python 的 SDK (Boto3)**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/organizations#code-examples)中設定和執行。

```
def describe_policy(policy_id, orgs_client):
    """
    Describes a policy.

    :param policy_id: The ID of the policy to describe.
    :param orgs_client: The Boto3 Organizations client.
    :return: The description of the policy.
    """
    try:
        response = orgs_client.describe_policy(PolicyId=policy_id)
        policy = response["Policy"]
        logger.info("Got policy %s.", policy_id)
    except ClientError:
        logger.exception("Couldn't get policy %s.", policy_id)
        raise
    else:
        return policy
```
+  如需 API 詳細資訊，請參閱《AWS SDK for Python (Boto3) API 參考》**中的 [DescribePolicy](https://docs.aws.amazon.com/goto/boto3/organizations-2016-11-28/DescribePolicy)。

------
#### [ SAP ABAP ]

**適用於 SAP ABAP 的開發套件**  
 GitHub 上提供更多範例。尋找完整範例，並了解如何在 [AWS 程式碼範例儲存庫](https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/sap-abap/services/org#code-examples)中設定和執行。

```
    TRY.
        oo_result = lo_org->describepolicy(     " oo_result is returned for testing purposes. "
          iv_policyid = iv_policy_id ).
        DATA(lo_policy) = oo_result->get_policy( ).
        MESSAGE 'Retrieved policy details.' TYPE 'I'.
      CATCH /aws1/cx_orgaccessdeniedex.
        MESSAGE 'You do not have permission to describe the policy.' TYPE 'E'.
      CATCH /aws1/cx_orgpolicynotfoundex.
        MESSAGE 'The specified policy does not exist.' TYPE 'E'.
    ENDTRY.
```
+  如需 API 詳細資訊，請參閱《適用於 *AWS SAP ABAP 的 SDK API 參考*》中的 [DescribePolicy](https://docs.aws.amazon.com/sdk-for-sap-abap/v1/api/latest/index.html)。

------