

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用任務附件來共用檔案
<a name="build-job-attachments"></a>

使用*任務附件*讓不在共用目錄中的檔案可供您的任務使用，如果輸出檔案未寫入共用目錄，則擷取輸出檔案。任務連接使用 Amazon S3 在主機之間傳輸檔案。檔案存放在 S3 儲存貯體中，如果檔案的內容未變更，則不需要上傳檔案。

在[服務受管機群](https://docs.aws.amazon.com/deadline-cloud/latest/userguide/smf-manage.html)上執行任務時，您必須使用任務附件，因為主機不會共用檔案系統位置。當任務的輸入或輸出檔案存放在共用網路檔案系統上時，例如當您的任務[套件](https://docs.aws.amazon.com/deadline-cloud/latest/userguide/submit-job-bundle.html)包含 shell 或 Python 指令碼時，任務附件也適用於[客戶受管機群](https://docs.aws.amazon.com/deadline-cloud/latest/userguide/manage-cmf.html)。

 當您使用[截止日期雲端 CLI](https://pypi.org/project/deadline/) 或截止日期雲端提交者提交任務套件時，任務連接會使用任務的儲存描述檔和佇列的必要檔案系統位置來識別不在工作者主機上的輸入檔案，並且應該上傳到 Amazon S3 作為任務提交的一部分。這些儲存設定檔也有助於 Deadline Cloud 識別工作者主機位置中的輸出檔案，這些檔案必須上傳至 Amazon S3，以便可供您的工作站使用。

 任務附件範例使用來自 和 的陣列、機群、佇列[範例專案基礎設施](sample-project-infrastructure.md)和儲存設定檔組態[儲存設定檔和路徑映射](storage-profiles-and-path-mapping.md)。您應該在此之前完成這些區段。

在下列範例中，您會使用範例任務套件做為起點，然後將其修改以探索任務連接的功能。任務套件是任務使用任務附件的最佳方式。它們將目錄中的[開啟任務描述](https://github.com/OpenJobDescription/openjd-specifications/wiki)任務範本與使用任務套件列出任務所需檔案和目錄的其他檔案結合在一起。如需任務套件的詳細資訊，請參閱 [截止日期雲端的開啟任務描述 (OpenJD) 範本](build-job-bundle.md)。

# 使用任務提交檔案
<a name="submitting-files-with-a-job"></a>

使用截止日期雲端，您可以讓任務工作流程存取工作者主機上共用檔案系統位置中無法使用的輸入檔案。任務附件允許轉譯任務僅存取位於本機工作站磁碟機或服務受管機群環境的檔案。提交任務套件時，您可以包含任務所需的輸入檔案和目錄清單。截止日期 雲端會識別這些非共用檔案，從本機電腦上傳到 Amazon S3，並將它們下載到工作者主機。它簡化了將輸入資產傳輸到轉譯節點的程序，確保可存取所有必要檔案以進行分散式任務執行。

您可以直接在任務套件中指定任務的檔案、在您使用環境變數或指令碼提供的任務範本中使用參數，以及使用任務`assets_references`的檔案。您可以使用其中一種方法或這三種方法的組合。您可以為任務的套件指定儲存描述檔，以便只上傳已在本機工作站上變更的檔案。

本節使用來自 GitHub 的範例任務套件，示範 Deadline Cloud 如何識別任務中要上傳的檔案、這些檔案如何在 Amazon S3 中組織，以及如何提供給處理任務的工作者主機。

**Topics**
+ [Deadline Cloud 如何將檔案上傳至 Amazon S3](what-job-attachments-uploads-to-amazon-s3.md)
+ [Deadline Cloud 如何選擇要上傳的檔案](how-job-attachments-decides-what-to-upload-to-amazon-s3.md)
+ [任務如何尋找任務連接輸入檔案](how-jobs-find-job-attachments-input-files.md)

# Deadline Cloud 如何將檔案上傳至 Amazon S3
<a name="what-job-attachments-uploads-to-amazon-s3"></a>

此範例顯示 Deadline Cloud 如何將檔案從工作站或工作者主機上傳至 Amazon S3，以便共用這些檔案。它使用來自 GitHub 和截止日期雲端 CLI 的範例任務套件來提交任務。

 首先將[截止期限雲端範例 GitHub 儲存庫](https://github.com/aws-deadline/deadline-cloud-samples)複製到您的[AWS CloudShell](https://docs.aws.amazon.com/cloudshell/latest/userguide/welcome.html)環境，然後將`job_attachments_devguide`任務套件複製到您的主目錄：

```
git clone https://github.com/aws-deadline/deadline-cloud-samples.git
cp -r deadline-cloud-samples/job_bundles/job_attachments_devguide ~/
```

 安裝[截止日期雲端 CLI](https://pypi.org/project/deadline/) 以提交任務套件：

```
pip install deadline --upgrade
```

 `job_attachments_devguide` 任務套件具有單一步驟，其中包含執行 bash shell 指令碼的任務，其檔案系統位置會以任務參數傳遞。任務參數的定義為：

```
...
- name: ScriptFile
  type: PATH
  default: script.sh
  dataFlow: IN
  objectType: FILE
...
```

 `dataFlow` 屬性`IN`的值會告知任務附件， `ScriptFile` 參數的值是任務的輸入。`default` 屬性的值是任務套件目錄的相對位置，但也可以是絕對路徑。此參數定義會將任務套件目錄中`script.sh`的檔案宣告為執行任務所需的輸入檔案。

 接下來，請確定截止日期雲端 CLI 未設定儲存設定檔，然後將任務提交至佇列 `Q1`：

```
# Change the value of FARM_ID to your farm's identifier
FARM_ID=farm-00112233445566778899aabbccddeeff
# Change the value of QUEUE1_ID to queue Q1's identifier
QUEUE1_ID=queue-00112233445566778899aabbccddeeff

deadline config set settings.storage_profile_id ''

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID job_attachments_devguide/
```

 在此命令執行後，來自截止日期雲端 CLI 的輸出如下所示：

```
Submitting to Queue: Q1
...
Hashing Attachments  [####################################]  100%
Hashing Summary:
    Processed 1 file totaling 39.0 B.
    Skipped re-processing 0 files totaling 0.0 B.
    Total processing time of 0.0327 seconds at 1.19 KB/s.

Uploading Attachments  [####################################]  100%
Upload Summary:
    Processed 1 file totaling 39.0 B.
    Skipped re-processing 0 files totaling 0.0 B.
    Total processing time of 0.25639 seconds at 152.0 B/s.

Waiting for Job to be created...
Submitted job bundle:
   job_attachments_devguide/
Job creation completed successfully
job-74148c13342e4514b63c7a7518657005
```

當您提交任務時，截止日期雲端會先雜湊`script.sh`檔案，然後將其上傳至 Amazon S3。

Deadline Cloud 會將 S3 儲存貯體視為內容可定址儲存體。檔案會上傳至 S3 物件。物件名稱衍生自檔案內容的雜湊。如果兩個檔案具有相同的內容，則無論檔案位於何處或名稱為何，它們都具有相同的雜湊值。此內容可定址儲存可讓 Deadline Cloud 在檔案已可用時避免上傳檔案。

 您可以使用 [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html) 來查看上傳至 Amazon S3 的物件：

```
# The name of queue `Q1`'s job attachments S3 bucket
Q1_S3_BUCKET=$(
  aws deadline get-queue --farm-id $FARM_ID --queue-id $QUEUE1_ID \
    --query 'jobAttachmentSettings.s3BucketName' | tr -d '"'
)

aws s3 ls s3://$Q1_S3_BUCKET --recursive
```

 兩個物件已上傳至 S3：
+  `DeadlineCloud/Data/87cb19095dd5d78fcaf56384ef0e6241.xxh128` – 的內容`script.sh`。物件金鑰`87cb19095dd5d78fcaf56384ef0e6241`中的值是檔案內容的雜湊，副檔`xxh128`名表示雜湊值計算為 128 位元 [xxhash](https://xxhash.com/)。
+  `DeadlineCloud/Manifests/<farm-id>/<queue-id>/Inputs/<guid>/a1d221c7fd97b08175b3872a37428e8c_input` – 任務提交的資訊清單物件。值 `<farm-id>`、 `<queue-id>`和 `<guid>`是您的陣列識別符、佇列識別符和隨機十六進位值。`a1d221c7fd97b08175b3872a37428e8c` 此範例中的值是從字串 計算的雜湊值`/home/cloudshell-user/job_attachments_devguide`，即 `script.sh` 所在的目錄。

 資訊清單物件包含作為任務提交的一部分上傳至 S3 之特定根路徑上的輸入檔案資訊。下載此資訊清單檔案 (`aws s3 cp s3://$Q1_S3_BUCKET/<objectname>`)。其內容類似：

```
{
    "hashAlg": "xxh128",
    "manifestVersion": "2023-03-03",
    "paths": [
        {
            "hash": "87cb19095dd5d78fcaf56384ef0e6241",
            "mtime": 1721147454416085,
            "path": "script.sh",
            "size": 39
        }
    ],
    "totalSize": 39
}
```

這表示檔案`script.sh`已上傳，且該檔案內容的雜湊為 `87cb19095dd5d78fcaf56384ef0e6241`。此雜湊值符合物件名稱 中的值`DeadlineCloud/Data/87cb19095dd5d78fcaf56384ef0e6241.xxh128`。Deadline Cloud 會使用它來知道要為此檔案的內容下載哪個物件。

 此檔案的完整結構描述可在 [ GitHub 中取得](https://github.com/aws-deadline/deadline-cloud/blob/mainline/src/deadline/job_attachments/asset_manifests/v2023_03_03/validate.py)。

當您使用 [CreateJob 操作](https://docs.aws.amazon.com/deadline-cloud/latest/APIReference/API_CreateJob.html)時，您可以設定資訊清單物件的位置。您可以使用 [GetJob 操作](https://docs.aws.amazon.com/deadline-cloud/latest/APIReference/API_GetJob.html)來查看位置：

```
{
    "attachments": {
        "file system": "COPIED",
        "manifests": [
            {
                "inputManifestHash": "5b0db3d311805ea8de7787b64cbbe8b3",
                "inputManifestPath": "<farm-id>/<queue-id>/Inputs/<guid>/a1d221c7fd97b08175b3872a37428e8c_input",
                "rootPath": "/home/cloudshell-user/job_attachments_devguide",
                "rootPathFormat": "posix"
            }
        ]
    },
    ...
}
```

# Deadline Cloud 如何選擇要上傳的檔案
<a name="how-job-attachments-decides-what-to-upload-to-amazon-s3"></a>

 任務附件視為上傳到 Amazon S3 做為任務輸入的檔案和目錄如下：
+  任務套件任務範本中定義之所有 `PATH`類型任務參數的值，`dataFlow`其值為 `IN`或 `INOUT`。
+  列為任務套件資產參考檔案中輸入的檔案和目錄。

 如果您提交的任務沒有儲存描述檔，則會上傳所有考慮上傳的檔案。如果您使用儲存描述檔提交任務，如果檔案位於儲存描述檔的 `SHARED`類型檔案系統位置，而這些位置也是佇列所需的檔案系統位置，則檔案不會上傳到 Amazon S3。這些位置預期可在執行任務的工作者主機上使用，因此不需要將其上傳至 S3。

 在此範例中，您會在 AWS CloudShell 環境中的 `WSAll`中建立`SHARED`檔案系統位置，然後將檔案新增至這些檔案系統位置。使用下列命令：

```
# Change the value of WSALL_ID to the identifier of the WSAll storage profile
WSALL_ID=sp-00112233445566778899aabbccddeeff

sudo mkdir -p /shared/common /shared/projects/project1 /shared/projects/project2
sudo chown -R cloudshell-user:cloudshell-user /shared

for d in /shared/common /shared/projects/project1 /shared/projects/project2; do
  echo "File contents for $d" > ${d}/file.txt
done
```

 接著，將資產參考檔案新增至任務套件，其中包含您建立做為任務輸入的所有檔案。使用下列命令：

```
cat > ${HOME}/job_attachments_devguide/asset_references.yaml << EOF
assetReferences:
  inputs:
    filenames:
    - /shared/common/file.txt
    directories:
    - /shared/projects/project1
    - /shared/projects/project2
EOF
```

 接著，設定截止日期雲端 CLI 以使用`WSAll`儲存設定檔提交任務，然後提交任務套件：

```
# Change the value of FARM_ID to your farm's identifier
FARM_ID=farm-00112233445566778899aabbccddeeff
# Change the value of QUEUE1_ID to queue Q1's identifier
QUEUE1_ID=queue-00112233445566778899aabbccddeeff
# Change the value of WSALL_ID to the identifier of the WSAll storage profile
WSALL_ID=sp-00112233445566778899aabbccddeeff

deadline config set settings.storage_profile_id $WSALL_ID

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID job_attachments_devguide/
```

當您提交任務時，截止日期 Cloud 會將兩個檔案上傳至 Amazon S3。您可以從 S3 下載任務的資訊清單物件，以查看上傳的檔案：

```
for manifest in $( \
  aws deadline get-job --farm-id $FARM_ID --queue-id $QUEUE1_ID --job-id $JOB_ID \
    --query 'attachments.manifests[].inputManifestPath' \
    | jq -r '.[]'
); do
  echo "Manifest object: $manifest"
  aws s3 cp --quiet s3://$Q1_S3_BUCKET/DeadlineCloud/Manifests/$manifest /dev/stdout | jq .
done
```

 在此範例中，有一個資訊清單檔案，其中包含下列內容：

```
{
    "hashAlg": "xxh128",
    "manifestVersion": "2023-03-03",
    "paths": [
        {
            "hash": "87cb19095dd5d78fcaf56384ef0e6241",
            "mtime": 1721147454416085,
            "path": "home/cloudshell-user/job_attachments_devguide/script.sh",
            "size": 39
        },
        {
            "hash": "af5a605a3a4e86ce7be7ac5237b51b79",
            "mtime": 1721163773582362,
            "path": "shared/projects/project2/file.txt",
            "size": 44
        }
    ],
    "totalSize": 83
}
```

 使用資訊清單的 [GetJob 操作](https://docs.aws.amazon.com/deadline-cloud/latest/APIReference/API_GetJob.html)來查看 `rootPath`是 "/"。

```
aws deadline get-job --farm-id $FARM_ID --queue-id $QUEUE1_ID --job-id $JOB_ID --query 'attachments.manifests[*]'
```

 一組輸入檔案的根路徑永遠是這些檔案最長的常見子路徑。如果您的任務是從 提交，Windows並且因為位於不同的磁碟機上而沒有通用子路徑的輸入檔案，您會在每個磁碟機上看到個別的根路徑。資訊清單中的路徑一律與資訊清單的根路徑相對，因此上傳的輸入檔案為：
+  `/home/cloudshell-user/job_attachments_devguide/script.sh` – 任務套件中的指令碼檔案。
+  `/shared/projects/project2/file.txt` – `WSAll`儲存設定檔中`SHARED`檔案系統位置中的檔案，該檔案**不在**佇列 所需的檔案系統位置清單中`Q1`。

檔案系統位置 `FSCommon`(`/shared/common/file.txt`) 和 `FS1`(`/shared/projects/project1/file.txt`) 中的檔案不在清單中。這是因為這些檔案系統位置位於`WSAll`儲存設定檔`SHARED`中，而且它們都位於佇列 中所需檔案系統位置的清單中`Q1`。

您可以使用 GetStorageProfileForQueue `SHARED` 操作，查看使用特定儲存設定檔提交之任務所考慮的檔案系統位置。 [GetStorageProfileForQueue ](https://docs.aws.amazon.com/deadline-cloud/latest/APIReference/API_GetStorageProfileForQueue.html) 若要查詢佇列`WSAll`的儲存設定檔，`Q1`請使用下列命令：

```
aws deadline get-storage-profile --farm-id $FARM_ID --storage-profile-id $WSALL_ID

aws deadline get-storage-profile-for-queue --farm-id $FARM_ID --queue-id $QUEUE1_ID --storage-profile-id $WSALL_ID
```

# 任務如何尋找任務連接輸入檔案
<a name="how-jobs-find-job-attachments-input-files"></a>

 若要讓任務使用 Deadline Cloud 使用任務附件上傳至 Amazon S3 的檔案，您的任務需要透過工作者主機上的檔案系統提供這些檔案。當任務的[工作階段](https://github.com/OpenJobDescription/openjd-specifications/wiki/How-Jobs-Are-Run#sessions)在工作者主機上執行時，Deadline Cloud 會將任務的輸入檔案下載到工作者主機本機磁碟機的暫存目錄中，並將每個任務根路徑的路徑映射規則新增至本機磁碟機上的檔案系統位置。

 在此範例中，在 AWS CloudShell 索引標籤中啟動截止日期雲端工作者代理程式。讓任何先前提交的任務完成執行，然後從日誌目錄中刪除任務日誌：

```
rm -rf ~/devdemo-logs/queue-*
```

 下列指令碼會修改任務套件，以顯示工作階段臨時工作目錄中的所有檔案，以及路徑映射規則檔案的內容，然後提交具有修改後套件的任務：

```
# Change the value of FARM_ID to your farm's identifier
FARM_ID=farm-00112233445566778899aabbccddeeff
# Change the value of QUEUE1_ID to queue Q1's identifier
QUEUE1_ID=queue-00112233445566778899aabbccddeeff
# Change the value of WSALL_ID to the identifier of the WSAll storage profile
WSALL_ID=sp-00112233445566778899aabbccddeeff

deadline config set settings.storage_profile_id $WSALL_ID

cat > ~/job_attachments_devguide/script.sh << EOF
#!/bin/bash

echo "Session working directory is: \$(pwd)"
echo
echo "Contents:"
find . -type f
echo
echo "Path mapping rules file: \$1"
jq . \$1
EOF

cat > ~/job_attachments_devguide/template.yaml << EOF
specificationVersion: jobtemplate-2023-09
name: "Job Attachments Explorer"
parameterDefinitions:
- name: ScriptFile
  type: PATH
  default: script.sh
  dataFlow: IN
  objectType: FILE
steps:
- name: Step
  script:
    actions:
      onRun:
        command: /bin/bash
        args:
        - "{{Param.ScriptFile}}"
        - "{{Session.PathMappingRulesFile}}"
EOF

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID job_attachments_devguide/
```

 在 AWS CloudShell 環境中的工作者執行任務之後，您可以查看任務執行的日誌：

```
cat demoenv-logs/queue-*/session*.log
```

日誌顯示工作階段中發生的第一件事是任務的兩個輸入檔案下載到工作者：

```
2024-07-17 01:26:37,824 INFO ==============================================
2024-07-17 01:26:37,825 INFO --------- Job Attachments Download for Job
2024-07-17 01:26:37,825 INFO ==============================================
2024-07-17 01:26:37,825 INFO Syncing inputs using Job Attachments
2024-07-17 01:26:38,116 INFO Downloaded 142.0 B / 186.0 B of 2 files (Transfer rate: 0.0 B/s)
2024-07-17 01:26:38,174 INFO Downloaded 186.0 B / 186.0 B of 2 files (Transfer rate: 733.0 B/s)
2024-07-17 01:26:38,176 INFO Summary Statistics for file downloads:
Processed 2 files totaling 186.0 B.
Skipped re-processing 0 files totaling 0.0 B.
Total processing time of 0.09752 seconds at 1.91 KB/s.
```

 接下來是任務`script.sh`執行的輸出：
+  提交任務時上傳的輸入檔案位於目錄下，其名稱開頭為工作階段暫時目錄中的「assetroot」。
+  輸入檔案的路徑已相對於「assetroot」目錄重新定位，而不是相對於任務輸入資訊清單的根路徑 (`"/"`)。
+  路徑映射規則檔案包含一個額外的規則，可對應`"/"`至「assetroot」目錄的絕對路徑。

 例如：

```
2024-07-17 01:26:38,264 INFO Output:
2024-07-17 01:26:38,267 INFO Session working directory is: /sessions/session-5b33f
2024-07-17 01:26:38,267 INFO 
2024-07-17 01:26:38,267 INFO Contents:
2024-07-17 01:26:38,269 INFO ./tmp_xdhbsdo.sh
2024-07-17 01:26:38,269 INFO ./tmpdi00052b.json
2024-07-17 01:26:38,269 INFO ./assetroot-assetroot-3751a/shared/projects/project2/file.txt
2024-07-17 01:26:38,269 INFO ./assetroot-assetroot-3751a/home/cloudshell-user/job_attachments_devguide/script.sh
2024-07-17 01:26:38,269 INFO 
2024-07-17 01:26:38,270 INFO Path mapping rules file: /sessions/session-5b33f/tmpdi00052b.json
2024-07-17 01:26:38,282 INFO {
2024-07-17 01:26:38,282 INFO   "version": "pathmapping-1.0",
2024-07-17 01:26:38,282 INFO   "path_mapping_rules": [
2024-07-17 01:26:38,282 INFO     {
2024-07-17 01:26:38,282 INFO       "source_path_format": "POSIX",
2024-07-17 01:26:38,282 INFO       "source_path": "/shared/projects/project1",
2024-07-17 01:26:38,283 INFO       "destination_path": "/mnt/projects/project1"
2024-07-17 01:26:38,283 INFO     },
2024-07-17 01:26:38,283 INFO     {
2024-07-17 01:26:38,283 INFO       "source_path_format": "POSIX",
2024-07-17 01:26:38,283 INFO       "source_path": "/shared/common",
2024-07-17 01:26:38,283 INFO       "destination_path": "/mnt/common"
2024-07-17 01:26:38,283 INFO     },
2024-07-17 01:26:38,283 INFO     {
2024-07-17 01:26:38,283 INFO       "source_path_format": "POSIX",
2024-07-17 01:26:38,283 INFO       "source_path": "/",
2024-07-17 01:26:38,283 INFO       "destination_path": "/sessions/session-5b33f/assetroot-assetroot-3751a"
2024-07-17 01:26:38,283 INFO     }
2024-07-17 01:26:38,283 INFO   ]
2024-07-17 01:26:38,283 INFO }
```

**注意**  
 如果您提交的任務具有多個具有不同根路徑的資訊清單，則每個根路徑都有不同的「assetroot」命名目錄。

 如果您需要參考其中一個輸入檔案、目錄或檔案系統位置的重新定位檔案系統位置，您可以處理任務中的路徑映射規則檔案並自行執行重新映射，或將`PATH`類型任務參數新增至任務套件中的任務範本，並將重新映射所需的值傳遞為該參數的值。例如，下列範例會將任務套件修改為具有其中一個任務參數，然後以檔案系統位置`/shared/projects/project2`做為其值來提交任務：

```
cat > ~/job_attachments_devguide/template.yaml << EOF
specificationVersion: jobtemplate-2023-09
name: "Job Attachments Explorer"
parameterDefinitions:
- name: LocationToRemap
  type: PATH
steps:
- name: Step
  script:
    actions:
      onRun:
        command: /bin/echo
        args:
        - "The location of {{RawParam.LocationToRemap}} in the session is {{Param.LocationToRemap}}"
EOF

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID job_attachments_devguide/ \
  -p LocationToRemap=/shared/projects/project2
```

 此任務執行的日誌檔案包含其輸出：

```
2024-07-17 01:40:35,283 INFO Output:
2024-07-17 01:40:35,284 INFO The location of /shared/projects/project2 in the session is /sessions/session-5b33f/assetroot-assetroot-3751a
```

# 從任務取得輸出檔案
<a name="getting-output-files-from-a-job"></a>

此範例顯示 Deadline Cloud 如何識別任務產生的輸出檔案、決定是否將這些檔案上傳至 Amazon S3，以及如何在工作站上取得這些輸出檔案。

 此範例使用 `job_attachments_devguide_output` 任務套件，而非 `job_attachments_devguide`任務套件。首先，從您複製的截止日期雲端範例 GitHub 儲存庫，在您的 AWS CloudShell 環境中複製套件：

```
cp -r deadline-cloud-samples/job_bundles/job_attachments_devguide_output ~/
```

 此任務套件和`job_attachments_devguide`任務套件之間的重要差異在於在任務範本中新增新的任務參數：

```
...
parameterDefinitions:
...
- name: OutputDir
  type: PATH
  objectType: DIRECTORY
  dataFlow: OUT
  default: ./output_dir
  description: This directory contains the output for all steps.
...
```

 參數的 `dataFlow` 屬性具有值 `OUT`。Deadline Cloud 使用 值為 `OUT`或 `dataFlow`的任務參數值`INOUT`做為任務的輸出。如果傳遞為這類任務參數值的檔案系統位置重新映射至執行任務的工作者上的本機檔案系統位置，則 Deadline Cloud 會在該位置尋找新檔案，並將這些檔案上傳到 Amazon S3 做為任務輸出。

 若要查看其運作方式，請先在 AWS CloudShell 索引標籤中啟動截止日期雲端工作者代理程式。讓任何先前提交的任務完成執行。然後從日誌目錄中刪除任務日誌：

```
rm -rf ~/devdemo-logs/queue-*
```

 接著，使用此任務套件提交任務。在 CloudShell 中執行的工作者執行後，請查看日誌：

```
# Change the value of FARM_ID to your farm's identifier
FARM_ID=farm-00112233445566778899aabbccddeeff
# Change the value of QUEUE1_ID to queue Q1's identifier
QUEUE1_ID=queue-00112233445566778899aabbccddeeff
# Change the value of WSALL_ID to the identifier of the WSAll storage profile
WSALL_ID=sp-00112233445566778899aabbccddeeff

deadline config set settings.storage_profile_id $WSALL_ID

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID ./job_attachments_devguide_output
```

 日誌顯示檔案已偵測到為輸出並上傳至 Amazon S3：

```
2024-07-17 02:13:10,873 INFO ----------------------------------------------
2024-07-17 02:13:10,873 INFO Uploading output files to Job Attachments
2024-07-17 02:13:10,873 INFO ----------------------------------------------
2024-07-17 02:13:10,873 INFO Started syncing outputs using Job Attachments
2024-07-17 02:13:10,955 INFO Found 1 file totaling 117.0 B in output directory: /sessions/session-7efa/assetroot-assetroot-3751a/output_dir
2024-07-17 02:13:10,956 INFO Uploading output manifest to DeadlineCloud/Manifests/farm-0011/queue-2233/job-4455/step-6677/task-6677-0/2024-07-17T02:13:10.835545Z_sessionaction-8899-1/c6808439dfc59f86763aff5b07b9a76c_output
2024-07-17 02:13:10,988 INFO Uploading 1 output file to S3: s3BucketName/DeadlineCloud/Data
2024-07-17 02:13:11,011 INFO Uploaded 117.0 B / 117.0 B of 1 file (Transfer rate: 0.0 B/s)
2024-07-17 02:13:11,011 INFO Summary Statistics for file uploads:
Processed 1 file totaling 117.0 B.
Skipped re-processing 0 files totaling 0.0 B.
Total processing time of 0.02281 seconds at 5.13 KB/s.
```

 日誌也顯示 Deadline Cloud 在 Amazon S3 儲存貯體中建立新的資訊清單物件，該儲存貯體設定為由佇列 上的任務附件使用`Q1`。資訊清單物件的名稱衍生自產生輸出之任務的陣列、佇列、任務、步驟、任務、時間戳記和`sessionaction`識別符。下載此資訊清單檔案，以查看截止日期雲端放置此任務輸出檔案的位置：

```
# The name of queue `Q1`'s job attachments S3 bucket
Q1_S3_BUCKET=$(
  aws deadline get-queue --farm-id $FARM_ID --queue-id $QUEUE1_ID \
    --query 'jobAttachmentSettings.s3BucketName' | tr -d '"'
)

# Fill this in with the object name from your log
OBJECT_KEY="DeadlineCloud/Manifests/..."

aws s3 cp --quiet s3://$Q1_S3_BUCKET/$OBJECT_KEY /dev/stdout | jq .
```

 資訊清單看起來像：

```
{
  "hashAlg": "xxh128",
  "manifestVersion": "2023-03-03",
  "paths": [
    {
      "hash": "34178940e1ef9956db8ea7f7c97ed842",
      "mtime": 1721182390859777,
      "path": "output_dir/output.txt",
      "size": 117
    }
  ],
  "totalSize": 117
}
```

 這會顯示輸出檔案的內容會儲存到 Amazon S3，就像儲存任務輸入檔案一樣。與輸入檔案類似，輸出檔案存放在 S3 中，其物件名稱包含檔案的雜湊和字首 `DeadlineCloud/Data`。

```
$ aws s3 ls --recursive s3://$Q1_S3_BUCKET | grep 34178940e1ef9956db8ea7f7c97ed842
2024-07-17 02:13:11        117 DeadlineCloud/Data/34178940e1ef9956db8ea7f7c97ed842.xxh128
```

 您可以使用截止日期雲端監視器或截止日期雲端 CLI，將任務的輸出下載到您的工作站：

```
deadline job download-output --farm-id $FARM_ID --queue-id $QUEUE1_ID --job-id $JOB_ID
```

 所提交`OutputDir`任務中的任務參數值為 `./output_dir`，因此輸出會下載至任務套件目錄中名為 `output_dir`的目錄。如果您將絕對路徑或不同的相對位置指定為 的值`OutputDir`，則輸出檔案會改為下載至該位置。

```
$ deadline job download-output --farm-id $FARM_ID --queue-id $QUEUE1_ID --job-id $JOB_ID
Downloading output from Job 'Job Attachments Explorer: Output'

Summary of files to download:
    /home/cloudshell-user/job_attachments_devguide_output/output_dir/output.txt (1 file)

You are about to download files which may come from multiple root directories. Here are a list of the current root directories:
[0] /home/cloudshell-user/job_attachments_devguide_output
> Please enter the index of root directory to edit, y to proceed without changes, or n to cancel the download (0, y, n) [y]: 

Downloading Outputs  [####################################]  100%
Download Summary:
    Downloaded 1 files totaling 117.0 B.
    Total download time of 0.14189 seconds at 824.0 B/s.
    Download locations (total file counts):
        /home/cloudshell-user/job_attachments_devguide_output (1 file)
```

# 在相依步驟中使用步驟中的檔案
<a name="using-files-output-from-a-step-in-a-dependent-step"></a>

此範例顯示任務中的一個步驟如何從相同任務中依賴的步驟存取輸出。

 為了讓一個步驟的輸出可供另一個步驟使用，Deadline Cloud 會將其他動作新增至工作階段，以便在工作階段中執行任務之前下載這些輸出。您可以將這些步驟宣告為需要使用輸出之步驟的相依性，藉此告知從 下載輸出的步驟。

使用此範例`job_attachments_devguide_output`的任務套件。首先，從您複製的截止日期雲端範例 GitHub 儲存庫，在您的 AWS CloudShell 環境中建立複本。修改它以新增相依步驟，該步驟只會在現有步驟之後執行，並使用該步驟的輸出：

```
cp -r deadline-cloud-samples/job_bundles/job_attachments_devguide_output ~/

cat >> job_attachments_devguide_output/template.yaml << EOF
- name: DependentStep
  dependencies:
  - dependsOn: Step
  script:
    actions:
      onRun:
        command: /bin/cat
        args:
        - "{{Param.OutputDir}}/output.txt"
EOF
```

 使用此修改後的任務套件建立的任務會以兩個單獨的工作階段執行，一個用於步驟「步驟」中的任務，另一個用於步驟「DependentStep」中的任務。

首先在 CloudShell 索引標籤中啟動截止日期雲端工作者代理程式。讓任何先前提交的任務完成執行，然後從日誌目錄中刪除任務日誌：

```
rm -rf ~/devdemo-logs/queue-*
```

 接著，使用修改後的任務套件提交`job_attachments_devguide_output`任務。等待它在 CloudShell 環境中的工作者上完成執行。查看兩個工作階段的日誌：

```
# Change the value of FARM_ID to your farm's identifier
FARM_ID=farm-00112233445566778899aabbccddeeff
# Change the value of QUEUE1_ID to queue Q1's identifier
QUEUE1_ID=queue-00112233445566778899aabbccddeeff
# Change the value of WSALL_ID to the identifier of the WSAll storage profile
WSALL_ID=sp-00112233445566778899aabbccddeeff

deadline config set settings.storage_profile_id $WSALL_ID

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID ./job_attachments_devguide_output

# Wait for the job to finish running, and then:

cat demoenv-logs/queue-*/session-*
```

 在名為 之步驟中任務的工作階段日誌中`DependentStep`，會執行兩個不同的下載動作：

```
2024-07-17 02:52:05,666 INFO ==============================================
2024-07-17 02:52:05,666 INFO --------- Job Attachments Download for Job
2024-07-17 02:52:05,667 INFO ==============================================
2024-07-17 02:52:05,667 INFO Syncing inputs using Job Attachments
2024-07-17 02:52:05,928 INFO Downloaded 207.0 B / 207.0 B of 1 file (Transfer rate: 0.0 B/s)
2024-07-17 02:52:05,929 INFO Summary Statistics for file downloads:
Processed 1 file totaling 207.0 B.
Skipped re-processing 0 files totaling 0.0 B.
Total processing time of 0.03954 seconds at 5.23 KB/s.

2024-07-17 02:52:05,979 INFO 
2024-07-17 02:52:05,979 INFO ==============================================
2024-07-17 02:52:05,979 INFO --------- Job Attachments Download for Step
2024-07-17 02:52:05,979 INFO ==============================================
2024-07-17 02:52:05,980 INFO Syncing inputs using Job Attachments
2024-07-17 02:52:06,133 INFO Downloaded 117.0 B / 117.0 B of 1 file (Transfer rate: 0.0 B/s)
2024-07-17 02:52:06,134 INFO Summary Statistics for file downloads:
Processed 1 file totaling 117.0 B.
Skipped re-processing 0 files totaling 0.0 B.
Total processing time of 0.03227 seconds at 3.62 KB/s.
```

 第一個動作會下載名為「步驟」的步驟所使用的`script.sh`檔案。第二個動作會從該步驟下載輸出。Deadline Cloud 會使用該步驟產生的輸出資訊清單做為輸入資訊清單，來決定要下載哪些檔案。

 在相同的日誌中，您可以查看名為 "DependentStep" 步驟的輸出：

```
2024-07-17 02:52:06,213 INFO Output:
2024-07-17 02:52:06,216 INFO Script location: /sessions/session-5b33f/assetroot-assetroot-3751a/script.sh
```