

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Amazon Verified Permissions 策略存储架构
<a name="schema"></a>

*[架构](https://docs.cedarpolicy.com/overview/terminology.html#schema)*是对应用程序支持的实体类型结构以及应用程序在授权请求中可能提供的操作的声明。要了解已验证权限和 Cedar 处理架构的方式之间的区别，请参阅[架构支持](terminology-differences-avp-cedar.md#differences-templates)。

有关更多信息，请参阅《Cedar 策略语言参考指南》中的 [Cedar 架构格式](https://docs.cedarpolicy.com/schema/schema.html)。

**注意**  
您可以自由选择是否在 Verified Permissions 中使用架构，但我们强烈建议您在生产软件中使用架构。创建新策略时，Verified Permissions 可以使用架构来验证范围和条件中引用的实体和属性，以避免策略中出现可能导致系统行为混乱的错别字和错误。如果您激活[策略验证](policy-validation-mode.md)，则所有新策略都必须符合该架构。

------
#### [ Amazon Web Services 管理控制台 ]

**要创建架构，请按以下步骤操作：**

1. 打开已[验证权限控制台](https://console.amazonaws.cn/verifiedpermissions/)。选择您的保单商店。

1. 在左侧导航窗格中，选择**架构**。

1. 选择**创建架构**。

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

**要提交新架构，或使用 Amazon CLI覆盖现有架构，请按以下步骤操作：**  
您可以通过运行类似于以下示例的 Amazon CLI 命令来创建策略存储。

考虑使用包含以下 Cedar 内容的架构：

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

您必须先将 JSON 转义为单行字符串，并在其前面加上其数据类型的声明：`cedarJson`。以下示例使用 `schema.json` 文件中的以下内容，该文件包含 JSON 架构的转义版本。

**注意**  
为了便于阅读，此处的示例采用的是换行格式。您必须将整个文件放在一行上，这样命令才能接受。

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

```
$ aws verifiedpermissions put-schema \
    --definition file://schema.json \
    --policy-store PSEXAMPLEabcdefg111111
{
    "policyStoreId": "PSEXAMPLEabcdefg111111",
    "namespaces": [
        "MySampleNamespace"
    ],
    "createdDate": "2023-07-17T21:07:43.659196+00:00",
    "lastUpdatedDate": "2023-08-16T17:03:53.081839+00:00"
}
```

------
#### [ Amazon SDKs ]

您可以使用 `PutSchema` API 创建策略存储。有关更多信息，请参阅[PutSchema](https://docs.amazonaws.cn/verifiedpermissions/latest/apireference/API_PutSchema.html)《Amazon 已验证权限 API 参考指南》。

------