

# 设置、管理和编程访问
<a name="setting-up"></a>

如果您已注册 Amazon Web Services，则可以立即开始使用 Amazon Athena。如果您尚未注册 AWS 或需要入门帮助，请确保完成以下任务。

## 注册 AWS 账户
<a name="sign-up-for-aws"></a>

如果您还没有，AWS 账户请完成以下步骤来创建一个。

**注册 AWS 账户**

1. 打开 [https://portal.aws.amazon.com/billing/signup](https://portal.aws.amazon.com/billing/signup)。

1. 按照屏幕上的说明操作。

   在注册时，将接到电话或收到短信，要求使用电话键盘输入一个验证码。

   当您注册 AWS 账户 时，系统将会创建一个。*AWS 账户根用户*根用户有权访问该账户中的所有 AWS 服务 和资源。作为最佳安全实践，请为用户分配管理访问权限，并且只使用根用户来执行[需要根用户访问权限的任务](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_root-user.html#root-user-tasks)。

注册过程完成后，AWS 会向您发送一封确认电子邮件。在任何时候，您都可以通过转至 [https://aws.amazon.com/](https://aws.amazon.com/) 并选择**我的账户**来查看当前的账户活动并管理您的账户。

## 创建具有管理访问权限的用户
<a name="create-an-admin"></a>

注册 AWS 账户 后，请保护好您的，AWS 账户根用户启用，AWS IAM Identity Center并创建一个管理用户，以避免使用根用户执行日常任务。

**保护您的 AWS 账户根用户**

1.  选择**根用户**并输入您的 AWS 账户 电子邮件地址，以账户拥有者身份登录。[AWS 管理控制台](https://console.aws.amazon.com/)在下一页上，输入您的密码。

   要获取使用根用户登录方面的帮助，请参阅《AWS 登录 用户指南》**中的 [Signing in as the root user](https://docs.aws.amazon.com/signin/latest/userguide/console-sign-in-tutorials.html#introduction-to-root-user-sign-in-tutorial)。

1. 为您的根用户启用多重身份验证（MFA）。

   有关说明，请参阅《IAM 用户指南》**中的[为 AWS 账户 根用户启用虚拟 MFA 设备（控制台）](https://docs.aws.amazon.com/IAM/latest/UserGuide/enable-virt-mfa-for-root.html)。

**创建具有管理访问权限的用户**

1. 启用 IAM Identity Center。

   有关说明，请参阅**《AWS IAM Identity Center 用户指南》中的[启用 AWS IAM Identity Center](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-set-up-for-idc.html)。

1. 在 IAM Identity Center 中，为用户授予管理访问权限。

   有关如何使用 IAM Identity Center 目录 作为身份源的教程，请参阅**《AWS IAM Identity Center 用户指南》中的 [Configure user access with the default。IAM Identity Center 目录](https://docs.aws.amazon.com//singlesignon/latest/userguide/quick-start-default-idc.html)

**以具有管理访问权限的用户身份登录**
+ 要使用您的 IAM Identity Center 用户身份登录，请使用您在创建 IAM Identity Center 用户时发送到您的电子邮件地址的登录 URL。

  要获取使用 IAM Identity Center 用户登录方面的帮助，请参阅《AWS 登录 用户指南》**中的 [Signing in to the AWS access portal](https://docs.aws.amazon.com/signin/latest/userguide/iam-id-center-sign-in-tutorial.html)。

**将访问权限分配给其他用户**

1. 在 IAM Identity Center 中，创建一个权限集，该权限集遵循应用最低权限的最佳做法。

   有关说明，请参阅《AWS IAM Identity Center 用户指南》**中的 [Create a permission set](https://docs.aws.amazon.com//singlesignon/latest/userguide/get-started-create-a-permission-set.html)。

1. 将用户分配到一个组，然后为该组分配单点登录访问权限。

   有关说明，请参阅《AWS IAM Identity Center 用户指南》**中的 [Add groups](https://docs.aws.amazon.com//singlesignon/latest/userguide/addgroups.html)。

## 授权以编程方式访问
<a name="setting-up-grant-programmatic-access"></a>

如果用户需要在 AWS 管理控制台 之外与 AWS 交互，则需要编程式访问权限。授予编程式访问权限的方法取决于访问 AWS 的用户类型。

要向用户授予编程式访问权限，请选择以下选项之一。


****  

| 哪个用户需要编程式访问权限？ | 目的 | 方式 | 
| --- | --- | --- | 
| IAM | （推荐）使用控制台凭证作为临时凭证来签署向 AWS CLI、AWS SDK 或 AWS API 发出的编程请求。 |  按照您希望使用的界面的说明进行操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/setting-up.html)  | 
|  人力身份 （在 IAM Identity Center 中管理的用户）  | 使用临时凭证签署向 AWS CLI、AWS SDK 或 AWS API 发出的编程请求。 |  按照您希望使用的界面的说明进行操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/setting-up.html)  | 
| IAM | 使用临时凭证签署向 AWS CLI、AWS SDK 或 AWS API 发出的编程请求。 | 按照《IAM 用户指南》中[将临时凭证用于 AWS 资源](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html)中的说明进行操作。 | 
| IAM | （不推荐使用）使用长期凭证签署向 AWS CLI、AWS SDK 或 AWS API 发出的编程请求。 |  按照您希望使用的界面的说明进行操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/athena/latest/ug/setting-up.html)  | 

## 为 Athena 附加托管式策略
<a name="setting-up-attach-managed-policies-for-athena"></a>

Athena 托管策略授予 Athena 功能使用权限。您可以将这些托管策略附加到一个或多个 IAM 角色，用户可以担任这些角色以便使用 Athena。

 IAM [角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)是可在账户中创建的一种具有特定权限的 IAM 身份。IAM 角色类似于 IAM 用户，因为它是一个 AWS 身份，具有确定其在 AWS 中可执行和不可执行的操作的权限策略。但是，角色旨在让需要它的任何人代入，而不是唯一地与某个人员关联。此外，角色没有关联的标准长期凭证（如密码或访问密钥）。相反，当您代入角色时，它会为您提供角色会话的临时安全凭证。

有关角色的更多信息，请参阅《IAM 用户指南**》中的 [IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)和[创建 IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create.html)。

要创建向 Athena 授予访问权限的角色，您需要将 Athena 托管策略附加到该角色。Athena 有两个托管策略：`AmazonAthenaFullAccess` 和 `AWSQuicksightAthenaAccess`。这些策略向 Athena 授予查询 Amazon S3 的权限以及代表您将您的查询结果写入单独存储桶的权限。要查看适用于 Athena 的这些策略的内容，请参阅 [](security-iam-awsmanpol.md)。

有关向角色附加 Athena 托管策略的步骤，请遵循《IAM 用户指南**》中的[添加 IAM 身份权限（控制台）](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html#add-policies-console)进行操作，并将 `AmazonAthenaFullAccess` 和 `AWSQuicksightAthenaAccess` 托管策略添加到您创建的角色。

**注意**  
您可能需要额外的权限才能访问 Amazon S3 中的底层数据集。如果您不是账户拥有者或以其他方式限制了对某个存储桶的访问权限，请与存储桶拥有者联系以使用基于资源的存储桶策略授予访问权限，或与您的账户管理员联系以使用基于角色的策略授予访问权限。有关更多信息，请参阅 [控制从 Athena 对 Amazon S3 的访问](s3-permissions.md)。如果数据集或 Athena 查询结果是加密的，您可能需要额外的权限。有关更多信息，请参阅 [静态加密](encryption.md)。