

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

# 使用 的已驗證許可範例 AWS CLI
<a name="cli_verifiedpermissions_code_examples"></a>

下列程式碼範例示範如何使用 AWS Command Line Interface 搭配 Verified Permissions 來執行動作和實作常見案例。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

每個範例均包含完整原始碼的連結，您可在連結中找到如何設定和執行內容中程式碼的相關指示。

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

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

### `create-identity-source`
<a name="verifiedpermissions_CreateIdentitySource_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-identity-source`。

**AWS CLI**  
**建立身分來源**  
下列 `create-identity-source` 範例會建立身分來源，可讓您參考存放在指定 Amazon Cognito 使用者集區中的身分。這些身分可在 Verified Permissions 中做為類型 `User` 的實體。  

```
aws verifiedpermissions create-identity-source \
    --configuration file://config.txt \
    --principal-entity-type "User" \
    --policy-store-id PSEXAMPLEabcdefg111111
```
`config.txt` 的內容：  

```
{
    "cognitoUserPoolConfiguration": {
        "userPoolArn": "arn:aws:cognito-idp:us-west-2:123456789012:userpool/us-west-2_1a2b3c4d5",
        "clientIds":["a1b2c3d4e5f6g7h8i9j0kalbmc"]
    }
}
```
輸出：  

```
{
    "createdDate": "2023-05-19T20:30:28.214829+00:00",
    "identitySourceId": "ISEXAMPLEabcdefg111111",
    "lastUpdatedDate": "2023-05-19T20:30:28.214829+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111"
}
```
如需身分來源的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[搭配使用 Amazon Verified Permissions 和身分提供者](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateIdentitySource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/create-identity-source.html)。

### `create-policy-store`
<a name="verifiedpermissions_CreatePolicyStore_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-policy-store`。

**AWS CLI**  
**建立政策存放區**  
下列`create-policy-store`範例會在目前 AWS 區域中建立政策存放區。  

```
aws verifiedpermissions create-policy-store \
    --validation-settings "mode=STRICT"
```
輸出：  

```
{
    "arn": "arn:aws:verifiedpermissions::123456789012:policy-store/PSEXAMPLEabcdefg111111",
    "createdDate": "2023-05-16T17:41:29.103459+00:00",
    "lastUpdatedDate": "2023-05-16T17:41:29.103459+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111"
}
```
如需政策存放區的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策存放區](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-stores.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreatePolicyStore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/create-policy-store.html)。

### `create-policy-template`
<a name="verifiedpermissions_CreatePolicyTemplate_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-policy-template`。

**AWS CLI**  
**建立政策範本**  
下列 `create-policy-template` 範例會使用包含主體預留位置的陳述式來建立政策範本。  

```
aws verifiedpermissions create-policy-template \
    --statement file://template1.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
`template1.txt` 的內容：  

```
permit(
    principal in ?principal,
    action == Action::"view",
    resource == Photo::"VacationPhoto94.jpg"
);
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:47:42.804511+00:00",
    "lastUpdatedDate": "2023-06-12T20:47:42.804511+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyTemplateId": "PTEXAMPLEabcdefg111111"
}
```
如需政策範本的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策範本](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-templates.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreatePolicyTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/create-policy-template.html)。

### `create-policy`
<a name="verifiedpermissions_CreatePolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `create-policy`。

**AWS CLI**  
**範例 1：建立靜態政策**  
下列 `create-policy` 範例會建立一個靜態政策，其中具有會指定主體與資源的政策範圍。  

```
aws verifiedpermissions create-policy \
    --definition file://definition1.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
檔案 `definition1.txt` 的內容：  

```
{
    "static": {
        "description":  "Grant everyone of janeFriends UserGroup access to the vacationFolder Album",
        "statement": "permit(principal in UserGroup::\"janeFriends\", action, resource in Album::\"vacationFolder\" );"
    }
}
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:33:37.382907+00:00",
    "lastUpdatedDate": "2023-06-12T20:33:37.382907+00:00",
    "policyId": "SPEXAMPLEabcdefg111111",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyType": "STATIC",
    "principal": {
        "entityId": "janeFriends",
        "entityType": "UserGroup"
    },
    "resource": {
        "entityId": "vacationFolder",
        "entityType": "Album"
    }
}
```
**範例 2：建立將資源存取權授予每個人的靜態政策**  
下列 `create-policy` 範例會建立一個靜態政策，其中具有僅指定資源的政策範圍。  

```
aws verifiedpermissions create-policy \
    --definition file://definition2.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
檔案 `definition2.txt` 的內容：  

```
{
    "static": {
        "description":  "Grant everyone access to the publicFolder Album",
        "statement": "permit(principal, action, resource in Album::\"publicFolder\");"
    }
}
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:39:44.975897+00:00",
    "lastUpdatedDate": "2023-06-12T20:39:44.975897+00:00",
    "policyId": "PbfR73F8oh5MMfr9uRtFDB",
    "policyStoreId": "PSEXAMPLEabcdefg222222",
    "policyType": "STATIC",
    "resource": {
        "entityId": "publicFolder",
        "entityType": "Album"
    }
}
```
**範例 3：建立與指定範本相關聯的範本連結政策**  
下列 `create-policy` 範例會使用指定的政策範本建立範本連結政策，並將要使用的指定主體與新範本連結政策建立關聯。  

```
aws verifiedpermissions create-policy \
    --definition file://definition.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
`definition.txt` 的內容：  

```
{
    "templateLinked": {
        "policyTemplateId": "PTEXAMPLEabcdefg111111",
        "principal": {
            "entityType": "User",
            "entityId": "alice"
        }
    }
}
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:49:51.490211+00:00",
    "lastUpdatedDate": "2023-06-12T20:49:51.490211+00:00",
    "policyId": "TPEXAMPLEabcdefg111111",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyType": "TEMPLATE_LINKED",
    "principal": {
        "entityId": "alice",
        "entityType": "User"
    },
    "resource": {
        "entityId": "VacationPhoto94.jpg",
        "entityType": "Photo"
    }
}
```
如需政策的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreatePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/create-policy.html)。

### `delete-identity-source`
<a name="verifiedpermissions_DeleteIdentitySource_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-identity-source`。

**AWS CLI**  
**刪除身分來源**  
下列 `delete-identity-source` 範例會刪除具有指定 ID 的身分來源。  

```
aws verifiedpermissions delete-identity-source \
    --identity-source-id ISEXAMPLEabcdefg111111 \
    --policy-store-id PSEXAMPLEabcdefg111111
```
此命令不會產生輸出。  
如需身分來源的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[搭配使用 Amazon Verified Permissions 和身分提供者](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteIdentitySource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/delete-identity-source.html)。

### `delete-policy-store`
<a name="verifiedpermissions_DeletePolicyStore_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-policy-store`。

**AWS CLI**  
**刪除政策存放區**  
下列 `delete-policy-store` 範例會刪除具有指定 ID 的政策存放區。  

```
aws verifiedpermissions delete-policy-store \
    --policy-store-id PSEXAMPLEabcdefg111111
```
此命令不會產生輸出。  
如需政策存放區的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策存放區](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-stores.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeletePolicyStore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/delete-policy-store.html)。

### `delete-policy-template`
<a name="verifiedpermissions_DeletePolicyTemplate_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-policy-template`。

**AWS CLI**  
**刪除政策範本**  
下列 `delete-policy-template` 範例會刪除具有指定 ID 的政策範本。  

```
aws verifiedpermissions delete-policy \
    --policy-template-id PTEXAMPLEabcdefg111111 \
    --policy-store-id PSEXAMPLEabcdefg111111
```
此命令不會產生輸出。  
如需政策範本的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策範本](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-templates.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeletePolicyTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/delete-policy-template.html)。

### `delete-policy`
<a name="verifiedpermissions_DeletePolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `delete-policy`。

**AWS CLI**  
**刪除靜態或範本連結政策**  
下列 `delete-policy` 範例會刪除具有指定 ID 的政策。  

```
aws verifiedpermissions delete-policy \
    --policy-id SPEXAMPLEabcdefg111111 \
    --policy-store-id PSEXAMPLEabcdefg111111
```
此命令不會產生輸出。  
如需政策的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeletePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/delete-policy.html)。

### `get-identity-source`
<a name="verifiedpermissions_GetIdentitySource_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-identity-source`。

**AWS CLI**  
**擷取身分來源的詳細資訊**  
下列 `get-identity-source` 範例會顯示具有所指定 ID 的身分來源詳細資訊。  

```
aws verifiedpermissions get-identity-source \
    --identity-source  ISEXAMPLEabcdefg111111 \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "createdDate": "2023-06-12T22:27:49.150035+00:00",
    "details": {
        "clientIds": [ "a1b2c3d4e5f6g7h8i9j0kalbmc" ],
        "discoveryUrl": "https://cognito-idp.us-west-2.amazonaws.com/us-west-2_1a2b3c4d5",
        "openIdIssuer": "COGNITO",
        "userPoolArn": "arn:aws:cognito-idp:us-west-2:123456789012:userpool/us-west-2_1a2b3c4d5"
    },
    "identitySourceId": "ISEXAMPLEabcdefg111111",
    "lastUpdatedDate": "2023-06-12T22:27:49.150035+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "principalEntityType": "User"
}
```
如需身分來源的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[搭配使用 Amazon Verified Permissions 和身分提供者](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetIdentitySource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/get-identity-source.html)。

### `get-policy-store`
<a name="verifiedpermissions_GetPolicyStore_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-policy-store`。

**AWS CLI**  
**擷取有關政策存放區的詳細資訊**  
下列 `get-policy-store` 範例會顯示具有所指定 ID 的政策存放區詳細資訊。  

```
aws verifiedpermissions get-policy-store \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "arn": "arn:aws:verifiedpermissions::123456789012:policy-store/PSEXAMPLEabcdefg111111",
    "createdDate": "2023-06-05T20:16:46.225598+00:00",
    "lastUpdatedDate": "2023-06-08T20:40:23.173691+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "validationSettings": { "mode": "OFF" }
}
```
如需政策存放區的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策存放區](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-stores.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetPolicyStore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/get-policy-store.html)。

### `get-policy-template`
<a name="verifiedpermissions_GetPolicyTemplate_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-policy-template`。

**AWS CLI**  
**擷取政策範本的詳細資訊**  
下列 `get-policy-template` 範例會顯示具有所指定 ID 的政策範本詳細資訊。  

```
aws verifiedpermissions get-policy-template \
    --policy-template-id  PTEXAMPLEabcdefg111111 \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:47:42.804511+00:00",
    "lastUpdatedDate": "2023-06-12T20:47:42.804511+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyTemplateId": "PTEXAMPLEabcdefg111111",
    "statement": "permit(\n    principal in ?principal,\n    action == Action::\"view\",\n    resource == Photo::\"VacationPhoto94.jpg\"\n);"
}
```
如需政策範本的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策範本](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-templates.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetPolicyTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/get-policy-template.html)。

### `get-policy`
<a name="verifiedpermissions_GetPolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-policy`。

**AWS CLI**  
**擷取有關政策的詳細資訊**  
下列 `get-policy` 範例會顯示具有所指定 ID 的政策詳細資訊。  

```
aws verifiedpermissions get-policy \
    --policy-id PSEXAMPLEabcdefg111111 \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:33:37.382907+00:00",
    "definition": {
        "static": {
            "description": "Grant everyone of janeFriends UserGroup access to the vacationFolder Album",
            "statement": "permit(principal in UserGroup::\"janeFriends\", action, resource in Album::\"vacationFolder\" );"
        }
    },
    "lastUpdatedDate": "2023-06-12T20:33:37.382907+00:00",
    "policyId": "SPEXAMPLEabcdefg111111",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyType": "STATIC",
    "principal": {
        "entityId": "janeFriends",
        "entityType": "UserGroup"
    },
    "resource": {
        "entityId": "vacationFolder",
        "entityType": "Album"
    }
}
```
如需政策的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetPolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/get-policy.html)。

### `get-schema`
<a name="verifiedpermissions_GetSchema_cli_topic"></a>

以下程式碼範例顯示如何使用 `get-schema`。

**AWS CLI**  
**擷取政策存放區中的結構描述**  
下列 `get-schema` 範例會顯示在所指定政策存放區中的結構描述詳細資訊。  

```
aws verifiedpermissions get-schema \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "schema": "{\"MySampleNamespace\":{\"entityTypes\":{\"Employee\":{\"shape\":{\"attributes\":{\"jobLevel\":{\"type\":\"Long\"},\"name\":{\"type\":\"String\"}},\"type\":\"Record\"}}},\"actions\":{\"remoteAccess\":{\"appliesTo\":{\"principalTypes\":[\"Employee\"]}}}}}",
    "createdDate": "2023-06-14T17:47:13.999885+00:00",
    "lastUpdatedDate": "2023-06-14T17:47:13.999885+00:00"
}
```
如需結構描述的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[政策存放區結構描述](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/schema.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetSchema](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/get-schema.html)。

### `is-authorized-with-token`
<a name="verifiedpermissions_IsAuthorizedWithToken_cli_topic"></a>

以下程式碼範例顯示如何使用 `is-authorized-with-token`。

**AWS CLI**  
**範例 1：請求使用者請求的授權決定 (允許)**  
下列 `is-authorized-with-token` 範例會為 Amazon Cognito 驗證的使用者請求授權決定。此請求使用 Cognito 提供的身分字符，而不是存取字符。在此範例中，指定的資訊存放區會設定為將主體傳回做為類型 `CognitoUser` 的實體。  

```
aws verifiedpermissions is-authorized-with-token \
    --action actionId="View",actionType="Action" \
    --resource entityId="vacationPhoto94.jpg",entityType="Photo" \
    --policy-store-id PSEXAMPLEabcdefg111111 \
    --identity-token "AbCdE12345...long.string...54321EdCbA"
```
政策存放區包含具有下列陳述式的政策，可接受來自所指定 Cognito 使用者集區和應用程式 ID 的身分。  

```
permit(
    principal == CognitoUser::"us-east-1_1a2b3c4d5|a1b2c3d4e5f6g7h8i9j0kalbmc",
    action,
    resource == Photo::"VacationPhoto94.jpg"
);
```
輸出：  

```
{
    "decision":"Allow",
    "determiningPolicies":[
        {
        "determiningPolicyId":"SPEXAMPLEabcdefg111111"
        }
    ],
    "errors":[]
}
```
如需使用 Cognito 使用者集區中身分的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[搭配使用 Amazon Verified Permissions 和身分提供者](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [IsAuthorizedWithToken](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/is-authorized-with-token.html)。

### `is-authorized`
<a name="verifiedpermissions_IsAuthorized_cli_topic"></a>

以下程式碼範例顯示如何使用 `is-authorized`。

**AWS CLI**  
**範例 1：請求使用者請求的授權決定 (允許)**  
下列 `is-authorized` 範例會針對類型為 `User` 名為 `Alice`，且想要對類型為 `Photo` 名為 `VacationPhoto94.jpg` 的資源執行 `updatePhoto` 操作的主體請求授權決策。  
此回應顯示該請求已由一個政策允許。  

```
aws verifiedpermissions is-authorized \
    --principal entityType=User,entityId=alice \
    --action actionType=Action,actionId=view \
    --resource entityType=Photo,entityId=VactionPhoto94.jpg \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "decision": "ALLOW",
    "determiningPolicies": [
        {
            "policyId": "SPEXAMPLEabcdefg111111"
        }
    ],
    "errors": []
}
```
**範例 2：請求使用者請求的授權決策 (拒絕)**  
下列範例與上一個範例相同，但主體是 `User::"Bob"`。政策存放區未包含允許該使用者存取 `Album::"alice_folder"` 的任何政策。  
此輸出指出 `Deny` 是隱含的，因為 `DeterminingPolicies` 的清單是空的。  

```
aws verifiedpermissions create-policy \
    --definition file://definition2.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "decision": "DENY",
    "determiningPolicies": [],
    "errors": []
}
```
如需詳細資訊，請參閱《[Amazon Verified Permissions 使用者指南](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/)》。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [IsAuthorized](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/is-authorized.html)。

### `list-identity-sources`
<a name="verifiedpermissions_ListIdentitySources_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-identity-sources`。

**AWS CLI**  
**列出可用的身分來源**  
下列 `list-identity-sources` 範例會列出所指定政策存放區中的所有身分來源。  

```
aws verifiedpermissions list-identity-sources \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "identitySources": [
        {
            "createdDate": "2023-06-12T22:27:49.150035+00:00",
            "details": {
                "clientIds": [ "a1b2c3d4e5f6g7h8i9j0kalbmc" ],
                "discoveryUrl": "https://cognito-idp.us-west-2.amazonaws.com/us-west-2_1a2b3c4d5",
                "openIdIssuer": "COGNITO",
                "userPoolArn": "arn:aws:cognito-idp:us-west-2:123456789012:userpool/us-west-2_1a2b3c4d5"
            },
            "identitySourceId": "ISEXAMPLEabcdefg111111",
            "lastUpdatedDate": "2023-06-12T22:27:49.150035+00:00",
            "policyStoreId": "PSEXAMPLEabcdefg111111",
            "principalEntityType": "User"
        }
    ]
}
```
如需身分來源的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[搭配使用 Amazon Verified Permissions 和身分提供者](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListIdentitySources](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/list-identity-sources.html)。

### `list-policies`
<a name="verifiedpermissions_ListPolicies_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-policies`。

**AWS CLI**  
**列出可用的政策**  
下列 `list-policies` 範例會列出所指定政策存放區中的所有政策。  

```
aws verifiedpermissions list-policies \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "policies": [
        {
            "createdDate": "2023-06-12T20:33:37.382907+00:00",
            "definition": {
                "static": {
                    "description": "Grant everyone of janeFriends UserGroup access to the vacationFolder Album"
                }
            },
            "lastUpdatedDate": "2023-06-12T20:33:37.382907+00:00",
            "policyId": "SPEXAMPLEabcdefg111111",
            "policyStoreId": "PSEXAMPLEabcdefg111111",
            "policyType": "STATIC",
            "principal": {
                "entityId": "janeFriends",
                "entityType": "UserGroup"
            },
            "resource": {
                "entityId": "vacationFolder",
                "entityType": "Album"
            }
        },
        {
            "createdDate": "2023-06-12T20:39:44.975897+00:00",
            "definition": {
                "static": {
                    "description": "Grant everyone access to the publicFolder Album"
                }
            },
            "lastUpdatedDate": "2023-06-12T20:39:44.975897+00:00",
            "policyId": "SPEXAMPLEabcdefg222222",
            "policyStoreId": "PSEXAMPLEabcdefg111111",
            "policyType": "STATIC",
            "resource": {
                "entityId": "publicFolder",
                "entityType": "Album"
            }
        },
        {
            "createdDate": "2023-06-12T20:49:51.490211+00:00",
            "definition": {
                "templateLinked": {
                    "policyTemplateId": "PTEXAMPLEabcdefg111111"
                }
            },
            "lastUpdatedDate": "2023-06-12T20:49:51.490211+00:00",
            "policyId": "SPEXAMPLEabcdefg333333",
            "policyStoreId": "PSEXAMPLEabcdefg111111",
            "policyType": "TEMPLATE_LINKED",
            "principal": {
                "entityId": "alice",
                "entityType": "User"
            },
            "resource": {
                "entityId": "VacationPhoto94.jpg",
                "entityType": "Photo"
            }
        }
    ]
}
```
如需政策的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPolicies](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/list-policies.html)。

### `list-policy-stores`
<a name="verifiedpermissions_ListPolicyStores_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-policy-stores`。

**AWS CLI**  
**列出可用的政策存放區**  
下列`list-policy-stores`範例列出 區域中的所有政策存放 AWS 區。Verified Permissions 的所有命令，但 `create-policy-store` 和 `list-policy-stores` 需要您指定所要使用政策存放區的 ID。  

```
aws verifiedpermissions list-policy-stores
```
輸出：  

```
{
    "policyStores": [
        {
            "arn": "arn:aws:verifiedpermissions::123456789012:policy-store/PSEXAMPLEabcdefg111111",
            "createdDate": "2023-06-05T20:16:46.225598+00:00",
            "policyStoreId": "PSEXAMPLEabcdefg111111"
        },
        {
            "arn": "arn:aws:verifiedpermissions::123456789012:policy-store/PSEXAMPLEabcdefg222222",
            "createdDate": "2023-06-08T18:09:37.364356+00:00",
            "policyStoreId": "PSEXAMPLEabcdefg222222"
        },
        {
            "arn": "arn:aws:verifiedpermissions::123456789012:policy-store/PSEXAMPLEabcdefg333333",
            "createdDate": "2023-06-08T18:09:46.920600+00:00",
            "policyStoreId": "PSEXAMPLEabcdefg333333"
        }
    ]
}
```
如需政策存放區的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策存放區](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-stores.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPolicyStores](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/list-policy-stores.html)。

### `list-policy-templates`
<a name="verifiedpermissions_ListPolicyTemplates_cli_topic"></a>

以下程式碼範例顯示如何使用 `list-policy-templates`。

**AWS CLI**  
**列出可用的政策範本**  
下列 `list-policy-templates` 範例會列出所指定政策存放區中的所有政策範本。  

```
aws verifiedpermissions list-policy-templates \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "policyTemplates": [
        {
            "createdDate": "2023-06-12T20:47:42.804511+00:00",
            "lastUpdatedDate": "2023-06-12T20:47:42.804511+00:00",
            "policyStoreId": "PSEXAMPLEabcdefg111111",
            "policyTemplateId": "PTEXAMPLEabcdefg111111"
        }
    ]
}
```
如需政策範本的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策範本](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-templates.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListPolicyTemplates](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/list-policy-templates.html)。

### `put-schema`
<a name="verifiedpermissions_PutSchema_cli_topic"></a>

以下程式碼範例顯示如何使用 `put-schema`。

**AWS CLI**  
**將結構描述儲存到政策存放區**  
下列 `put-schema` 範例會在指定的政策存放區中建立或取代結構描述。  
輸入檔案中的 `cedarJson` 參數採用 JSON 物件的字串表示法。它包含最外部引號對內的嵌入引號 (")。這需要您將 JSON 轉換為字串，方法是將所有嵌入引號前面加上反斜線字元 ( " )，並將所有行合併為沒有換行符號的單一文字行。  
您可以將範例字串顯示為多行以方便閱讀，但操作需要以單行字串形式提交參數。  
aws verifiedpermissions put-schema --definition file://schema.txt --policy-store-id PSEXAMPLEabcdefg111111  
`schema.txt` 的內容：  

```
{
    "cedarJson": "{\"MySampleNamespace\": {\"actions\": {\"remoteAccess\": {
            \"appliesTo\": {\"principalTypes\": [\"Employee\"]}}},\"entityTypes\": {
            \"Employee\": {\"shape\": {\"attributes\": {\"jobLevel\": {\"type\":
            \"Long\"},\"name\": {\"type\": \"String\"}},\"type\": \"Record\"}}}}}"
}
```
輸出：  

```
{
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "namespaces": [
        "MySampleNamespace"
    ],
    "createdDate": "2023-06-14T17:47:13.999885+00:00",
    "lastUpdatedDate": "2023-06-14T17:47:13.999885+00:00"
}
```
如需結構描述的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[政策存放區結構描述](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/schema.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [PutSchema](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/put-schema.html)。

### `update-identity-source`
<a name="verifiedpermissions_UpdateIdentitySource_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-identity-source`。

**AWS CLI**  
**更新身分來源**  
下列 `update-identity-source` 範例會提供新的 Cognito 使用者集區組態，並變更由身分來源傳回的實體類型，來修改指定的身分來源。  

```
aws verifiedpermissions update-identity-source
    --identity-source-id ISEXAMPLEabcdefg111111 \
    --update-configuration file://config.txt \
    --principal-entity-type "Employee" \
    --policy-store-id PSEXAMPLEabcdefg111111
```
`config.txt` 的內容：  

```
{
        "cognitoUserPoolConfiguration": {
                "userPoolArn": "arn:aws:cognito-idp:us-west-2:123456789012:userpool/us-west-2_1a2b3c4d5",
                "clientIds":["a1b2c3d4e5f6g7h8i9j0kalbmc"]
        }
}
```
輸出：  

```
{
    "createdDate": "2023-05-19T20:30:28.214829+00:00",
    "identitySourceId": "ISEXAMPLEabcdefg111111",
    "lastUpdatedDate": "2023-05-19T20:30:28.214829+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111"
}
```
如需身分來源的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的[搭配使用 Amazon Verified Permissions 和身分提供者](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/identity-providers.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateIdentitySource](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/update-identity-source.html)。

### `update-policy-store`
<a name="verifiedpermissions_UpdatePolicyStore_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-policy-store`。

**AWS CLI**  
**更新政策存放區**  
下列 `update-policy-store` 範例會透過變更政策存放區驗證設定來修改政策存放區。  

```
aws verifiedpermissions update-policy-store \
    --validation-settings "mode=STRICT" \
    --policy-store-id PSEXAMPLEabcdefg111111
```
輸出：  

```
{
    "arn": "arn:aws:verifiedpermissions::123456789012:policy-store/PSEXAMPLEabcdefg111111",
    "createdDate": "2023-05-16T17:41:29.103459+00:00",
    "lastUpdatedDate": "2023-05-16T17:41:29.103459+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111"
}
```
如需政策存放區的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策存放區](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-stores.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdatePolicyStore](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/update-policy-store.html)。

### `update-policy-template`
<a name="verifiedpermissions_UpdatePolicyTemplate_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-policy-template`。

**AWS CLI**  
**範例 1：更新政策範本**  
下列 `update-policy-template` 範例會修改指定的範本連結政策，以取代其政策陳述式。  

```
aws verifiedpermissions update-policy-template \
    --policy-template-id PTEXAMPLEabcdefg111111 \
    --statement file://template1.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
檔案 `template1.txt` 的內容：  

```
permit(
    principal in ?principal,
    action == Action::"view",
    resource == Photo::"VacationPhoto94.jpg"
);
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:47:42.804511+00:00",
    "lastUpdatedDate": "2023-06-12T20:47:42.804511+00:00",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyTemplateId": "PTEXAMPLEabcdefg111111"
}
```
如需政策範本的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策範本](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policy-templates.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdatePolicyTemplate](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/update-policy-template.html)。

### `update-policy`
<a name="verifiedpermissions_UpdatePolicy_cli_topic"></a>

以下程式碼範例顯示如何使用 `update-policy`。

**AWS CLI**  
**更新靜態政策**  
下列 `update-policy` 範例會透過更新靜態政策的描述和陳述式來修改現有的靜態政策。  

```
aws verifiedpermissions update-policy \
    --policy-id SPEXAMPLEabcdefg111111 \
    --definition file://updated-definition.txt \
    --policy-store-id PSEXAMPLEabcdefg111111
```
`statement` 參數採用 JSON 物件的字串表示法。它包含最外部引號對內的嵌入引號 (")。這需要您將 JSON 轉換為字串，方法是將所有嵌入引號前面加上反斜線字元 ( " )，並將所有行合併為沒有換行符號的單一文字行。  
您可以將範例字串顯示為多行以方便閱讀，但操作需要以單行字串形式提交參數。  
檔案 `updated-definition.txt` 的內容：  

```
{
    "static": {
        "description": "Updated policy to grant janeFriends UserGroup access to the vacationFolder Album with view action only",
        "statement": "permit(principal in UserGroup::\"janeFriends\", action == Action::\"view\", resource in Album::\"vacationFolder\" );"
    }
}
```
輸出：  

```
{
    "createdDate": "2023-06-12T20:33:37.382907+00:00",
    "lastUpdatedDate": "2023-06-12T20:33:37.382907+00:00",
    "policyId": "SPEXAMPLEabcdefg111111",
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "policyType": "STATIC",
    "principal": {
        "entityId": "janeFriends",
        "entityType": "UserGroup"
    },
    "resource": {
        "entityId": "vacationFolder",
        "entityType": "Album"
    }
}
```
如需政策的詳細資訊，請參閱《*Amazon Verified Permissions 使用者指南*》中的 [Amazon Verified Permissions 政策](https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/policies.html)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdatePolicy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/verifiedpermissions/update-policy.html)。