

# 创建批量操作作业以更新对象加密
<a name="batch-ops-update"></a>

要使用单个请求更新多个 Amazon S3 对象的服务器端加密类型，您可以使用 S3 批量操作。可以通过 Amazon S3 控制台、AWS Command Line Interface（AWS CLI）、AWS SDK 或 Amazon S3 REST API 使用 S3 批量操作。

## 使用 AWS CLI
<a name="batch-ops-example-cli-update-job"></a>

要运行以下命令，您必须安装并配置 AWS CLI。如果未安装 AWS CLI，请参阅《AWS Command Line Interface 用户指南》**中的[安装或更新最新版本的 AWS CLI](https://docs.aws.amazon.com//cli/latest/userguide/getting-started-install.html)。

或者，可以从控制台中使用 AWS CloudShell 运行 AWS CLI 命令。AWS CloudShell 是一个基于浏览器、预先经过身份验证的 Shell，您可以直接从 AWS 管理控制台中启动它。有关更多信息，请参阅《AWS CloudShell 用户指南》**中的 [What is CloudShell?](https://docs.aws.amazon.com//cloudshell/latest/userguide/welcome.html) 和 [Getting started with AWS CloudShell](https://docs.aws.amazon.com//cloudshell/latest/userguide/getting-started.html)。

**Example 1 – 创建一个批量操作作业，该作业将加密的对象从一个 AWS KMS key更新为另一个 KMS 密钥**  
以下示例说明如何创建一个 S3 批量操作作业，该作业更新通用存储桶中多个对象的加密设置。此命令创建一个作业，该作业将使用一个 AWS Key Management Service（AWS KMS）密钥加密的对象更改为使用不同的 KMS 密钥。此作业还会生成和保存受影响对象的清单，并创建结果报告。要使用此命令，请将 `{{user input placeholders}}` 替换为您自己的信息。  

```
aws s3control create-job --account-id {{account-id}} \
--no-confirmation-required \
--operation '{"S3UpdateObjectEncryption": {  "ObjectEncryption": { "SSEKMS": { "KMSKeyArn": "{{KMS-key-ARN-to-apply}}", "BucketKeyEnabled": false  }  }  } }' \
--report '{ "Enabled": true, "Bucket": "{{report-bucket-ARN}}",  "Format": "Report_CSV_20180820", "Prefix": "report", "ReportScope": "AllTasks" }' \
--manifest-generator '{ "S3JobManifestGenerator": { "ExpectedBucketOwner": "{{account-id}}", "SourceBucket": "{{source-bucket-ARN}}", "EnableManifestOutput": true, "ManifestOutputLocation": { "Bucket": "{{manifest-bucket-ARN}}", "ManifestFormat": "S3InventoryReport_CSV_20211130", "ManifestPrefix": "{{manifest-prefix}}" }, "Filter": {   "MatchAnyObjectEncryption": [{ "SSEKMS": { "KmsKeyArn": "{{kms-key-ARN-to-match}}" } }] } } }' \
--priority 1 \
--role-arn {{batch-operations-role-ARN}}
```
为了获得最佳性能，我们建议将 `KmsKeyArn` 筛选条件与其它对象元数据筛选条件（例如 `MatchAnyPrefix`、`CreatedAfter` 或 `MatchAnyStorageClass`）结合使用。

**Example 2 – 创建一个批量操作作业，该作业将 SSE-S3 加密的对象更新为 SSE-KMS**  
以下示例说明如何创建一个 S3 批量操作作业，该作业更新通用存储桶中多个对象的加密设置。此命令创建一个作业，该作业将使用具有 Amazon S3 托管式密钥的服务器端加密（SSE-S3）加密的对象更改为使用具有 AWS Key Management Service（AWS KMS）密钥的服务器端加密（SSE-KMS）。此作业还会生成和保存受影响对象的清单，并创建结果报告。要使用此命令，请将 `{{user input placeholders}}` 替换为您自己的信息。  

```
aws s3control create-job --account-id {{account-id}} \
--no-confirmation-required \
--operation '{"S3UpdateObjectEncryption": {  "ObjectEncryption": { "SSEKMS": { "KMSKeyArn": "{{KMS-key-ARN-to-apply}}", "BucketKeyEnabled": false  }  }  } }' \
--report '{ "Enabled": true, "Bucket": "{{report-bucket-ARN}}",  "Format": "Report_CSV_20180820", "Prefix": "report", "ReportScope": "AllTasks" }' \
--manifest-generator '{ "S3JobManifestGenerator": { "ExpectedBucketOwner": "{{account-id}}", "SourceBucket": "{{source-bucket-ARN}}", "EnableManifestOutput": true, "ManifestOutputLocation": { "Bucket": "{{manifest-bucket-ARN}}", "ManifestFormat": "S3InventoryReport_CSV_20211130", "ManifestPrefix": "{{manifest-prefix}}" }, "Filter": {   "MatchAnyObjectEncryption": [{ "SSES3": {} }] } } }' \
--priority 1 \
--role-arn {{batch-operations-role-ARN}}
```
为了获得最佳性能，我们建议将 `KmsKeyArn` 筛选条件与其它对象元数据筛选条件（例如 `MatchAnyPrefix`、`CreatedAfter` 或 `MatchAnyStorageClass`）结合使用。