

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

# 对 Amazon Keyspaces 使用服务相关角色
<a name="using-service-linked-roles"></a>

[Amazon Keyspaces（适用于 Apache Cassandra）使用 AWS Identity and Access Management (IAM) 服务相关角色。](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)服务相关角色是一种独特类型的 IAM 角色，它与 Amazon Keyspaces 直接相关。服务相关角色由 Amazon Keyspaces 预定义，包括该服务代表您调用 AWS 其他服务所需的所有权限。

有关支持服务相关角色的其他服务的信息，请参阅与 [IAM 配合使用的AWS 服务，](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html)并在**服务相关角色**列中查找标有 “**是**” 的服务。选择**是**和链接，查看该服务的服务关联角色文档。

**Topics**
+ [使用角色实现 Amazon Keyspaces 应用程序自动扩缩](using-service-linked-roles-app-auto-scaling.md)
+ [使用角色进行 Amazon Keyspaces 多区域复制](using-service-linked-roles-multi-region-replication.md)
+ [在 Amazon Keyspaces CDC 直播中使用角色](using-service-linked-roles-CDC-streams.md)

# 使用角色实现 Amazon Keyspaces 应用程序自动扩缩
<a name="using-service-linked-roles-app-auto-scaling"></a>

[Amazon Keyspaces（适用于 Apache Cassandra）使用 AWS Identity and Access Management (IAM) 服务相关角色。](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)服务相关角色是一种独特类型的 IAM 角色，它与 Amazon Keyspaces 直接相关。服务相关角色由 Amazon Keyspaces 预定义，包括该服务代表您调用 AWS 其他服务所需的所有权限。

服务相关角色可让您更轻松地设置 Amazon Keyspaces，因为您不必手动添加必要的权限。Amazon Keyspaces 定义其服务相关角色的权限，除非另外定义，否则只有 Amazon Keyspaces 可以代入该角色。定义的权限包括信任策略和权限策略，而且权限策略不能附加到任何其它 IAM 实体。

只有在首先删除服务相关角色的相关资源后，才能删除该角色。这将保护您的 Amazon Keyspaces 资源，因为您不会无意中删除对资源的访问权限。

## Amazon Keyspaces 的服务相关角色权限
<a name="service-linked-role-permissions-app-auto-scaling"></a>

Amazon Keyspaces 使用名为**AWSServiceRoleForApplicationAutoScaling\$1CassandraTable**的服务相关角色允许 Auto Scaling 代表您调用亚马逊密钥空间和亚马逊。 CloudWatch 

 AWSServiceRoleForApplicationAutoScaling\$1CassandraTable 服务相关角色信任以下服务来代入该角色：
+ `cassandra.application-autoscaling.amazonaws.com`

角色权限策略允许 Application Auto Scaling 在指定的 Amazon Keyspaces 资源上完成以下操作：
+ 操作：`arn:*:cassandra:*:*:/keyspace/system/table/*` 上的 `cassandra:Select`
+ 操作：资源 `arn:*:cassandra:*:*:/keyspace/system_schema/table/*` 上的 `cassandra:Select`
+ 操作：资源 `arn:*:cassandra:*:*:/keyspace/system_schema_mcs/table/*` 上的 `cassandra:Select`
+ 操作：资源 `arn:*:cassandra:*:*:"*"` 上的 `cassandra:Alter`

## 为 Amazon Keyspaces 创建服务相关角色
<a name="create-service-linked-role-app-auto-scaling"></a>

您无需手动为 Amazon Keyspaces 自动扩展创建服务相关角色。当您使用 AWS 管理控制台、CQL、或 AWS API 在表上启用 Amazon Keyspaces 自动扩展时，Application Auto Scaling 会为您创建服务相关角色。 AWS CLI

如果您删除该服务关联角色，然后需要再次创建，您可以使用相同流程在账户中重新创建此角色。当为表启用 Amazon Keyspaces 自动扩缩时，Application Auto Scaling 会再次为您创建服务相关角色。

**重要**  
 如果您在其他使用此角色支持的功能的服务中完成某个操作，此服务关联角色可以出现在您的账户中。要了解更多信息，请参阅 “[我的” 中出现了一个新角色 AWS 账户](https://docs.aws.amazon.com/IAM/latest/UserGuide/troubleshoot_roles.html#troubleshoot_roles_new-role-appeared)。

## 为 Amazon Keyspaces 编辑服务相关角色
<a name="edit-service-linked-role-app-auto-scaling"></a>

Amazon Keyspaces 不允许您编辑 AWSServiceRoleForApplicationAutoScaling\$1CassandraTable 服务相关角色。创建服务关联角色后，您将无法更改角色的名称，因为可能有多种实体引用该角色。但是可以使用 IAM 编辑角色描述。有关更多信息，请参阅《IAM 用户指南》**中的[编辑服务关联角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#edit-service-linked-role)。

## 删除适用于 Amazon Keyspaces 的服务相关角色
<a name="delete-service-linked-role-app-auto-scaling"></a>

如果您不再需要使用某个需要服务相关角色的特征或服务，我们建议您删除该角色。这样您就没有未被主动监控或维护的未使用实体。但是，必须先禁用账户中所有表的自动缩放功能， AWS 区域 然后才能手动删除服务相关角色。要对 Amazon Keyspaces 表禁用自动扩缩，请参阅[为表关闭 Amazon Keyspaces 自动扩缩](autoscaling.turnoff.md)。

**注意**  
如果在您尝试修改资源时 Amazon Keyspaces 自动扩展使用该角色，则取消注册可能会失败。如果发生这种情况，请等待几分钟后重试。

**使用 IAM 手动删除服务关联角色**

使用 IAM 控制台 AWS CLI、或 AWS API 删除 AWSServiceRoleForApplicationAutoScaling\$1CassandraTable 服务相关角色。有关更多信息，请参见《IAM 用户指南》**中的[删除服务相关角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#delete-service-linked-role)。

**注意**  
要删除 Amazon Keyspaces 自动扩展所使用的服务相关角色，您必须首先禁用账户中所有表的自动扩展。

## Amazon Keyspaces 服务相关角色支持的区域
<a name="slr-regions-app-auto-scaling"></a>

Amazon Keyspaces 支持在该服务可用的所有区域中使用服务相关角色。有关更多信息，请参阅 [Amazon Keyspaces 服务端点](https://docs.aws.amazon.com/keyspaces/latest/devguide/programmatic.endpoints.html)。

# 使用角色进行 Amazon Keyspaces 多区域复制
<a name="using-service-linked-roles-multi-region-replication"></a>

[Amazon Keyspaces（适用于 Apache Cassandra）使用 AWS Identity and Access Management (IAM) 服务相关角色。](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)服务相关角色是一种独特类型的 IAM 角色，它与 Amazon Keyspaces 直接相关。服务相关角色由 Amazon Keyspaces 预定义，包括该服务代表您调用 AWS 其他服务所需的所有权限。

服务相关角色可让您更轻松地设置 Amazon Keyspaces，因为您不必手动添加必要的权限。Amazon Keyspaces 定义其服务相关角色的权限，除非另外定义，否则只有 Amazon Keyspaces 可以代入该角色。定义的权限包括信任策略和权限策略，而且权限策略不能附加到任何其它 IAM 实体。

只有在首先删除服务相关角色的相关资源后，才能删除该角色。这将保护您的 Amazon Keyspaces 资源，因为您不会无意中删除对资源的访问权限。

## Amazon Keyspaces 的服务相关角色权限
<a name="service-linked-role-permissions-multi-region-replication"></a>

Amazon Keyspaces 使用名为的服务相关角色来**AWSServiceRoleForAmazonKeyspacesReplication**允许 Amazon Keyspaces 代表您 AWS 区域 向密钥空间添加新内容，并将表及其所有数据和设置复制到新区域。该角色还允许 Amazon Keyspaces 代表您复制对所有区域中表的写入操作。

 AWSServiceRoleForAmazonKeyspacesReplication 服务相关角色信任以下服务来代入该角色：
+ `replication.cassandra.amazonaws.com`

名为的角色权限策略 KeyspacesReplicationServiceRolePolicy 允许 Amazon Keyspaces 完成以下操作：
+ 操作：`cassandra:Select`
+ 操作：`cassandra:SelectMultiRegionResource`
+ 操作：`cassandra:Modify`
+ 操作：`cassandra:ModifyMultiRegionResource`
+ 操作：`cassandra:AlterMultiRegionResource`
+ 操作：`application-autoscaling:RegisterScalableTarget`— Amazon Keyspaces 在启用自动扩展的预配置模式下向单个区域表添加副本时，将使用应用程序的自动扩展权限。
+ 操作：`application-autoscaling:DeregisterScalableTarget`
+ 操作：`application-autoscaling:DescribeScalableTargets`
+ 操作：`application-autoscaling:PutScalingPolicy`
+ 操作：`application-autoscaling:DescribeScalingPolicies`
+ 操作：`cassandra:Alter`
+ 操作：`cloudwatch:DeleteAlarms`
+ 操作：`cloudwatch:DescribeAlarms`
+ 操作：`cloudwatch:PutMetricAlarm`

尽管 Amazon Keyspaces 服务相关角色 AWSServiceRoleForAmazonKeyspacesReplication 为策略中指定的亚马逊资源名称 (ARN) “arn: \$1” 提供了权限：“操作：”，但亚马逊密钥空间会提供您账户的 ARN。

创建服务相关角色的权限包含 AWSServiceRoleForAmazonKeyspacesReplication 在`AmazonKeyspacesFullAccess`托管策略中。有关更多信息，请参阅 [AWS 托管策略： AmazonKeyspacesFullAccess](security-iam-awsmanpol.md#security-iam-awsmanpol-AmazonKeyspacesFullAccess)。

您必须配置使用户、组或角色能够创建、编辑或删除服务相关角色的权限。有关更多信息，请参阅*《IAM 用户指南》*中的[服务相关角色权限](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#service-linked-role-permissions)。

## 为 Amazon Keyspaces 创建服务相关角色
<a name="create-service-linked-role-multi-region-replication"></a>

您不能手动创建服务相关角色。当您在、或 AWS API 中创建多区域密钥空间时 AWS 管理控制台，Amazon Keyspaces 会为您创建服务相关角色。 AWS CLI

如果您删除该服务关联角色，然后需要再次创建，您可以使用相同流程在账户中重新创建此角色。当您创建多区域键空间时，Amazon Keyspaces 将再次为您创建服务相关角色。

## 为 Amazon Keyspaces 编辑服务相关角色
<a name="edit-service-linked-role-multi-region-replication"></a>

Amazon Keyspaces 不允许您编辑 AWSServiceRoleForAmazonKeyspacesReplication 服务相关角色。创建服务关联角色后，您将无法更改角色的名称，因为可能有多种实体引用该角色。但是可以使用 IAM 编辑角色描述。有关更多信息，请参阅《IAM 用户指南》**中的[编辑服务关联角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#edit-service-linked-role)。

## 删除适用于 Amazon Keyspaces 的服务相关角色
<a name="delete-service-linked-role-multi-region-replication"></a>

如果不再需要使用某个需要服务关联角色的功能或服务，我们建议您删除该角色。这样就没有未被主动监控或维护的未使用实体。但是，必须先删除账户中的所有多区域密钥空间， AWS 区域 然后才能手动删除服务相关角色。

### 清除服务相关角色
<a name="service-linked-role-review-before-delete-multi-region-replication"></a>

必须先删除服务相关角色使用的多区域键空间和表，然后才能使用 IAM 删除该角色。

**注意**  
如果在您试图删除资源时，Amazon Keyspaces 服务正在使用该角色，则删除操作可能会失败。如果发生这种情况，请等待几分钟后重试。

**删除 AWSServiceRoleForAmazonKeyspacesReplication （控制台）使用的 Amazon Keyspaces 资源**

1. [登录并在家中打开 Amazon Keyspaces 控制台。 AWS 管理控制台 https://console.aws.amazon.com/keyspaces/](https://console.aws.amazon.com/keyspaces/home)

1. 从左侧面板中选择 **Keyspaces**。

1. 从列表中选择所有多区域键空间。

1. 选择**删除**确认删除操作，然后选择**删除键空间**。

您也可以使用以下任何一种方法以编程方式删除多区域键空间。
+ Cassandra 查询语言 (CQL) [DROP KEYSPACE](cql.ddl.keyspace.md#cql.ddl.keyspace.drop) 语句。
+ C [LI 的删除密钥空间](https://docs.aws.amazon.com/cli/latest/reference/keyspaces/delete-keyspace.html)操作。 AWS 
+ Amazon Keyspaces API 的[DeleteKeyspace](https://docs.aws.amazon.com/keyspaces/latest/APIReference/API_DeleteKeyspace.html)操作。

### 手动删除服务相关角色
<a name="slr-manual-delete-multi-region-replication"></a>

使用 IAM 控制台 AWS CLI、或 AWS API 删除 AWSServiceRoleForAmazonKeyspacesReplication服务相关角色。有关更多信息，请参阅《IAM 用户指南》**中的[删除服务关联角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#delete-service-linked-role)。

## Amazon Keyspaces 服务相关角色支持的区域
<a name="slr-regions-multi-region-replication"></a>

Amazon Keyspaces 并非在提供该服务的每个区域中都支持使用服务相关角色。您可以在以下区域使用该 AWSServiceRoleForAmazonKeyspacesReplication 角色。


****  

|  区域名称 | 区域标识 | Amazon Keyspaces 支持 | 
| --- | --- | --- | 
| 美国东部（弗吉尼亚州北部） | us-east-1 | 是 | 
| 美国东部（俄亥俄州） | us-east-2 | 是 | 
| 美国西部（北加利福尼亚） | us-west-1 | 是 | 
| 美国西部（俄勒冈州） | us-west-2 | 是 | 
| 亚太地区（孟买） | ap-south-1 | 是 | 
| 亚太地区（大阪） | ap-northeast-3 | 是 | 
| 亚太地区（首尔） | ap-northeast-2 | 是 | 
| 亚太地区（新加坡） | ap-southeast-1 | 是 | 
| 亚太地区（悉尼） | ap-southeast-2 | 是 | 
| 亚太地区（东京） | ap-northeast-1 | 是 | 
| 加拿大（中部） | ca-central-1 | 是 | 
| 欧洲地区（法兰克福） | eu-central-1 | 是 | 
| 欧洲地区（爱尔兰） | eu-west-1 | 是 | 
| 欧洲地区（伦敦） | eu-west-2 | 是 | 
| 欧洲地区（巴黎） | eu-west-3 | 是 | 
| 非洲（开普敦） | af-south-1 | 是 | 
| 南美洲（圣保罗） | sa-east-1 | 是 | 
| AWS GovCloud （美国东部） | us-gov-east-1 | 否 | 
| AWS GovCloud （美国西部） | us-gov-west-1 | 否 | 

# 在 Amazon Keyspaces CDC 直播中使用角色
<a name="using-service-linked-roles-CDC-streams"></a>

[Amazon Keyspaces（适用于 Apache Cassandra）使用 AWS Identity and Access Management (IAM) 服务相关角色。](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts.html#iam-term-service-linked-role)服务相关角色是一种独特类型的 IAM 角色，它与 Amazon Keyspaces 直接相关。服务相关角色由 Amazon Keyspaces 预定义，包括该服务代表您调用 AWS 其他服务所需的所有权限。

服务相关角色可让您更轻松地设置 Amazon Keyspaces，因为您不必手动添加必要的权限。Amazon Keyspaces 定义其服务相关角色的权限，除非另外定义，否则只有 Amazon Keyspaces 可以代入该角色。定义的权限包括信任策略和权限策略，而且权限策略不能附加到任何其它 IAM 实体。

您无法删除服务相关角色。

## Amazon Keyspaces 的服务相关角色权限
<a name="service-linked-role-permissions-CDC-streams"></a>

Amazon Keyspaces 使用名为 **AWSServiceRoleForAmazonKeyspacesCDC** 的服务相关角色来允许 Amazon Keyspaces CDC 直播代表您向您的 CloudWatch 账户发布指标。

 AWSServiceRoleForAmazonKeyspacesCDC 服务相关角色信任以下服务来代替该角色：
+ `cassandra-streams.amazonaws.com`

名为 [Keyspaces 的角色权限策略允许 CDCService RolePolicy](https://docs.aws.amazon.com/aws-managed-policy/latest/reference/KeyspacesCDCServiceRolePolicy.html) Amazon Keyspaces 对命名空间中的资源完成以下操作： CloudWatch `AWS/Cassandra`
+ 操作：`*` 上的 `cloudwatch:PutMetricData`

   AWSServiceRoleForAmazonKeyspacesCDC对符合以下条件的所有资源提供权限:操作:PutMetricData cloudwatch:`"cloudwatch:namespace": "AWS/Cassandra"`.

有关 Keyspaces 的更多信息 CDCServiceRolePolicy，请参阅。[AWS 托管策略：Keyspaces CDCService RolePolicy](security-iam-awsmanpol.md#security-iam-awsmanpol-KeyspacesCDCServiceRolePolicy)

要为自动创建服务相关角色 CDC 的表启用 AWSService RoleForAmazonKeyspaces CDC 流，IAM 委托人需要以下权限。

```
{
    "Sid": "KeyspacesCDCServiceLinkedRole",
    "Effect": "Allow",
    "Action": "iam:CreateServiceLinkedRole",
    "Resource": "arn:aws:iam::*:role/aws-service-role/cassandra-streams.amazonaws.com/AWSServiceRoleForAmazonKeyspacesCDC",
    "Condition": {
    "StringLike": {
        "iam:AWSServiceName": "cassandra-streams.amazonaws.com"
    }
}
```

创建服务相关角色 AWSService RoleForAmazonKeyspaces CDC 的权限包含在`AmazonKeyspacesFullAccess`托管策略中。有关更多信息，请参阅 [AWS 托管策略： AmazonKeyspacesFullAccess](security-iam-awsmanpol.md#security-iam-awsmanpol-AmazonKeyspacesFullAccess)。

## 为 Amazon Keyspaces 创建服务相关角色
<a name="create-service-linked-role-CDC-streams"></a>

您无需为 Amazon Keyspaces CDC 直播手动创建服务相关角色。当您使用 AWS 管理控制台、CQL、或 API 在表上启用 Amazon Keyspaces CDC 流时 AWS ，Amazon Keyspaces 会为您创建服务相关角色。 AWS CLI

如果您删除该服务关联角色，然后需要再次创建，您可以使用相同流程在账户中重新创建此角色。当您为表启用 Amazon Keyspaces CDC 流时，Amazon Keyspaces 会再次为您创建与服务相关的角色。

## 为 Amazon Keyspaces 编辑服务相关角色
<a name="edit-service-linked-role-CDC-streams"></a>

Amazon Keyspaces 不允许您编辑 AWSService RoleForAmazonKeyspaces CDC 服务相关角色。创建服务关联角色后，您将无法更改角色的名称，因为可能有多种实体引用该角色。但是可以使用 IAM 编辑角色描述。有关更多信息，请参阅《IAM 用户指南》**中的[编辑服务关联角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/using-service-linked-roles.html#edit-service-linked-role)。

## Amazon Keyspaces 服务相关角色支持的区域
<a name="slr-regions-CDC-streams"></a>

Amazon Keyspaces 支持在该服务可用的所有区域中使用服务相关角色。有关更多信息，请参阅 [AWS 区域和端点](https://docs.aws.amazon.com/general/latest/gr/rande.html)。