

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

# Amazon GameLift Servers 的 IAM 权限示例
<a name="gamelift-iam-policy-examples"></a>

使用这些示例中的语法为需要访问Amazon GameLift Servers资源的用户设置 Amazon Identity and Access Management (IAM) 权限。有关管理用户权限的更多信息，请参阅[为 Amazon GameLift Servers 设置用户权限](setting-up-aws-login.md#getting-started-create-iam-user)。在管理 IAM Identity Center 以外的用户的权限时，最佳实操是始终向 IAM 角色或用户组授予权限，而不是向个人用户授予权限。

如果您要Amazon GameLift ServersFleetIQ用作独立解决方案，请参阅[设置您 Amazon Web Services 账户 的Amazon GameLift ServersFleetIQ](https://docs.amazonaws.cn/gameliftservers/latest/fleetiqguide/gsg-iam-permissions.html)。

## 管理权限示例
<a name="iam-policy-simple-example"></a>

这些示例为托管管理员或开发人员提供了有针对性的访问权限，以便管理 Amazon GameLift Servers 游戏托管资源。

**Example Amazon GameLift Servers 资源完全访问权限语法**  
以下示例扩展了对所有 Amazon GameLift Servers 资源的完全访问权限。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": "gamelift:*",
    "Resource": "*"
  }
}
```

**Example 支持默认未启用区域的 Amazon GameLift Servers 资源权限的语法**  
以下示例将访问权限扩展到所有默认情况下未启用的Amazon GameLift Servers资源和 Amazon 区域。有关默认情况下未启用的区域以及如何启用这些区域的更多信息，请参阅《Amazon Web Services 一般参考》**中的[管理 Amazon Web Services 区域](https://docs.amazonaws.cn/general/latest/gr/rande-manage.html)。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": [
      "ec2:DescribeRegions",
      "gamelift:*"
    ],
    "Resource": "*"
  }
}
```

**Example Amazon GameLift Servers 资源访问 Amazon ECR 中的容器映像的语法**  
以下示例扩展了 Amazon GameLift Servers 用户在使用托管式容器实例集时所需的 Amazon Elastic Container Registry（Amazon ECR）操作的访问权限。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Effect": "Allow",
    "Action": [
      "ecr:DescribeImages",
      "ecr:BatchGetImage",
      "ecr:GetDownloadUrlForLayer"
    ],
    "Resource": "*"
  }
}
```

**Example Amazon GameLift Servers 资源和 `PassRole` 权限的语法**  
以下示例扩展了对所有 Amazon GameLift Servers 资源的访问权限，并允许用户将 IAM 服务角色传递给 Amazon GameLift Servers。服务角色使 Amazon GameLift Servers 能够有限地代表您访问其他资源和服务，如[为 Amazon GameLift Servers 设置 IAM 服务角色](setting-up-role.md)中所述。例如，在响应 `CreateBuild` 请求时，Amazon GameLift Servers 需要访问您在 Amazon S3 存储桶中的生成包文件。有关该`PassRole`操作的更多信息，请参阅 [IAM *用户指南中的 IAM：将 IAM* 角色传递给特定 Amazon 服务](https://docs.amazonaws.cn/IAM/latest/UserGuide/reference_policies_examples_iam-passrole-service.html)。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": "gamelift:*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "iam:PassRole",
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "iam:PassedToService": "gamelift.amazonaws.com"
        }
      }
    }
  ]
}
```

## 玩家用户权限示例
<a name="iam-policy-admin-game-dev-example"></a>

这些示例允许后端服务或其他实体对 Amazon GameLift Servers API 进行 API 调用。它们涵盖了管理游戏会话、玩家会话和对战的常见场景。有关更多信息，请参阅[为游戏设置编程式访问权限](setting-up-aws-login.md#getting-started-iam-player-user)。

**Example 游戏会话置放权限的语法**  
以下示例扩展了对使用游戏会话放置队列来创建游戏会话和管理玩家会话的访问权限。Amazon GameLift Servers APIs     
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "PlayerPermissionsForGameSessionPlacements",
    "Effect": "Allow",
    "Action": [
      "gamelift:StartGameSessionPlacement",
      "gamelift:DescribeGameSessionPlacement",
      "gamelift:StopGameSessionPlacement",
      "gamelift:CreatePlayerSession",
      "gamelift:CreatePlayerSessions",
      "gamelift:DescribeGameSessions"
    ],
    "Resource": "*"
  }
}
```

**Example 对战权限的语法**  
以下示例扩展了FlexMatch对管理配对活动的访问权限。Amazon GameLift Servers APIs FlexMatch为新游戏或现有游戏会话匹配玩家，并为托管的游戏启动游戏会话放置。Amazon GameLift Servers有关 FlexMatch 的更多信息，请参阅[什么是 Amazon GameLift ServersFlexMatch？](https://docs.amazonaws.cn/gameliftservers/latest/flexmatchguide/match-intro.html)    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "PlayerPermissionsForGameSessionMatchmaking",
    "Effect": "Allow",
    "Action": [
      "gamelift:StartMatchmaking",
      "gamelift:DescribeMatchmaking",
      "gamelift:StopMatchmaking",
      "gamelift:AcceptMatch",
      "gamelift:StartMatchBackfill",
      "gamelift:DescribeGameSessions"
    ],
    "Resource": "*"
  }
}
```

**Example 手动游戏会话放置权限的语法**  
以下示例扩展了对在Amazon GameLift Servers APIs 指定队列上手动创建游戏会话和玩家会话的访问权限。此场景支持不使用放置队列的游戏，例如允许玩家通过从可用游戏会话列表中进行选择来加入的游戏（“list-and-pick” 方法）。    
****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": {
    "Sid": "PlayerPermissionsForManualGameSessions",
    "Effect": "Allow",
    "Action": [
      "gamelift:CreateGameSession",
      "gamelift:DescribeGameSessions",
      "gamelift:SearchGameSessions",
      "gamelift:CreatePlayerSession",
      "gamelift:CreatePlayerSessions",
      "gamelift:DescribePlayerSessions"
    ],
    "Resource": "*"
  }
}
```