

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

# 参考：Amazon EC2 启动模板示例
<a name="launch-template-examples"></a>

以下是 MIME 分段文件的示例，您可以用它来创建您自己的模板。

**Topics**
+ [示例：挂载现有 Amazon EFS 文件系统](#example-mount-an-existing-amazon-efs-file-system)
+ [示例：覆盖默认 Amazon ECS 容器代理配置](#example-override-default-amazon-ecs-container-agent-configuration)
+ [示例：挂载现有的 Amazon f FSx or Lustre 文件系统](#example-mount-an-existing-amazon-fsx-for-lustre-file-system)

## 示例：挂载现有 Amazon EFS 文件系统
<a name="example-mount-an-existing-amazon-efs-file-system"></a>

**Example**  
此示例 MIME 分段文件将配置计算资源以安装 `amazon-efs-utils` 程序包并在 `/mnt/efs` 处装载现有 Amazon EFS 文件系统。  

```
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/cloud-config; charset="us-ascii"

packages:
- amazon-efs-utils

runcmd:
- file_system_id_01=fs-abcdef123
- efs_directory=/mnt/efs

- mkdir -p ${efs_directory}
- echo "${file_system_id_01}:/ ${efs_directory} efs tls,_netdev" >> /etc/fstab
- mount -a -t efs defaults

--==MYBOUNDARY==--
```

## 示例：覆盖默认 Amazon ECS 容器代理配置
<a name="example-override-default-amazon-ecs-container-agent-configuration"></a>

**Example**  
此示例 MIME 分段文件将覆盖计算资源的默认 Docker 映像清除设置。  

```
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/x-shellscript; charset="us-ascii"

#!/bin/bash
echo ECS_IMAGE_CLEANUP_INTERVAL=60m >> /etc/ecs/ecs.config
echo ECS_IMAGE_MINIMUM_CLEANUP_AGE=60m >> /etc/ecs/ecs.config

--==MYBOUNDARY==--
```

## 示例：挂载现有的 Amazon f FSx or Lustre 文件系统
<a name="example-mount-an-existing-amazon-fsx-for-lustre-file-system"></a>

**Example**  
此示例 MIME 多部分文件将计算资源配置为从 Extras Library 安装`lustre2.10`软件包，并将现有 FSx 的 For Lustre 文件系统挂载到`/scratch`且挂载名称为。`fsx`此示例是 Amazon Linux 2 的示例。有关其他 Linux 发行版的安装说明，请参阅 *Amazon FSx for Lustre 用户指南中的安装 Lustre* [客户端](https://docs.aws.amazon.com/fsx/latest/LustreGuide/install-lustre-client.html)。有关更多信息，请参阅 [Amazon FSx for *Lustre 用户指南中的自动挂载您的亚马逊 FSx *文件系统](https://docs.aws.amazon.com/fsx/latest/LustreGuide/mount-fs-auto-mount-onreboot.html)。  

```
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="==MYBOUNDARY=="

--==MYBOUNDARY==
Content-Type: text/cloud-config; charset="us-ascii"

runcmd:
- file_system_id_01=fs-0abcdef1234567890
- region=us-east-2
- fsx_directory=/scratch
- amazon-linux-extras install -y lustre2.10
- mkdir -p ${fsx_directory}
- mount -t lustre ${file_system_id_01}.fsx.${region}.amazonaws.com@tcp:fsx ${fsx_directory}

--==MYBOUNDARY==--
```
在容器属性的 [volumes](https://docs.aws.amazon.com/batch/latest/APIReference/API_ContainerProperties.html#Batch-Type-ContainerProperties-volumes) 和 [mountPoints](https://docs.aws.amazon.com/batch/latest/APIReference/API_ContainerProperties.html#Batch-Type-ContainerProperties-mountPoints) 成员中，装载点必须映射到容器中。  

```
{
    "volumes": [
        {
            "host": {
                "sourcePath": "/scratch"
            },
            "name": "Scratch"
        }
    ],
    "mountPoints": [
        {
            "containerPath": "/scratch",
            "sourceVolume": "Scratch"
        }
    ],
}
```