

# 将 Amazon S3 Storage Lens 存储统计管理工具与 AWS Organizations 结合使用
<a name="storage_lens_with_organizations"></a>

Amazon S3 Storage Lens 存储统计管理工具是一项云存储分析功能，您可以使用它在整个组织范围内了解对象存储的使用情况和活动。您可以使用 S3 Storage Lens 存储统计管理工具指标生成摘要见解，例如，了解整个组织中有多少存储空间，或增长最快的桶和前缀是哪些。还可以使用 Amazon S3 Storage Lens 存储统计管理工具收集属于 AWS Organizations 层次结构一部分的所有 AWS 账户的存储指标和用量数据。为此，您必须使用 AWS Organizations，并且必须使用您的 AWS Organizations 管理账户启用 S3 Storage Lens 存储统计管理工具可信访问权限。

启用可信访问权限后，向组织中的账户添加委派管理员访问权限。委派管理员账户用于创建 S3 Storage Lens 存储统计管理工具配置和控制面板，以收集组织范围的存储指标和用户数据。有关启用可信访问权限的更多信息，请参阅《*AWS Organizations 用户指南*》中的 [Amazon S3 Storage Lens 存储统计管理工具和 AWS Organizations](https://docs.aws.amazon.com/organizations/latest/userguide/services-that-can-integrate-s3lens.html)。

**Topics**
+ [为 S3 Storage Lens 存储统计管理工具启用可信访问权限](storage_lens_with_organizations_enabling_trusted_access.md)
+ [为 S3 Storage Lens 存储统计管理工具禁用可信访问权限](storage_lens_with_organizations_disabling_trusted_access.md)
+ [为 S3 Storage Lens 存储统计管理工具注册委托管理员](storage_lens_with_organizations_registering_delegated_admins.md)
+ [为 S3 Storage Lens 存储统计管理工具取消注册委托管理员](storage_lens_with_organizations_deregistering_delegated_admins.md)

# 为 S3 Storage Lens 存储统计管理工具启用可信访问权限
<a name="storage_lens_with_organizations_enabling_trusted_access"></a>

通过启用可信访问权限，可让 Amazon S3 Storage Lens 存储统计管理工具通过 AWS Organizations API 操作访问 AWS Organizations 层次结构、成员资格和结构。然后，S3 Storage Lens 存储统计管理工具便成为整个组织结构的可信服务。

无论何时创建控制面板配置，S3 Storage Lens 存储统计管理工具都会在组织的管理或委托管理员账户中创建服务相关角色。服务相关角色向 S3 Storage Lens 存储统计管理工具授予执行以下操作的权限：
+ 描述组织
+ 列出账户
+ 验证组织的 AWS 服务访问权限列表
+ 为组织获取委托管理员



随后，S3 Storage Lens 存储统计管理工具可以确保它具有相应的访问权限，可收集组织中账户的跨账户指标。有关更多信息，请参阅[使用面向 Amazon S3 Storage Lens 存储统计管理工具的服务相关角色](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-service-linked-roles.html)。

启用可信访问权限后，您可以为组织中的账户分配委托管理员访问权限。当账户被标记为服务的委托管理员时，该账户将获得访问所有只读组织 API 操作的授权。此访问权限向委托管理员提供了对您组织成员和结构的可见性，以便他们也可以创建 S3 Storage Lens 存储统计管理工具控制面板。

**注意**  
只能由[管理账户](https://docs.aws.amazon.com/managedservices/latest/userguide/management-account.html)启用可信访问权限。
 只有管理账户和委托管理员才能为您的组织创建 S3 Storage Lens 存储统计管理工具控制面板或配置。

# 使用 S3 控制台
<a name="storage_lens_console_organizations_enabling_trusted_access"></a>

**使 S3 Storage Lens 存储统计管理工具拥有 AWS Organizations 可信访问权限**

1. 登录到 AWS 管理控制台，然后通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)。

1. 在左侧导航窗格中，导航到 **Storage Lens 存储统计管理工具**。

1. 选择 **AWS Organizations 设置**。将显示 **Storage Lens 存储统计管理工具的 AWS Organizations 访问权限**页面。

1. 在 **AWS Organizations 可信访问权限**下，选择**编辑**。

   将显示 **AWS Organizations 访问权限**页面。

1. 选择**启用**，以便为 S3 Storage Lens 存储统计管理工具控制面板启用可信访问权限。

1. 选择**保存更改**。

# 使用 AWS CLI
<a name="OrganizationsEnableTrustedAccessS3LensCLI"></a>

**Example**  
以下示例显示了如何在 AWS CLI 中为 S3 Storage Lens 存储统计管理工具启用 AWS Organizations 可信访问权限。  

```
aws organizations enable-aws-service-access --service-principal storage-lens.s3.amazonaws.com
```

# 使用适用于 Java 的 AWS SDK
<a name="OrganizationsEnableTrustedAccessS3LensJava"></a>

**Example – 使用适用于 Java 的 SDK 为 S3 Storage Lens 存储统计管理工具启用 AWS Organizations 可信访问权限**  
以下示例显示了如何在适用于 Java 的 SDK 中为 S3 Storage Lens 存储统计管理工具启用可信访问权限。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。  

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.organizations.AWSOrganizations;
import com.amazonaws.services.organizations.AWSOrganizationsClient;
import com.amazonaws.services.organizations.model.EnableAWSServiceAccessRequest;

public class EnableOrganizationsTrustedAccess {
	private static final String S3_STORAGE_LENS_SERVICE_PRINCIPAL = "storage-lens.s3.amazonaws.com";

	public static void main(String[] args) {
		try {
            AWSOrganizations organizationsClient = AWSOrganizationsClient.builder()
                .withCredentials(new ProfileCredentialsProvider())
                .withRegion(Regions.US_EAST_1)
                .build();

            organizationsClient.enableAWSServiceAccess(new EnableAWSServiceAccessRequest()
                .withServicePrincipal(S3_STORAGE_LENS_SERVICE_PRINCIPAL));
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but AWS Organizations couldn't process
            // it and returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // AWS Organizations couldn't be contacted for a response, or the client
            // couldn't parse the response from AWS Organizations.
            e.printStackTrace();
        }
	}
}
```

# 为 S3 Storage Lens 存储统计管理工具禁用可信访问权限
<a name="storage_lens_with_organizations_disabling_trusted_access"></a>

以委派管理员身份移除账户或禁用可信访问权限，会将账户拥有者的 S3 Storage Lens 存储统计管理工具控制面板指标限制为仅在账户级别起作用。然后，每个账户持有人所能看到的 S3 Storage Lens 存储统计管理工具的优势仅限于其账户的有限范围，而不是整个组织范围。

在 S3 Storage Lens 存储统计管理工具中禁用可信访问权限时，任何需要可信访问权限的控制面板都不再更新。所创建的任何组织控制面板也不再更新。相反，您只能查询 [S3 Storage Lens 存储统计管理工具控制面板的历史数据](https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage_lens_basics_metrics_recommendations.html#storage_lens_basics_data_queries)（当这些数据仍然可用时）。

**注意**  
禁用对 S3 Storage Lens 存储统计管理工具的可信访问还会自动阻止所有组织级控制面板收集和聚合存储指标。这是因为 S3 Storage Lens 存储统计管理工具不再对组织账户拥有可信访问权限。
管理账户和委派管理员账户仍可以查看任何禁用的控制面板的历史数据。这些账户还可以在历史数据仍可用时查询这些数据。

# 使用 S3 控制台
<a name="storage_lens_console_organizations_disabling_trusted_access"></a>

**为 S3 Storage Lens 存储统计管理工具禁用可信访问权限**

1. 登录到 AWS 管理控制台，然后通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)。

1. 在左侧导航窗格中，导航到 **Storage Lens 存储统计管理工具**。

1. 选择 **AWS Organizations 设置**。将显示 **Storage Lens 存储统计管理工具的 AWS Organizations 访问权限**页面。

1. 在 **AWS Organizations 可信访问权限**下，选择**编辑**。

   将显示 **AWS Organizations 访问权限**页面。

1. 选择**禁用**，以便为 S3 Storage Lens 存储统计管理工具控制面板禁用可信访问权限。

1. 选择**保存更改**。

# 使用 AWS CLI
<a name="OrganizationsDisableTrustedAccessS3LensCLI"></a>

**Example**  
以下示例使用 AWS CLI 为 S3 Storage Lens 存储统计管理工具禁用可信访问权限。  

```
aws organizations disable-aws-service-access --service-principal storage-lens.s3.amazonaws.com
```

# 使用适用于 Java 的 AWS SDK
<a name="OrganizationsDisableTrustedAccessS3LensJava"></a>

**Example – 为 S3 Storage Lens 存储统计管理工具禁用 AWS Organizations 可信访问权限**  
以下示例显示了如何在适用于 Java 的 SDK 中为 S3 Storage Lens 存储统计管理工具禁用 AWS Organizations 可信访问权限。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。  

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.organizations.AWSOrganizations;
import com.amazonaws.services.organizations.AWSOrganizationsClient;
import com.amazonaws.services.organizations.model.DisableAWSServiceAccessRequest;

public class DisableOrganizationsTrustedAccess {
	private static final String S3_STORAGE_LENS_SERVICE_PRINCIPAL = "storage-lens.s3.amazonaws.com";

	public static void main(String[] args) {
		try {
            AWSOrganizations organizationsClient = AWSOrganizationsClient.builder()
                .withCredentials(new ProfileCredentialsProvider())
                .withRegion(Regions.US_EAST_1)
                .build();

            // Make sure to remove any existing delegated administrator for S3 Storage Lens 
            // before disabling access; otherwise, the request will fail.
            organizationsClient.disableAWSServiceAccess(new DisableAWSServiceAccessRequest()
                .withServicePrincipal(S3_STORAGE_LENS_SERVICE_PRINCIPAL));
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but AWS Organizations couldn't process
            // it and returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // AWS Organizations couldn't be contacted for a response, or the client
            // couldn't parse the response from AWS Organizations.
            e.printStackTrace();
        }
	}
}
```

# 为 S3 Storage Lens 存储统计管理工具注册委托管理员
<a name="storage_lens_with_organizations_registering_delegated_admins"></a>

您可以使用组织的管理账户或委托管理员账户创建组织级控制面板。委托管理员账户允许除管理账户以外的其他账户创建组织级控制面板。只有组织的管理账户才能将其他账户注册为组织的委托管理员以及取消其注册。

启用可信访问权限后，可以通过 [management account](https://docs.aws.amazon.com/managedservices/latest/userguide/management-account.html)，使用 AWS Organizations REST API、AWS CLI 或 SDK 对组织中的账户注册委派管理员访问权限。（有关更多信息，请参阅《AWS Organizations API 参考》**中的 [https://docs.aws.amazon.com/organizations/latest/APIReference/API_RegisterDelegatedAdministrator.html](https://docs.aws.amazon.com/organizations/latest/APIReference/API_RegisterDelegatedAdministrator.html)。） 当账户注册为委派管理员后，该账户将获得访问所有只读 AWS Organizations API 操作的授权。这就提供了对您组织成员和结构的可见性，以便他们可以代表您创建 S3 Storage Lens 存储统计管理工具控制面板。

**注意**  
在使用 AWS Organizations REST API、AWS CLI 或 SDK 指定委托管理员之前，必须调用 [https://docs.aws.amazon.com/organizations/latest/APIReference/API_EnableAWSServiceAccess.html](https://docs.aws.amazon.com/organizations/latest/APIReference/API_EnableAWSServiceAccess.html) 操作。

# 使用 S3 控制台
<a name="storage_lens_console_organizations_registering_delegated_admins"></a>

**为 S3 Storage Lens 存储统计管理工具注册委托管理员**

1. 登录到 AWS 管理控制台，然后通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)。

1. 在左侧导航窗格中，导航到 **Storage Lens 存储统计管理工具**。

1.  选择 **AWS Organizations 设置**。

1. 在**委派管理员**下，选择**注册账户**。

1. 添加 AWS 账户 ID，以便将该账户注册为委派管理员。委派管理员可以为组织中的所有账户和存储创建组织级别控制面板。

1. 选择**注册账户**。

# 使用 AWS CLI
<a name="OrganizationsRegisterDelegatedAdministratorS3LensCLI"></a>

**Example**  
以下示例显示了如何使用 AWS CLI 为 S3 Storage Lens 存储统计管理工具注册组织委派管理员。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。  

```
aws organizations register-delegated-administrator --service-principal storage-lens.s3.amazonaws.com --account-id 111122223333
```

# 使用适用于 Java 的 AWS SDK
<a name="OrganizationsRegisterDelegatedAdministratorS3LensJava"></a>

**Example – 为 S3 Storage Lens 存储统计管理工具注册组织委派管理员**  
以下示例显示了如何在适用于 Java 的 SDK 中为 S3 Storage Lens 存储统计管理工具注册 AWS Organizations 委派管理员。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。  

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.organizations.AWSOrganizations;
import com.amazonaws.services.organizations.AWSOrganizationsClient;
import com.amazonaws.services.organizations.model.RegisterDelegatedAdministratorRequest;

public class RegisterOrganizationsDelegatedAdministrator {
	private static final String S3_STORAGE_LENS_SERVICE_PRINCIPAL = "storage-lens.s3.amazonaws.com";

	public static void main(String[] args) {
		try {
            String delegatedAdminAccountId = "111122223333"; // Account Id for the delegated administrator.
            AWSOrganizations organizationsClient = AWSOrganizationsClient.builder()
                .withCredentials(new ProfileCredentialsProvider())
                .withRegion(Regions.US_EAST_1)
                .build();

            organizationsClient.registerDelegatedAdministrator(new RegisterDelegatedAdministratorRequest()
                .withAccountId(delegatedAdminAccountId)
                .withServicePrincipal(S3_STORAGE_LENS_SERVICE_PRINCIPAL));
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but AWS Organizations couldn't process
            // it and returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // AWS Organizations couldn't be contacted for a response, or the client
            // couldn't parse the response from AWS Organizations.
            e.printStackTrace();
        }
	}
}
```

# 为 S3 Storage Lens 存储统计管理工具取消注册委托管理员
<a name="storage_lens_with_organizations_deregistering_delegated_admins"></a>

启用可信访问权限后，还可以对组织中的账户注销委派管理员访问权限。委派管理员账户可让除 [management account](https://docs.aws.amazon.com/managedservices/latest/userguide/management-account.html) 以外的其它账户创建组织级别控制面板。只有组织的管理账户才能以组织的委托管理员身份取消注册账户。

还可以通过管理账户，使用 AWS Organizations AWS 管理控制台、REST API、AWS CLI 或 AWS SDK 来注销委派管理员。有关更多信息，请参阅《AWS Organizations API Reference》**中的 [https://docs.aws.amazon.com/organizations/latest/APIReference/API_DeregisterDelegatedAdministrator.html](https://docs.aws.amazon.com/organizations/latest/APIReference/API_DeregisterDelegatedAdministrator.html)。

当账户被注销委派管理员时，该账户将失去对以下各项的访问权限：
+ 所有只读 AWS Organizations API 操作，这些操作可提供组织成员和结构的可见性。
+ 委派管理员创建的所有组织级别控制面板。取消注册委托管理员还会自动阻止该委托管理员创建的所有组织级控制面板聚合新的存储指标。
**注意**  
如果注销的委派管理员创建的已禁用控制面板的历史数据仍可供查询，则这些管理员仍然可以查看这些数据。

# 使用 S3 控制台
<a name="storage_lens_console_organizations_deregistering_delegated_admins"></a>

**为 S3 Storage Lens 存储统计管理工具注销委派管理员**

1. 登录到 AWS 管理控制台，然后通过以下网址打开 Amazon S3 控制台：[https://console.aws.amazon.com/s3/](https://console.aws.amazon.com/s3/)。

1. 在左侧导航窗格中，导航到 **Storage Lens 存储统计管理工具**。

1.  选择 **AWS Organizations 设置**。

1. 在**委派管理员**下，选择您希望注销的账户。

1. 选择**注销账户**。已注销的账户不再是委派管理员，且现在无法为组织中的所有账户和存储创建组织级别控制面板。

1. 选择**注册账户**。

# 使用 AWS CLI
<a name="OrganizationsDeregisterDelegatedAdministratorS3LensCLI"></a>

**Example**  
以下示例显示了如何使用 AWS CLI 为 S3 Storage Lens 存储统计管理工具注销组织委派管理员。要使用此示例，请将 `111122223333` 替换为您自己的 AWS 账户 ID。  

```
aws organizations deregister-delegated-administrator --service-principal storage-lens.s3.amazonaws.com --account-id 111122223333
```

# 使用适用于 Java 的 AWS SDK
<a name="OrganizationsDeregisterDelegatedAdministratorS3LensJava"></a>

**Example – 为 S3 Storage Lens 存储统计管理工具注销组织委派管理员**  
以下示例显示了如何使用适用于 Java 的 SDK 为 S3 Storage Lens 存储统计管理工具注销组织委派管理员。要使用此示例，请将 `user input placeholders` 替换为您自己的信息。  

```
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.organizations.AWSOrganizations;
import com.amazonaws.services.organizations.AWSOrganizationsClient;
import com.amazonaws.services.organizations.model.DeregisterDelegatedAdministratorRequest;

public class DeregisterOrganizationsDelegatedAdministrator {
	private static final String S3_STORAGE_LENS_SERVICE_PRINCIPAL = "storage-lens.s3.amazonaws.com";

	public static void main(String[] args) {
		try {
            String delegatedAdminAccountId = "111122223333"; // Account Id for the delegated administrator.
            AWSOrganizations organizationsClient = AWSOrganizationsClient.builder()
                .withCredentials(new ProfileCredentialsProvider())
                .withRegion(Regions.US_EAST_1)
                .build();

            organizationsClient.deregisterDelegatedAdministrator(new DeregisterDelegatedAdministratorRequest()
                .withAccountId(delegatedAdminAccountId)
                .withServicePrincipal(S3_STORAGE_LENS_SERVICE_PRINCIPAL));
        } catch (AmazonServiceException e) {
            // The call was transmitted successfully, but AWS Organizations couldn't process
            // it and returned an error response.
            e.printStackTrace();
        } catch (SdkClientException e) {
            // AWS Organizations couldn't be contacted for a response, or the client
            // couldn't parse the response from AWS Organizations.
            e.printStackTrace();
        }
	}
}
```