

# 排除 Amazon S3 存储类
<a name="aws-glue-programming-etl-storage-classes"></a>

如果您要运行从 Amazon Simple Storage Service（Amazon S3）读取文件或分区的 Amazon Glue ETL 任务，则可以排除某些 Amazon S3 存储类类型。

Amazon S3 中提供以下存储类：
+ `STANDARD` – 用于频繁访问数据的通用存储。
+ `INTELLIGENT_TIERING` – 用于具有未知或访问模式不断变化的数据。
+ `STANDARD_IA` 和 `ONEZONE_IA` – 用于长期存在但不常访问的数据。
+ `GLACIER`、`DEEP_ARCHIVE` 和 `REDUCED_REDUNDANCY` – 用于长期归档和数字化保存。

有关更多信息，请参阅《Amazon S3 开发人员指南》**中的 [Amazon S3 存储类](https://docs.amazonaws.cn/AmazonS3/latest/userguide/storage-class-intro.html)。

本节中的示例向您展示了如何排除 `GLACIER` 和 `DEEP_ARCHIVE` 存储类。这些类允许您列出文件，但除非文件已还原，否则它们不会让您读取文件。（有关更多信息，请参阅《Amazon S3 开发人员指南》**中的[还原存档对象](https://docs.amazonaws.cn/AmazonS3/latest/dev/restoring-objects.html)。

通过使用存储类排除，您可以确保您的 Amazon Glue 作业可以在具有跨这些存储类层的分区的表上工作。如果没有排除，则从这些层读取数据的作业将失败，并显示以下错误：AmazonS3Exception：操作对于此对象的存储类无效。

有多种不同的方法可供您在 Amazon Glue 中筛选 Amazon S3 存储类。

**Topics**
+ [创建动态帧时排除 Amazon S3 存储类](#aws-glue-programming-etl-storage-classes-dynamic-frame)
+ [在数据目录表上排除 Amazon S3 存储类](#aws-glue-programming-etl-storage-classes-table)

## 创建动态帧时排除 Amazon S3 存储类
<a name="aws-glue-programming-etl-storage-classes-dynamic-frame"></a>

要在创建动态帧时排除 Amazon S3 存储类，请使用 `additionalOptions` 中的 `excludeStorageClasses`。 Amazon Glue 会自动使用自己的 Amazon S3 `Lister` 实施列出和排除与指定存储类对应的文件。

以下 Python 和 Scala 示例显示了在创建动态帧时如何排除 `GLACIER` 和 `DEEP_ARCHIVE` 存储类。

Python 示例：

```
glueContext.create_dynamic_frame.from_catalog(
    database = "my_database",
    tableName = "my_table_name",
    redshift_tmp_dir = "",
    transformation_ctx = "my_transformation_context",
    additional_options = {
        "excludeStorageClasses" : ["GLACIER", "DEEP_ARCHIVE"]
    }
)
```

Scala 示例：

```
val* *df = glueContext.getCatalogSource(
    nameSpace, tableName, "", "my_transformation_context",  
    additionalOptions = JsonOptions(
        Map("excludeStorageClasses" -> List("GLACIER", "DEEP_ARCHIVE"))
    )
).getDynamicFrame()
```

## 在数据目录表上排除 Amazon S3 存储类
<a name="aws-glue-programming-etl-storage-classes-table"></a>

您可以将 Amazon Glue ETL 任务使用的存储类排除指定为 Amazon Glue 数据目录中的表参数。您可以使用 Amazon Command Line Interface (Amazon CLI) 或以编程方式使用 API 在 `CreateTable` 操作中包含此参数。有关更多信息，请参阅 [Table 结构](https://docs.amazonaws.cn/glue/latest/dg/aws-glue-api-catalog-tables.html#aws-glue-api-catalog-tables-Table)和 [CreateTable](https://docs.amazonaws.cn/glue/latest/webapi/API_CreateTable.html)。

您还可以在 Amazon Glue 控制台上指定排除的存储类。

**排除 Amazon S3 存储类（控制台）**

1. 登录 Amazon Web Services 管理控制台，然后打开 Amazon Glue 控制台，网址为：[https://console.aws.amazon.com/glue/](https://console.amazonaws.cn/glue/)。

1. 在左侧的导航窗格中，选择 **Tables (表)**。

1. 选择列表中的表名称，然后选择 **Edit table (编辑表)**。

1. 在 **Table properties (表属性)** 中，添加 **excludeStorageClasses** 作为键，添加 **[\$1"GLACIER\$1",\$1"DEEP\$1ARCHIVE\$1"]** 作为值。

1. 选择**应用**。