

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

# 计算资源 AMIs
<a name="compute_resource_AMIs"></a>

默认情况下， AWS Batch 托管计算环境使用最新经批准的 Amazon ECS 优化版 AMI 来处理计算资源。但是，您可能出于以下原因需要创建自己的 &AMI; 以用于托管计算环境和非托管计算环境：如果您需要以下任何一项，我们建议您创建自己的 AMI：
+ 增加 AMI 根卷或数据卷的存储大小。
+ 为支持的 Amazon EC2 实例类型添加实例存储卷。
+ 自定义 Amazon ECS 容器代理。
+ 自定义 Docker
+ 配置 GPU 工作负载 AMI，它允许容器访问支持的 Amazon EC2 实例类型上的 GPU 硬件

**注意**  
创建计算环境后， AWS Batch 不会在计算环境 AMIs 中升级。 AWS Batch 当有更新版本的 AMIs Amazon ECS 优化的 AMI 可用时，也不会在您的计算环境中更新。您需要管理客户操作系统。其中包括任何更新和安全补丁。您还负责为在计算资源上安装的任何其他应用程序软件或实用程序。要将新的 AMI 用于您的 AWS Batch 任务，请执行以下操作：  
使用新的 AMI 创建新计算环境。
将计算环境添加到现有作业队列。
从作业队列中删除早期的计算环境。
删除早期的计算环境。
2022 年 4 月， AWS Batch 增加了对更新计算环境的增强支持。有关更多信息，请参阅 [更新中的计算环境 AWS Batch](updating-compute-environments.md)。要使用计算环境的增强更新进行更新 AMIs，请遵循以下规则：  
要么不要设置服务角色 ([https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateComputeEnvironment.html#Batch-CreateComputeEnvironment-request-serviceRole](https://docs.aws.amazon.com/batch/latest/APIReference/API_CreateComputeEnvironment.html#Batch-CreateComputeEnvironment-request-serviceRole)) 参数，要么将其设置为**AWSServiceRoleForBatch**服务相关角色。
将分配策略（[https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResource.html#Batch-Type-ComputeResource-allocationStrategy](https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResource.html#Batch-Type-ComputeResource-allocationStrategy)）参数设置为 `BEST_FIT_PROGRESSIVE`、`SPOT_CAPACITY_OPTIMIZED` 或 `SPOT_PRICE_CAPACITY_OPTIMIZED`。
将更新到最新图像版本([https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-updateToLatestImageVersion](https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-updateToLatestImageVersion))参数设置为`true`。
请勿在[https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-imageId](https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-imageId)、[https://docs.aws.amazon.com/batch/latest/APIReference/API_Ec2Configuration.html#Batch-Type-Ec2Configuration-imageIdOverride](https://docs.aws.amazon.com/batch/latest/APIReference/API_Ec2Configuration.html#Batch-Type-Ec2Configuration-imageIdOverride)（在[https://docs.aws.amazon.com/batch/latest/APIReference/API_Ec2Configuration.html](https://docs.aws.amazon.com/batch/latest/APIReference/API_Ec2Configuration.html)）或启动模板 ([https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-launchTemplate](https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-launchTemplate)) 中指定 AMI ID。如果您不指定 AMI ID，请 AWS Batch 选择在启动基础设施更新时 AWS Batch 支持的最新 Amazon ECS 优化的 AMI。或者，您可以指定 `imageIdOverride` 参数，而不是 `imageId`。或者，也可以指定由 `LaunchTemplate` 属性标识的启动模板。更改这些属性中的任何一个都将启动基础架构更新。如果在启动模板中指定了 AMI ID，则不能通过在 `imageId` 或 `imageIdOverride` 参数中指定 AMI ID 来替换它。AMI ID 只能通过指定不同的启动模板进行替换。如果启动模板版本设置为 `$Default` 或 `$Latest`，则可以通过为启动模板设置新的默认版本（如果 `$Default`）或向启动模板添加新版本（如果 `$Latest`）来替换 AMI ID。
如果遵循这些规则，触发基础设施更新的任何更新都将导致重新选择 AMI ID。如果启动模板 ([https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-launchTemplate](https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-launchTemplate)) 中的[https://docs.aws.amazon.com/batch/latest/APIReference/API_LaunchTemplateSpecification.html#Batch-Type-LaunchTemplateSpecification-version](https://docs.aws.amazon.com/batch/latest/APIReference/API_LaunchTemplateSpecification.html#Batch-Type-LaunchTemplateSpecification-version)设置设置为`$Latest`或`$Default`，则在基础架构更新时会评估启动模板的最新版本或默认版本，即使[https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-launchTemplate](https://docs.aws.amazon.com/batch/latest/APIReference/API_ComputeResourceUpdate.html#Batch-Type-ComputeResourceUpdate-launchTemplate)未更新。

**Topics**
+ [计算资源 &AMI; 规范](batch-ami-spec.md)
+ [AMI 选择顺序](ami-selection-order.md)
+ [在计算环境中管理 AMI 版本](managing-ami-versions.md)
+ [教程：创建计算资源 AMI](create-batch-ami.md)
+ [使用 GPU 工作负载 AMI](batch-gpu-ami.md)
+ [Amazon Linux 弃用](al1-ami-deprecation.md)
+ [Amazon EKS Amazon Linux 2 AMI 弃用](eks-al2-ami-deprecation.md)
+ [Amazon ECS Amazon Linux 2 AMI 弃用](ecs-al2-ami-deprecation.md)