

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

# 参考：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)
+ [示例：挂载现有的适用于 Lustre 的 Amazon FSx 文件系统](#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==--
```

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

**Example**  
此示例 MIME 分段文件将配置计算资源，以从 Extras Library 安装 `lustre2.10` 程序包，并在 `/scratch` 处以 `fsx` 的装载名装载现有 FSx for Lustre 文件系统。此示例是 Amazon Linux 2 的示例。有关其他 Linux 发行版的安装说明，请参阅*适用于 Lustre 的 Amazon FSx 用户指南*中的[安装 Lustre 客户端](https://docs.aws.amazon.com/fsx/latest/LustreGuide/install-lustre-client.html)。有关更多信息，请参阅*适用于 Lustre 的 Amazon FSx 用户指南*中的[自动挂载 Amazon 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}}"
        }
    ],
}
```