

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

# 使用 Amazon 已验证权限策略在 API 操作中存储别名
使用策略存储别名

任何接受`policyStoreId`参数（例如、和 [GetPolicyStore](https://docs.amazonaws.cn/verifiedpermissions/latest/apireference/API_GetPolicyStore.html)）的 Amazon Verified Permissions 操作都可以接受策略存储别名来代替策略存储 ID。[IsAuthorized[IsAuthorizedWithToken](https://docs.amazonaws.cn/verifiedpermissions/latest/apireference/API_IsAuthorizedWithToken.html)](https://docs.amazonaws.cn/verifiedpermissions/latest/apireference/API_IsAuthorized.html)

**重要**  
使用策略存储别名作为`policyStoreId`参数值时，必须包含前`policy-store-alias/`缀。例如，使用`policy-store-alias/example-policy-store`，不是`example-policy-store`。

## 在操作中使用策略存储别名


以下`IsAuthorized`命令使用名为的策略存储别名`example-policy-store`来标识策略存储。

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

```
$ aws verifiedpermissions is-authorized \
    --policy-store-id policy-store-alias/example-policy-store \
    --principal entityType=User,entityId=alice \
    --action actionType=Action,actionId=view \
    --resource entityType=Photo,entityId=photo123
```

------

**注意**  
您不能使用策略存储别名来代替该[DeletePolicyStore](https://docs.amazonaws.cn/verifiedpermissions/latest/apireference/API_DeletePolicyStore.html)操作的`policyStoreId`字段。

## 跨使用策略存储别名 Amazon Web Services 区域


别名的最强大用途之一是在多个 Amazon Web Services 区域中运行的应用程序中。例如，您可能有一个全球应用程序，该应用程序在每个区域中使用不同的策略存储。
+ 在 us-east-1 中，你想使用。`PSEXAMPLEabcdefg111111`
+ 在 eu-west-1 中，你想使用。`PSEXAMPLEabcdefg222222`

您可以在每个区域创建不同版本的应用程序，也可以使用字典或 switch 语句为每个区域选择正确的策略存储。但是，在每个区域中创建具有相同策略存储别名的策略存储别名要容易得多。请记住，策略存储别名区分大小写。

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

```
$ aws --region us-east-1 verifiedpermissions create-policy-store-alias \
    --alias-name policy-store-alias/my-app \
    --policy-store-id PSEXAMPLEabcdefg111111

$ aws --region eu-west-1 verifiedpermissions create-policy-store-alias \
    --alias-name policy-store-alias/my-app \
    --policy-store-id PSEXAMPLEabcdefg222222
```

------

然后，在代码中使用策略存储别名。当您的代码在每个区域运行时，策略存储别名将引用其在该区域中的关联策略存储。

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

```
$ aws verifiedpermissions is-authorized \
    --policy-store-id policy-store-alias/my-app \
    --principal entityType=User,entityId=alice \
    --action actionType=Action,actionId=view \
    --resource entityType=Photo,entityId=photo123
```

------

但是，存在策略存储别名被删除的风险。在这种情况下，应用程序尝试使用策略存储别名将失败，您可能需要重新创建或更新策略存储别名。要降低这种风险，请谨慎地授予委托人管理您在应用程序中使用的策略存储别名的权限。