

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

# AWS TOE 元件管理員支援的動作模組
<a name="toe-action-modules"></a>

映像建置服務，例如 EC2 Image Builder，使用 AWS TOE 動作模組來協助設定用於建置和測試自訂機器映像的 EC2 執行個體。本節說明常用 AWS TOE 動作模組的功能，以及如何設定這些功能，包括範例。

元件是以純文字 YAML 文件撰寫。如需文件語法的詳細資訊，請參閱 [使用自訂 AWS TOE 元件的元件文件架構](toe-use-documents.md)。

**注意**  
所有動作模組在執行時使用與 Systems Manager 代理程式相同的帳戶，即 `root` Linux 和 Windows `NT Authority\SYSTEM`上的 。

下列交叉參考會根據動作模組執行的動作類型來分類動作模組。

 

**一般執行**
+ [Assert (Linux、Windows、macOS)](#action-modules-assertion)
+ [ExecuteBash (Linux、macOS)](#action-modules-executebash)
+ [ExecuteBinary (Linux、Windows、macOS)](#action-modules-executebinary)
+ [ExecuteDocument (Linux、Windows、macOS)](#action-modules-executedocument)
+ [ExecutePowerShell (Windows)](#action-modules-executepowershell)

 

**檔案下載和上傳**
+ [S3Download (Linux、Windows、macOS)](#action-modules-s3download)
+ [S3Upload (Linux、Windows、macOS)](#action-modules-s3upload)
+ [WebDownload (Linux、Windows、macOS)](#action-modules-webdownload)

 

**檔案系統操作**
+ [AppendFile (Linux、Windows、macOS)](#action-modules-appendfile)
+ [CopyFile (Linux、Windows、macOS)](#action-modules-copyfile)
+ [CopyFolder (Linux、Windows、macOS)](#action-modules-copyfolder)
+ [CreateFile (Linux、Windows、macOS)](#action-modules-createfile)
+ [CreateFolder (Linux、Windows、macOS)](#action-modules-createfolder)
+ [CreateSymlink (Linux、Windows、macOS)](#action-modules-createsymlink)
+ [DeleteFile (Linux、Windows、macOS)](#action-modules-deletefile)
+ [DeleteFolder (Linux、Windows、macOS)](#action-modules-deletefolder)
+ [ListFiles (Linux、Windows、macOS)](#action-modules-listfiles)
+ [MoveFile (Linux、Windows、macOS)](#action-modules-movefile)
+ [MoveFolder (Linux、Windows、macOS)](#action-modules-movefolder)
+ [ReadFile (Linux、Windows、macOS)](#action-modules-readfile)
+ [SetFileEncoding (Linux、Windows、macOS)](#action-modules-setfileencoding)
+ [SetFileOwner (Linux、Windows、macOS)](#action-modules-setfileowner)
+ [SetFolderOwner (Linux、Windows、macOS)](#action-modules-setfolderowner)
+ [SetFilePermissions (Linux、Windows、macOS)](#action-modules-setfilepermissions)
+ [SetFolderPermissions (Linux、Windows、macOS)](#action-modules-setfolderpermissions)

 

**軟體安裝動作**
+ [InstallMSI (Windows)](#action-modules-install-msi)
+ [UninstallMSI (Windows)](#action-modules-uninstall-msi)

 

**系統動作**
+ [重新啟動 (Linux、Windows)](#action-modules-reboot)
+ [SetRegistry (Windows)](#action-modules-setregistry)
+ [UpdateOS (Linux、Windows)](#action-modules-updateos)

## 一般執行模組
<a name="action-modules-general-execution"></a>

下一節包含執行命令和控制執行工作流程之動作模組的詳細資訊。

**Topics**
+ [Assert (Linux、Windows、macOS)](#action-modules-assertion)
+ [ExecuteBash (Linux、macOS)](#action-modules-executebash)
+ [ExecuteBinary (Linux、Windows、macOS)](#action-modules-executebinary)
+ [ExecuteDocument (Linux、Windows、macOS)](#action-modules-executedocument)
+ [ExecutePowerShell (Windows)](#action-modules-executepowershell)

### Assert (Linux、Windows、macOS)
<a name="action-modules-assertion"></a>

**Assert** 動作模組會使用 [比較運算子](toe-comparison-operators.md)或 [邏輯運算子](toe-logical-operators.md)做為輸入來執行值比較。運算子表達式的結果 (true 或 false) 表示步驟的整體成功或失敗狀態。

如果比較或邏輯運算子表達式評估為 `true`，則步驟會標記為 `Success`。否則，步驟會標示為 `Failed`。如果步驟失敗， `onFailure` 參數會決定步驟的結果。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| input | 包含單一比較或邏輯運算子。請注意，邏輯運算子可以包含多個比較運算子。 | 這是變數，取決於運算子 | 是 | 

**輸入範例：使用比較運算子的簡單`stringEquals`比較**

此範例評估為 `true`。

```
- name: StringComparison
  action: Assert
  inputs:
    stringEquals: '2.1.1'
    value: '{{ validate.ApplicationVersion.outputs.stdout }}'
```

**輸入範例：使用比較運算子進行 Regex `patternMatches`比較**

這些範例都會評估為 `true`。

```
- name: Letters only
  action: Assert
  inputs:
    patternMatches: '^[a-zA-Z]+$'
    value: 'ThisIsOnlyLetters'

- name: Letters and spaces only
  action: Assert
  inputs:
    patternMatches: '^[a-zA-Z\s]+$'
    value: 'This text contains spaces'
  
- name: Numbers only
  action: Assert
  inputs:
    patternMatches: '^[0-9]+$'
    value: '1234567890'
```

**輸入範例：與邏輯運算子和鏈結變數的巢狀比較**

下列範例示範與邏輯運算子的巢狀比較，這些運算子使用鏈結變數的比較。`true` 如果下列任一項為 true，則 會`Assert`評估為 ：
+ `ApplicationVersion` 大於 `2.0`且 `CPUArchitecture`等於 `arm64`。
+ `CPUArchitecture` 等於 `x86_64`。

```
- name: NestedComparisons
  action: Assert
  inputs:
    or: # <- first level deep
      - and: # <- second level deep
          - numberGreaterThan: 2.0 # <- third level deep
            value: '{{ validate.ApplicationVersion.outputs.stdout }}'
          - stringEquals: 'arm64'
            value: '{{ validate.CPUArchitecture.outputs.stdout }}'
      - stringEquals: 'x86_64'
        value: '{{ validate.CPUArchitecture.outputs.stdout }}'
```

**輸出：**

的輸出`Assert`是步驟的成功或失敗。

### ExecuteBash (Linux、macOS)
<a name="action-modules-executebash"></a>

**ExecuteBash** 動作模組可讓您使用內嵌 shell 程式碼/命令執行 bash 指令碼。此模組支援 Linux。

您在命令區塊中指定的所有命令和指示都會轉換為檔案 （例如 `input.sh`)，並使用 bash shell 執行。執行 shell 檔案的結果是 步驟的結束碼。

如果指令碼以 的結束代碼結束，則 **ExecuteBash** 模組會處理系統重新啟動`194`。啟動時，應用程式會執行下列其中一個動作：
+ 如果由 Systems Manager Agent 執行，應用程式會將結束碼交給發起人。Systems Manager 代理程式會處理系統重新啟動，並執行啟動重新啟動的相同步驟，如[從指令碼重新啟動受管執行個體](https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-reboot.html)中所述。
+ 應用程式會儲存目前的 `executionstate`、設定重新啟動觸發以重新執行應用程式，以及重新啟動系統。

系統重新啟動後，應用程式會執行與啟動重新啟動相同的步驟。如果您需要此功能，您必須撰寫等冪指令碼，以處理相同 shell 命令的多個調用。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| commands | 包含根據 bash 語法執行的指示或命令清單。允許多行 YAML。 | 清單 | 是 | 

**輸入範例：重新啟動之前和之後**

```
name: ExitCode194Example
description: This shows how the exit code can be used to restart a system with ExecuteBash
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: RestartTrigger
        action: ExecuteBash
        inputs:
          commands:
            - |
              REBOOT_INDICATOR=/var/tmp/reboot-indicator
              if [ -f "${REBOOT_INDICATOR}" ]; then
                echo 'The reboot file exists. Deleting it and exiting with success.'
                rm "${REBOOT_INDICATOR}"
                exit 0
              fi
              echo 'The reboot file does not exist. Creating it and triggering a restart.'
              touch "${REBOOT_INDICATOR}"
              exit 194
```


**Output**  

| 欄位 | 說明 | Type | 
| --- | --- | --- | 
| stdout | 命令執行的標準輸出。 | string | 

如果您啟動重新啟動並傳回結束程式碼`194`做為動作模組的一部分，建置將在啟動重新啟動的相同動作模組步驟繼續。如果您在沒有結束碼的情況下啟動重新啟動，建置程序可能會失敗。

**輸出範例：重新啟動之前 （第一次通過文件）**

```
{
	“stdout”: “The reboot file does not exist. Creating it and triggering a restart."
}
```

**輸出範例：重新啟動後， （文件的第二次）**

```
{
	“stdout”: “The reboot file exists. Deleting it and exiting with success."
}
```

### ExecuteBinary (Linux、Windows、macOS)
<a name="action-modules-executebinary"></a>

**ExecuteBinary** 動作模組可讓您使用命令列引數清單執行二進位檔案。

如果二進位檔案以 `194`(Linux) 或 (`3010`Windows) 的結束碼結束，則 **ExecuteBinary** 模組會處理系統重新啟動。發生這種情況時，應用程式會執行下列其中一個動作：
+ 如果由 Systems Manager Agent 執行，應用程式會將結束碼交給發起人。Systems Manager 代理程式會處理重新啟動系統，並執行啟動重新啟動的相同步驟，如[從指令碼重新啟動受管執行個體](https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-reboot.html)中所述。
+ 應用程式會儲存目前的 `executionstate`、設定重新啟動觸發以重新執行應用程式，以及重新啟動系統。

系統重新啟動後，應用程式會執行與啟動重新啟動相同的步驟。如果您需要此功能，您必須撰寫等冪指令碼，以處理相同 shell 命令的多個調用。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| path | 二進位檔案的執行路徑。 | String | 是 | 
| arguments | 包含執行二進位檔時要使用的命令列引數清單。 | 字串清單 | 否 | 

**輸入範例：安裝 .NET**

```
  - name: "InstallDotnet"
    action: ExecuteBinary
    inputs:
      path: C:\PathTo\dotnet_installer.exe
      arguments:
        - /qb
        - /norestart
```


**Output**  

| 欄位 | 說明 | Type | 
| --- | --- | --- | 
| stdout | 命令執行的標準輸出。 | string | 

**輸出範例**

```
{
	"stdout": "success"
}
```

### ExecuteDocument (Linux、Windows、macOS)
<a name="action-modules-executedocument"></a>

**ExecuteDocument** 動作模組新增了對巢狀元件文件的支援，從一個文件中執行多個元件文件。 會在執行時間 AWS TOE 驗證在輸入參數中傳遞的文件。

**限制**
+ 此動作模組執行一次，不允許重試，也不允許設定逾時限制的選項。**ExecuteDocument** 會設定下列預設值，並在您嘗試變更時傳回錯誤。
  + `timeoutSeconds`：-1
  + `maxAttempts`：1
**注意**  
您可以將這些值保留空白，並使用 AWS TOE 預設值。
+ 允許文件巢狀化，最多三個層級深度，但不超過此層級。三種巢狀層級會轉換為四個文件層級，因為頂層不會巢狀化。在此案例中，最低層級的文件不得呼叫任何其他文件。
+ 不允許重複執行元件文件。在迴圈建構模組之外呼叫自己，或呼叫目前執行鏈中較高之其他文件的任何文件，都會啟動一個週期，進而產生無限迴圈。當 AWS TOE 偵測到循環執行時，它會停止執行並記錄失敗。

![\[ExecuteDocument 動作模組的巢狀層級限制。\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/images/toe-component-document-nesting.png)


如果元件文件嘗試自行執行，或執行目前執行鏈中更高的任何元件文件，則執行會失敗。

**輸入**


| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| document |  元件文件的路徑。有效的選項包含： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | String | 是 | 
| document-s3-bucket-owner |  存放元件文件之 S3 儲存貯體的 S3 儲存貯體擁有者的帳戶 ID。*（如果您在元件文件中使用 S3 URIs則建議使用。)*  | String | 否 | 
| phases |  在元件文件中執行的階段，以逗號分隔清單表示。如果未指定階段，則所有階段都會執行。  | String | 否 | 
| parameters |  在執行時間傳入元件文件的輸入參數，做為索引鍵值對。  | 參數映射清單 | 否 | 

**參數映射輸入**


| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| name |  要傳遞至 **ExecuteDocument** 動作模組正在執行之元件文件的輸入參數名稱。  | String | 是 | 
| value |  輸入參數的值。  | String | 是 | 

**輸入範例**  
以下範例顯示元件文件的輸入變化，取決於您的安裝路徑。

**輸入範例：本機文件路徑**

```
# main.yaml
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ExecuteNestedDocument
        action: ExecuteDocument
        inputs:
          document: Sample-1.yaml
          phases: build
          parameters:
            - name: parameter-1
              value: value-1
            - name: parameter-2
              value: value-2
```

**輸入範例：做為文件路徑的 S3 URI**

```
# main.yaml
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ExecuteNestedDocument
        action: ExecuteDocument
        inputs:
          document: s3://my-bucket/Sample-1.yaml
          document-s3-bucket-owner: 123456789012
          phases: build,validate
          parameters:
            - name: parameter-1
              value: value-1
            - name: parameter-2
              value: value-2
```

**輸入範例：EC2 Image Builder 元件 ARN 做為文件路徑**

```
# main.yaml
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ExecuteNestedDocument
        action: ExecuteDocument
        inputs:
          document: arn:aws:imagebuilder:us-west-2:aws:component/Sample-Test/1.0.0
          phases: test
          parameters:
            - name: parameter-1
              value: value-1
            - name: parameter-2
              value: value-2
```

**使用 ForEach 迴圈來執行文件**

```
# main.yaml
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ExecuteNestedDocument
        action: ExecuteDocument
        loop:
          name: 'myForEachLoop'
          forEach:
            - Sample-1.yaml
            - Sample-2.yaml
        inputs:
          document: "{{myForEachLoop.value}}"
          phases: test
          parameters:
            - name: parameter-1
              value: value-1
            - name: parameter-2
              value: value-2
```

**使用 For 迴圈來執行文件**

```
# main.yaml
schemaVersion: 1.0

phases:
  - name: build
    steps:
      - name: ExecuteNestedDocument
        action: ExecuteDocument
        loop:
          name: 'myForLoop'
          for:
            start: 1
            end: 2
            updateBy: 1
        inputs:
          document: "Sample-{{myForLoop.value}}.yaml"
          phases: test
          parameters:
            - name: parameter-1
              value: value-1
            - name: parameter-2
              value: value-2
```

**Output**  
AWS TOE 會在每次執行`detailedoutput.json`時建立名為 的輸出檔案。檔案包含執行時叫用之每個元件文件的每個階段和步驟的詳細資訊。對於 **ExecuteDocument** 動作模組，您可以在 欄位中找到簡短的執行時間摘要`outputs`，以及其在 中執行之階段、步驟和文件的詳細資訊`detailedOutput`。

```
{
	\"executedStepCount\":1,\"executionId\":\"97054e22-06cc-11ec-9b14-acde48001122\",\"failedStepCount\":0,\"failureMessage\":\"\",\"ignoredFailedStepCount\":0,\"logUrl\":\"\",\"status\":\"success\"
}",
```

每個元件文件的輸出摘要物件都包含下列詳細資訊，如下所示，其中包含範例值：
+ executedStepCount"：1
+ "executionId"："12345a67-89bc-01de-2f34-abcd56789012"
+ "failedStepCount"：0
+ "failureMessage"：""
+ "ignoredFailedStepCount"：0
+ "logUrl"：""
+ "狀態"："成功"

**輸出範例**  
下列範例顯示巢狀執行發生時，**ExecuteDocument** 動作模組的輸出。在此範例中，`main.yaml`元件文件成功執行`Sample-1.yaml`元件文件。

```
{
    "executionId": "12345a67-89bc-01de-2f34-abcd56789012",
    "status": "success",
    "startTime": "2021-08-26T17:20:31-07:00",
    "endTime": "2021-08-26T17:20:31-07:00",
    "failureMessage": "",
    "documents": [
        {
            "name": "",
            "filePath": "main.yaml",
            "status": "success",
            "description": "",
            "startTime": "2021-08-26T17:20:31-07:00",
            "endTime": "2021-08-26T17:20:31-07:00",
            "failureMessage": "",
            "phases": [
                {
                    "name": "build",
                    "status": "success",
                    "startTime": "2021-08-26T17:20:31-07:00",
                    "endTime": "2021-08-26T17:20:31-07:00",
                    "failureMessage": "",
                    "steps": [
                        {
                            "name": "ExecuteNestedDocument",
                            "status": "success",
                            "failureMessage": "",
                            "timeoutSeconds": -1,
                            "onFailure": "Abort",
                            "maxAttempts": 1,
                            "action": "ExecuteDocument",
                            "startTime": "2021-08-26T17:20:31-07:00",
                            "endTime": "2021-08-26T17:20:31-07:00",
                            "inputs": "[{\"document\":\"Sample-1.yaml\",\"document-s3-bucket-owner\":\"\",\"phases\":\"\",\"parameters\":null}]",
                            "outputs": "[{\"executedStepCount\":1,\"executionId\":\"98765f43-21ed-09cb-8a76-fedc54321098\",\"failedStepCount\":0,\"failureMessage\":\"\",\"ignoredFailedStepCount\":0,\"logUrl\":\"\",\"status\":\"success\"}]",
                            "loop": null,
                            "detailedOutput": [
                                {
                                    "executionId": "98765f43-21ed-09cb-8a76-fedc54321098",
                                    "status": "success",
                                    "startTime": "2021-08-26T17:20:31-07:00",
                                    "endTime": "2021-08-26T17:20:31-07:00",
                                    "failureMessage": "",
                                    "documents": [
                                        {
                                            "name": "",
                                            "filePath": "Sample-1.yaml",
                                            "status": "success",
                                            "description": "",
                                            "startTime": "2021-08-26T17:20:31-07:00",
                                            "endTime": "2021-08-26T17:20:31-07:00",
                                            "failureMessage": "",
                                            "phases": [
                                                {
                                                    "name": "build",
                                                    "status": "success",
                                                    "startTime": "2021-08-26T17:20:31-07:00",
                                                    "endTime": "2021-08-26T17:20:31-07:00",
                                                    "failureMessage": "",
                                                    "steps": [
                                                        {
                                                            "name": "ExecuteBashStep",
                                                            "status": "success",
                                                            "failureMessage": "",
                                                            "timeoutSeconds": 7200,
                                                            "onFailure": "Abort",
                                                            "maxAttempts": 1,
                                                            "action": "ExecuteBash",
                                                            "startTime": "2021-08-26T17:20:31-07:00",
                                                            "endTime": "2021-08-26T17:20:31-07:00",
                                                            "inputs": "[{\"commands\":[\"echo \\\"Hello World!\\\"\"]}]",
                                                            "outputs": "[{\"stdout\":\"Hello World!\"}]",
                                                            "loop": null,
                                                            "detailedOutput": null
                                                        }]
                                                }]
                                        }]
                                }]
                        }]
                
                }]
        }]
}
```

### ExecutePowerShell (Windows)
<a name="action-modules-executepowershell"></a>

**ExecutePowerShell** 動作模組可讓您使用內嵌 shell 程式碼/命令執行 PowerShell 指令碼。此模組支援 Windows 平台和 Windows PowerShell。

命令區塊中指定的所有命令/指示都會轉換為指令碼檔案 （例如 `input.ps1`)，並使用 Windows PowerShell 執行。執行 shell 檔案的結果是結束程式碼。

如果 shell 命令以 的結束代碼結束，則 **ExecutePowerShell** 模組會處理系統重新啟動`3010`。啟動時，應用程式會執行下列其中一個動作：
+ 如果由 Systems Manager Agent 執行，則將結束碼交給發起人。Systems Manager 代理程式會處理系統重新啟動，並執行啟動重新啟動的相同步驟，如[從指令碼重新啟動受管執行個體](https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-reboot.html)中所述。
+ 儲存目前的 `executionstate`、設定重新啟動觸發以重新執行應用程式，以及重新啟動系統。

系統重新啟動後，應用程式會執行與啟動重新啟動相同的步驟。如果您需要此功能，則必須撰寫等冪指令碼，以處理相同 shell 命令的多個調用。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| commands | 包含根據 PowerShell 語法執行的指示或命令清單。允許多行 YAML。 | 字串清單 | 是。必須指定 `commands`或 `file`，而非兩者。  | 
| file | 包含 PowerShell 指令碼檔案的路徑。PowerShell 將使用-file命令列引數對此檔案執行。路徑必須指向.ps1檔案。 | String | 是。必須指定 `commands`或 `file`，而非兩者。  | 

**輸入範例：重新啟動之前和之後**

```
name: ExitCode3010Example
description: This shows how the exit code can be used to restart a system with ExecutePowerShell
schemaVersion: 1.0
phases:
  - name: build
    steps:
      - name: RestartTrigger
        action: ExecutePowerShell
        inputs:
          commands:
            - |
              $rebootIndicator = Join-Path -Path $env:SystemDrive -ChildPath 'reboot-indicator'
              if (Test-Path -Path $rebootIndicator) {
                Write-Host 'The reboot file exists. Deleting it and exiting with success.'
                Remove-Item -Path $rebootIndicator -Force | Out-Null
                [System.Environment]::Exit(0)
              }
              Write-Host 'The reboot file does not exist. Creating it and triggering a restart.'
              New-Item -Path $rebootIndicator -ItemType File | Out-Null
              [System.Environment]::Exit(3010)
```


**Output**  

| 欄位 | 說明 | Type | 
| --- | --- | --- | 
| stdout | 命令執行的標準輸出。 | string | 

如果您執行重新啟動並傳回結束程式碼`3010`做為動作模組的一部分，則組建將在啟動重新啟動的相同動作模組步驟繼續。如果您在沒有結束碼的情況下執行重新啟動，建置程序可能會失敗。

**輸出範例：重新啟動之前 （第一次通過文件）**

```
{
	“stdout”: “The reboot file does not exist. Creating it and triggering a restart."
}
```

**輸出範例：重新啟動後， （文件的第二次）**

```
{
	“stdout”: “The reboot file exists. Deleting it and exiting with success."
}
```

## 檔案下載和上傳模組
<a name="action-modules-download-upload"></a>

下一節包含上傳或下載檔案的動作模組詳細資訊。

**Topics**
+ [S3Download (Linux、Windows、macOS)](#action-modules-s3download)
+ [S3Upload (Linux、Windows、macOS)](#action-modules-s3upload)
+ [WebDownload (Linux、Windows、macOS)](#action-modules-webdownload)

### S3Download (Linux、Windows、macOS)
<a name="action-modules-s3download"></a>

使用 `S3Download`動作模組，您可以將 Amazon S3 物件或一組物件下載到您使用 `destination` 路徑指定的本機檔案或資料夾。如果指定位置已存在任何檔案，且 `overwrite`旗標設為 true，則 會`S3Download`覆寫檔案。

您的`source`位置可以指向 Amazon S3 中的特定物件，或者您可以使用帶有星號萬用字元 (`*`) 的金鑰字首來下載一組符合金鑰字首路徑的物件。當您在`source`位置中指定金鑰字首時，`S3Download`動作模組會下載符合字首的所有項目 （包含檔案和資料夾）。請確定金鑰字首結尾是正斜線，後面接著星號 (`/*`)，以便您下載符合字首的所有項目。例如：`s3://my-bucket/my-folder/*`。

如果在下載期間指定金鑰字首`S3Download`的動作失敗，則在失敗之前，資料夾內容不會復原至其狀態。目的地資料夾會維持在失敗時的原狀。

**支援的使用案例**  
`S3Download` 動作模組支援下列使用案例：
+ Amazon S3 物件會下載至本機資料夾，如下載路徑中所指定。
+ Amazon S3 物件 （在 Amazon S3 檔案路徑中具有金鑰字首） 會下載至指定的本機資料夾，以遞迴方式將符合金鑰字首的所有 Amazon S3 物件複製到本機資料夾。

**IAM 要求**  
您與您的執行個體描述檔建立關聯的 IAM 角色必須具有執行 `S3Download`動作模組的許可。下列 IAM 政策必須連接到與執行個體描述檔相關聯的 IAM 角色：
+ **單一檔案**：`s3:GetObject`針對儲存貯體/物件 （例如，`arn:aws:s3:::BucketName/*`)。
+ **多個檔案**：`s3:ListBucket`針對儲存貯體/物件 （例如 `arn:aws:s3:::BucketName`) 和`s3:GetObject`針對儲存貯體/物件 （例如 `arn:aws:s3:::BucketName/*`)。


**Input**  

|  金錀  |  說明  |  Type  |  必要  |  預設  | 
| --- | --- | --- | --- | --- | 
|  `source`  |  下載來源的 Amazon S3 儲存貯體。您可以指定特定物件的路徑，或使用以正斜線結尾的金鑰字首，後面接著星號萬用字元 (`/*`)，以下載一組符合金鑰字首的物件。  |  String  |  是  |  N/A  | 
|  `destination`  |  下載 Amazon S3 物件的本機路徑。若要下載單一檔案，您必須指定檔案名稱做為路徑的一部分。例如 `/myfolder/package.zip`。  |  String  |  是  |  N/A  | 
|  `expectedBucketOwner`  |  `source` 路徑中提供的儲存貯體的預期擁有者帳戶 ID。我們建議您驗證來源中指定之 Amazon S3 儲存貯體的擁有權。  |  String  |  否  |  N/A  | 
|  `overwrite`  |  設為 true 時，如果指定本機路徑的目的地資料夾中已存在同名的檔案，則下載檔案會覆寫本機檔案。設定為 false 時，本機系統上現有的檔案會受到保護，不會遭到覆寫，而且動作模組會失敗並出現下載錯誤。 例如 `Error: S3Download: File already exists and "overwrite" property for "destination" file is set to false. Cannot download.`  |  Boolean  |  否  |  true  | 

**注意**  
對於下列範例，Windows 資料夾路徑可以替換為 Linux 路徑。例如， `C:\myfolder\package.zip` 可以取代為 `/myfolder/package.zip`。

**輸入範例：將 Amazon S3 物件複製到本機檔案**  
下列範例示範如何將 Amazon S3 物件複製到本機檔案。

```
  - name: DownloadMyFile
    action: S3Download
    inputs:
      - source: s3://amzn-s3-demo-source-bucket/path/to/package.zip
        destination: C:\myfolder\package.zip
        expectedBucketOwner: 123456789022
        overwrite: false
      - source: s3://amzn-s3-demo-source-bucket/path/to/package.zip
        destination: C:\myfolder\package.zip
        expectedBucketOwner: 123456789022
        overwrite: true
      - source: s3://amzn-s3-demo-source-bucket/path/to/package.zip
        destination: C:\myfolder\package.zip
        expectedBucketOwner: 123456789022
```

**輸入範例：將 Amazon S3 儲存貯體中具有金鑰字首的所有 Amazon S3 物件複製到本機資料夾**  
下列範例示範如何將 Amazon S3 儲存貯體中具有金鑰字首的所有 Amazon S3 物件複製到本機資料夾。Amazon S3 沒有資料夾的概念，因此會複製符合金鑰字首的所有物件。可下載的物件數量上限為 1000。

```
  - name: MyS3DownloadKeyprefix
    action: S3Download
    maxAttempts: 3
    inputs:
      - source: s3://amzn-s3-demo-source-bucket/path/to/*
        destination: C:\myfolder\
        expectedBucketOwner: 123456789022
        overwrite: false
      - source: s3://amzn-s3-demo-source-bucket/path/to/*
        destination: C:\myfolder\
        expectedBucketOwner: 123456789022
        overwrite: true
      - source: s3://amzn-s3-demo-source-bucket/path/to/*
        destination: C:\myfolder\
        expectedBucketOwner: 123456789022
```

**Output**  
無。

### S3Upload (Linux、Windows、macOS)
<a name="action-modules-s3upload"></a>

使用 **S3Upload** 動作模組，您可以將檔案從來源檔案或資料夾上傳至 Amazon S3 位置。您可以在為來源位置指定的路徑中使用萬用字元 (`*`)，上傳路徑符合萬用字元模式的所有檔案。

如果遞迴 **S3Upload** 動作失敗，任何已上傳的檔案都會保留在目的地 Amazon S3 儲存貯體中。

**支援的使用案例**
+ Amazon S3 物件的本機檔案。
+ 資料夾中的本機檔案 （使用萬用字元） 到 Amazon S3 金鑰字首。
+ 將本機資料夾 （必須`recurse`設定為 `true`) 複製到 Amazon S3 金鑰字首。

**IAM 要求**  
您與您的執行個體描述檔建立關聯的 IAM 角色必須具有執行`S3Upload`動作模組的許可。下列 IAM 政策必須連接到與執行個體描述檔相關聯的 IAM 角色。政策必須授予目標 Amazon S3 儲存貯體的`s3:PutObject`許可。例如，`arn:aws:s3:::BucketName/*`)。


**Input**  

|  金錀  |  說明  |  Type  |  必要  |  預設  | 
| --- | --- | --- | --- | --- | 
|  `source`  |  來源檔案/資料夾來源的本機路徑。`source` 支援星號萬用字元 (`*`)。  |  String  |  是  |  N/A  | 
|  `destination`  |  上傳來源檔案/資料夾的目的地 Amazon S3 儲存貯體路徑。  |  String  |  是  |  N/A  | 
|  `recurse`  |  設定為 時`true`， 會遞迴執行 **S3Upload**。  |  String  |  否  |  `false`  | 
|  `expectedBucketOwner`  |  目的地路徑中指定之 Amazon S3 儲存貯體的預期擁有者帳戶 ID。我們建議您驗證目的地中指定的 Amazon S3 儲存貯體擁有權。  |  String  |  否  |  N/A  | 

**輸入範例：將本機檔案複製到 Amazon S3 物件**  
下列範例示範如何將本機檔案複製到 Amazon S3 物件。

```
  - name: MyS3UploadFile
    action: S3Upload
    onFailure: Abort
    maxAttempts: 3
    inputs:
      - source: C:\myfolder\package.zip
        destination: s3://amzn-s3-demo-destination-bucket/path/to/package.zip
        expectedBucketOwner: 123456789022
```

**輸入範例：將本機資料夾中的所有檔案複製到具有金鑰字首的 Amazon S3 儲存貯體**  
下列範例顯示如何將本機資料夾中的所有檔案複製到具有金鑰字首的 Amazon S3 儲存貯體。此範例不會複製子資料夾或其內容，因為 `recurse` 未指定，且預設為 `false`。

```
  - name: MyS3UploadMultipleFiles
    action: S3Upload
    onFailure: Abort
    maxAttempts: 3
    inputs:
      - source: C:\myfolder\*
        destination: s3://amzn-s3-demo-destination-bucket/path/to/
        expectedBucketOwner: 123456789022
```

**輸入範例：將所有檔案和資料夾從本機資料夾遞迴複製到 Amazon S3 儲存貯體**  
下列範例顯示如何以遞迴方式將所有檔案和資料夾從本機資料夾複製到具有金鑰字首的 Amazon S3 儲存貯體。

```
  - name: MyS3UploadFolder
    action: S3Upload
    onFailure: Abort
    maxAttempts: 3
    inputs:
      - source: C:\myfolder\*
        destination: s3://amzn-s3-demo-destination-bucket/path/to/
        recurse: true
        expectedBucketOwner: 123456789022
```

**Output**  
無。

### WebDownload (Linux、Windows、macOS)
<a name="action-modules-webdownload"></a>

**WebDownload** 動作模組可讓您透過 HTTP/HTTPS 通訊協定從遠端位置下載檔案和資源 (*建議使用 HTTPS*)。下載的數量或大小沒有限制。此模組會處理重試和指數退避邏輯。

根據使用者輸入，每個下載操作最多分配 5 次嘗試成功。這些嘗試與文件 `maxAttempts`欄位中指定的嘗試不同`steps`，這些嘗試與動作模組失敗相關。

此動作模組隱含地處理重新導向。除了 之外，所有 HTTP 狀態碼`200`都會導致錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設 | 
| --- | --- | --- | --- | --- | 
| source | 有效的 HTTP/HTTPS URL (建議使用 HTTPS)，其遵循 RFC 3986 標準。允許鏈結表達式。 | String |  是  | N/A | 
| destination | 本機系統上的絕對或相對檔案或資料夾路徑。資料夾路徑必須以 結尾/。如果它們不是以 結尾/，則會被視為檔案路徑。模組會建立成功下載所需的任何檔案或資料夾。允許鏈結表達式。 | String | 是 | N/A | 
| overwrite | 啟用時， 會使用下載的檔案或資源覆寫本機系統上的任何現有檔案。未啟用時，不會覆寫本機系統上的任何現有檔案，且動作模組會失敗並顯示錯誤。啟用覆寫並指定檢查總和和和演算法時，只有在檢查總和和和任何預先存在檔案的雜湊不相符時，動作模組才會下載檔案。 | Boolean | 否 | true | 
| checksum | 當您指定檢查總和時，會針對使用提供的演算法產生的下載檔案雜湊進行檢查。若要啟用檔案驗證，必須提供檢查總和和和演算法。允許鏈結表達式。 | String | 否 | N/A | 
| algorithm | 用來計算檢查總和的演算法。選項包括 MD5, SHA1, SHA256和 SHA512。若要啟用檔案驗證，必須提供檢查總和和和演算法。允許鏈結表達式。 | String | 否 | N/A | 
| ignoreCertificateErrors | 啟用時，會忽略 SSL 憑證驗證。 | Boolean | 否 | false | 


**Output**  

| 金鑰名稱 | 說明 | Type | 
| --- | --- | --- | 
| destination | 以字元分隔的新行字串，指定存放下載檔案或資源的目的地路徑。 | String | 

**輸入範例：將遠端檔案下載至本機目的地**

```
  - name: DownloadRemoteFile
    action: WebDownload
    maxAttempts: 3
    inputs:
      - source: https://testdomain/path/to/java14.zip
        destination: C:\testfolder\package.zip
```

**輸出：**

```
{
	"destination": "C:\\testfolder\\package.zip"
}
```

**輸入範例：將多個遠端檔案下載到多個本機目的地 **

```
  - name: DownloadRemoteFiles
    action: WebDownload
    maxAttempts: 3
    inputs:
      - source: https://testdomain/path/to/java14.zip
        destination: /tmp/java14_renamed.zip
      - source: https://testdomain/path/to/java14.zip
        destination: /tmp/create_new_folder_and_add_java14_as_zip/
```

**輸出：**

```
{
	"destination": "/tmp/create_new_folder/java14_renamed.zip\n/tmp/create_new_folder_and_add_java14_as_zip/java14.zip"
}
```

**輸入範例：下載一個遠端檔案而不覆寫本機目的地，並使用檔案驗證下載另一個遠端檔案**

```
  - name: DownloadRemoteMultipleProperties
    action: WebDownload
    maxAttempts: 3
    inputs:
      - source: https://testdomain/path/to/java14.zip
        destination: C:\create_new_folder\java14_renamed.zip
        overwrite: false
      - source: https://testdomain/path/to/java14.zip
        destination: C:\create_new_folder_and_add_java14_as_zip\
        checksum: ac68bbf921d953d1cfab916cb6120864
        algorithm: MD5
        overwrite: true
```

**輸出：**

```
{
	"destination": "C:\\create_new_folder\\java14_renamed.zip\nC:\\create_new_folder_and_add_java14_as_zip\\java14.zip"
}
```

**輸入範例：下載遠端檔案並忽略 SSL 憑證驗證**

```
  - name: DownloadRemoteIgnoreValidation
    action: WebDownload
    maxAttempts: 3
    inputs:
      - source: https://www.bad-ssl.com/resource
        destination: /tmp/downloads/
        ignoreCertificateErrors: true
```

**輸出：**

```
{
	"destination": "/tmp/downloads/resource"
}
```

## 檔案系統操作模組
<a name="action-modules-file-system-operations"></a>

下一節包含執行檔案系統操作之動作模組的詳細資訊。

**Topics**
+ [AppendFile (Linux、Windows、macOS)](#action-modules-appendfile)
+ [CopyFile (Linux、Windows、macOS)](#action-modules-copyfile)
+ [CopyFolder (Linux、Windows、macOS)](#action-modules-copyfolder)
+ [CreateFile (Linux、Windows、macOS)](#action-modules-createfile)
+ [CreateFolder (Linux、Windows、macOS)](#action-modules-createfolder)
+ [CreateSymlink (Linux、Windows、macOS)](#action-modules-createsymlink)
+ [DeleteFile (Linux、Windows、macOS)](#action-modules-deletefile)
+ [DeleteFolder (Linux、Windows、macOS)](#action-modules-deletefolder)
+ [ListFiles (Linux、Windows、macOS)](#action-modules-listfiles)
+ [MoveFile (Linux、Windows、macOS)](#action-modules-movefile)
+ [MoveFolder (Linux、Windows、macOS)](#action-modules-movefolder)
+ [ReadFile (Linux、Windows、macOS)](#action-modules-readfile)
+ [SetFileEncoding (Linux、Windows、macOS)](#action-modules-setfileencoding)
+ [SetFileOwner (Linux、Windows、macOS)](#action-modules-setfileowner)
+ [SetFolderOwner (Linux、Windows、macOS)](#action-modules-setfolderowner)
+ [SetFilePermissions (Linux、Windows、macOS)](#action-modules-setfilepermissions)
+ [SetFolderPermissions (Linux、Windows、macOS)](#action-modules-setfolderpermissions)

### AppendFile (Linux、Windows、macOS)
<a name="action-modules-appendfile"></a>

**AppendFile** 動作模組會將指定的內容新增至檔案的預先存在內容。

如果檔案編碼值與預設編碼 (`utf-8`) 值不同，您可以使用 `encoding`選項指定檔案編碼值。根據預設， `utf-16`和 `utf-32` 會假設使用小端點編碼。

發生下列情況時，動作模組會傳回錯誤：
+ 指定的檔案在執行時間不存在。
+ 您沒有修改檔案內容的寫入許可。
+ 模組在檔案操作期間遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| content | 要附加至 檔案的內容。 | String | 否 | 空字串 | N/A | 是 | 
| encoding | 編碼標準。 | String | 否 | utf8 | utf8、utf-8、utf16、utf-16、utf16-LEutf-16-LEutf16-BE、、utf-16-BE、utf32、utf-32、utf32-LEutf-32-LE、 utf32-BE和  utf-32-BE。編碼選項的值不區分大小寫。 | 是 | 

**輸入範例：附加不含編碼的檔案 (Linux)**

```
  - name: AppendingFileWithOutEncodingLinux
    action: AppendFile
    inputs:
      - path: ./Sample.txt
        content: "The string to be appended to the file"
```

**輸入範例：附加不含編碼的檔案 (Windows)**

```
  - name: AppendingFileWithOutEncodingWindows
    action: AppendFile
    inputs:
      - path: C:\MyFolder\MyFile.txt
        content: "The string to be appended to the file"
```

**輸入範例：使用編碼附加檔案 (Linux)**

```
  - name: AppendingFileWithEncodingLinux
    action: AppendFile
    inputs:
      - path: /FolderName/SampleFile.txt
        content: "The string to be appended to the file"
        encoding: UTF-32
```

**輸入範例：使用編碼附加檔案 (Windows)**

```
  - name: AppendingFileWithEncodingWindows
    action: AppendFile
    inputs:
      - path: C:\MyFolderName\SampleFile.txt
        content: "The string to be appended to the file"
        encoding: UTF-32
```

**輸入範例：附加具有空字串的檔案 (Linux)**

```
  - name: AppendingEmptyStringLinux
    action: AppendFile
    inputs:
      - path: /FolderName/SampleFile.txt
```

**輸入範例：附加具有空字串的檔案 (Windows)**

```
  - name: AppendingEmptyStringWindows
    action: AppendFile
    inputs:
      - path: C:\MyFolderName\SampleFile.txt
```

**Output**  
無。

### CopyFile (Linux、Windows、macOS)
<a name="action-modules-copyfile"></a>

**CopyFile** 動作模組會將檔案從指定的來源複製到指定的目的地。根據預設，如果在執行時間不存在，模組會遞迴建立目的地資料夾。

如果指定名稱的檔案已存在於指定的資料夾中，動作模組預設會覆寫現有的檔案。您可以將覆寫選項設定為 來覆寫此預設行為`false`。當覆寫選項設定為 `false`，且指定位置中已有具有指定名稱的檔案時，動作模組會傳回錯誤。此選項的運作方式與 Linux 中的 `cp`命令相同，預設會覆寫該命令。

來源檔案名稱可以包含萬用字元 (`*`)。只有在最後一個檔案路徑分隔符號 (`/` 或 `\`) 之後，才會接受萬用字元。如果來源檔案名稱中包含萬用字元，則符合萬用字元的所有檔案都會複製到目的地資料夾。如果您想要使用萬用字元移動多個檔案， `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 `\`) 結尾，這表示目的地輸入是資料夾。

如果目的地檔案名稱與來源檔案名稱不同，您可以使用 `destination`選項指定目的地檔案名稱。如果您未指定目的地檔案名稱，則會使用來源檔案名稱來建立目的地檔案。遵循最後一個檔案路徑分隔符號 (`/` 或 `\`) 的任何文字都會視為檔案名稱。如果您想要使用與來源檔案相同的檔案名稱，則 `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 ) 結尾`\`。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有在指定資料夾中建立檔案的許可。
+ 來源檔案在執行時間不存在。
+ 已有具有指定檔案名稱的資料夾，且 `overwrite`選項設定為 `false`。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| source | 來源檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| destination | 目的地檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| overwrite | 設定為 false 時，如果指定位置中已有具有指定名稱的檔案，則不會取代目的地檔案。 | Boolean | 否 | true | N/A | 是 | 

**輸入範例：複製檔案 (Linux)**

```
  - name: CopyingAFileLinux
    action: CopyFile
    inputs:
      - source: /Sample/MyFolder/Sample.txt
        destination: /MyFolder/destinationFile.txt
```

**輸入範例：複製檔案 (Windows)**

```
  - name: CopyingAFileWindows
    action: CopyFile
    inputs:
      - source: C:\MyFolder\Sample.txt
        destination: C:\MyFolder\destinationFile.txt
```

**輸入範例：使用來源檔案名稱 (Linux) 複製檔案**

```
  - name: CopyingFileWithSourceFileNameLinux
    action: CopyFile
    inputs:
      - source: /Sample/MyFolder/Sample.txt
        destination: /MyFolder/
```

**輸入範例：使用來源檔案名稱 (Windows) 複製檔案**

```
  - name: CopyingFileWithSourceFileNameWindows
    action: CopyFile
    inputs:
      - source: C:\Sample\MyFolder\Sample.txt
        destination: C:\MyFolder\
```

**輸入範例：使用萬用字元 (Linux) 複製檔案**

```
  - name: CopyingFilesWithWildCardLinux
    action: CopyFile
    inputs:
      - source: /Sample/MyFolder/Sample*
        destination: /MyFolder/
```

**輸入範例：使用萬用字元複製檔案 (Windows)**

```
  - name: CopyingFilesWithWildCardWindows
    action: CopyFile
    inputs:
      - source: C:\Sample\MyFolder\Sample*
        destination: C:\MyFolder\
```

**輸入範例：複製檔案而不覆寫 (Linux)**

```
  - name: CopyingFilesWithoutOverwriteLinux
    action: CopyFile
    inputs:
      - source: /Sample/MyFolder/Sample.txt
        destination: /MyFolder/destinationFile.txt
        overwrite: false
```

**輸入範例：複製檔案而不覆寫 (Windows)**

```
  - name: CopyingFilesWithoutOverwriteWindows
    action: CopyFile
    inputs:
      - source: C:\Sample\MyFolder\Sample.txt
        destination: C:\MyFolder\destinationFile.txt
        overwrite: false
```

**Output**  
無。

### CopyFolder (Linux、Windows、macOS)
<a name="action-modules-copyfolder"></a>

**CopyFolder** 動作模組會將資料夾從指定的來源複製到指定的目的地。`source` 選項的輸入是要複製的資料夾，`destination`而選項的輸入是複製來源資料夾內容的資料夾。根據預設，如果在執行時間不存在，模組會遞迴建立目的地資料夾。

如果指定名稱的資料夾已存在於指定的資料夾中，則動作模組預設會覆寫現有的資料夾。您可以將覆寫選項設定為 來覆寫此預設行為`false`。當覆寫選項設定為 `false`，且指定位置中已有具有指定名稱的資料夾時，動作模組將傳回錯誤。

來源資料夾名稱可以包含萬用字元 (`*`)。只有在最後一個檔案路徑分隔符號 (`/` 或 `\`) 之後，才會接受萬用字元。如果來源資料夾名稱中包含萬用字元，則符合萬用字元的所有資料夾都會複製到目的地資料夾。如果您想要使用萬用字元複製多個資料夾， `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 `\`) 結尾，這表示目的地輸入是資料夾。

如果目的地資料夾名稱與來源資料夾名稱不同，您可以使用 `destination`選項指定目的地資料夾名稱。如果您未指定目的地資料夾名稱，則會使用來源資料夾的名稱來建立目的地資料夾。最後一個檔案路徑分隔符號 (`/` 或 `\`) 之後的任何文字都會視為資料夾名稱。如果您想要使用與來源資料夾相同的資料夾名稱，則 `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 ) 結尾`\`。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有在指定資料夾中建立資料夾的許可。
+ 來源資料夾在執行時間不存在。
+ 已有具有指定資料夾名稱的資料夾，且 `overwrite`選項設定為 `false`。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| source | 來源資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| destination | 目的地資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| overwrite | 設定為 false 時，如果指定位置中已有具有指定名稱的資料夾，則不會取代目的地資料夾。 | Boolean | 否 | true | N/A | 是 | 

**輸入範例：複製資料夾 (Linux)**

```
  - name: CopyingAFolderLinux
    action: CopyFolder
    inputs:
      - source: /Sample/MyFolder/SampleFolder
        destination: /MyFolder/destinationFolder
```

**輸入範例：複製資料夾 (Windows)**

```
  - name: CopyingAFolderWindows
    action: CopyFolder
    inputs:
      - source: C:\Sample\MyFolder\SampleFolder
        destination: C:\MyFolder\destinationFolder
```

**輸入範例：使用來源資料夾名稱 (Linux) 複製資料夾**

```
  - name: CopyingFolderSourceFolderNameLinux
    action: CopyFolder
    inputs:
      - source: /Sample/MyFolder/SourceFolder
        destination: /MyFolder/
```

**輸入範例：使用來源資料夾名稱 (Windows) 複製資料夾**

```
  - name: CopyingFolderSourceFolderNameWindows
    action: CopyFolder
    inputs:
      - source: C:\Sample\MyFolder\SampleFolder
        destination: C:\MyFolder\
```

**輸入範例：使用萬用字元 (Linux) 複製資料夾**

```
  - name: CopyingFoldersWithWildCardLinux
    action: CopyFolder
    inputs:
      - source: /Sample/MyFolder/Sample*
        destination: /MyFolder/
```

**輸入範例：使用萬用字元複製資料夾 (Windows)**

```
  - name: CopyingFoldersWithWildCardWindows
    action: CopyFolder
    inputs:
      - source: C:\Sample\MyFolder\Sample*
        destination: C:\MyFolder\
```

**輸入範例：複製資料夾而不覆寫 (Linux)**

```
  - name: CopyingFoldersWithoutOverwriteLinux
    action: CopyFolder
    inputs:
      - source: /Sample/MyFolder/SourceFolder
        destination: /MyFolder/destinationFolder
        overwrite: false
```

**輸入範例：複製資料夾而不覆寫 (Windows)**

```
  - name: CopyingFoldersWithoutOverwrite
    action: CopyFolder
    inputs:
      - source: C:\Sample\MyFolder\SourceFolder
        destination: C:\MyFolder\destinationFolder
        overwrite: false
```

**Output**  
無。

### CreateFile (Linux、Windows、macOS)
<a name="action-modules-createfile"></a>

**CreateFile** 動作模組會在指定的位置建立檔案。根據預設，如果需要，模組也會以遞迴方式建立父資料夾。

如果檔案已存在於指定的資料夾中，動作模組預設會截斷或覆寫現有的檔案。您可以將覆寫選項設定為 來覆寫此預設行為`false`。當覆寫選項設定為 `false`，且指定位置中已有具有指定名稱的檔案時，動作模組會傳回錯誤。

如果檔案編碼值與預設編碼 (`utf-8`) 值不同，您可以使用 `encoding`選項指定檔案編碼值。根據預設， `utf-16`和 `utf-32` 會假設使用小端點編碼。

`owner`、 `group`和 `permissions`是選用的輸入。的輸入`permissions`必須是字串值。若未提供，則會使用預設值建立檔案。Windows 平台不支援這些選項。如果 Windows 平台上使用 `owner`、 和 `permissions`選項`group`，此動作模組會驗證並傳回錯誤。

此動作模組可以建立具有作業系統`umask`預設值所定義許可的檔案 。如果您想要覆寫預設值，則必須設定 `umask` 值。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有在指定的父資料夾中建立檔案或資料夾的許可。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| content | 檔案的文字內容。 | String | 否 | N/A | N/A | 是 | 
| encoding | 編碼標準。 | String | 否 | utf8 | utf8、utf-8、utf16、utf-16、utf16-LEutf-16-LEutf16-BE、、utf-16-BE、utf32、utf-32、utf32-LEutf-32-LE、 utf32-BE和  utf-32-BE。編碼選項的值不區分大小寫。 | 是 | 
| owner | 使用者名稱或 ID。 | String | 否 | N/A | N/A | Windows 不支援。 | 
| group | 群組名稱或 ID。 | String | 否 | 目前的使用者。 | N/A | Windows 不支援。 | 
| permissions | 檔案許可。 | String | 否 | 0666 | N/A | Windows 不支援。 | 
| overwrite | 如果指定的檔案名稱已存在，請將此值設定為false防止預設截斷或覆寫檔案。 | Boolean | 否 | true | N/A | 是 | 

**輸入範例：建立檔案而不覆寫 (Linux)**

```
  - name: CreatingFileWithoutOverwriteLinux
    action: CreateFile
    inputs:
      - path: /home/UserName/Sample.txt
        content: The text content of the sample file.
        overwrite: false
```

**輸入範例：建立檔案而不覆寫 (Windows)**

```
  - name: CreatingFileWithoutOverwriteWindows
    action: CreateFile
    inputs:
      - path: C:\Temp\Sample.txt
        content: The text content of the sample file.
        overwrite: false
```

**輸入範例：建立具有檔案屬性的檔案**

```
  - name: CreatingFileWithFileProperties
    action: CreateFile
    inputs:
      - path: SampleFolder/Sample.txt
        content: The text content of the sample file.
        encoding: UTF-16
        owner: Ubuntu
        group: UbuntuGroup
        permissions: 0777
     - path: SampleFolder/SampleFile.txt
        permissions: 755
      - path: SampleFolder/TextFile.txt
        encoding: UTF-16
        owner: root
        group: rootUserGroup
```

**輸入範例：建立不含檔案屬性的檔案**

```
  - name: CreatingFileWithoutFileProperties
    action: CreateFile
    inputs:
      - path: ./Sample.txt
      - path: Sample1.txt
```

**輸入範例：建立空白檔案以略過 Linux 清除指令碼中的區段**

```
  - name: CreateSkipCleanupfile
    action: CreateFile
    inputs:
      - path: <skip section file name>
```

如需詳細資訊，請參閱[覆寫 Linux 清除指令碼](security-best-practices.md#override-linux-cleanup-script)

**Output**  
無。

### CreateFolder (Linux、Windows、macOS)
<a name="action-modules-createfolder"></a>

**CreateFolder** 動作模組會在指定位置建立資料夾。根據預設，如果需要，模組也會以遞迴方式建立父資料夾。

如果資料夾已存在於指定的資料夾中，動作模組預設會截斷或覆寫現有的資料夾。您可以將覆寫選項設定為 來覆寫此預設行為`false`。當覆寫選項設定為 `false`，且指定位置中已有具有指定名稱的資料夾時，動作模組將傳回錯誤。

`owner`、 `group`和 `permissions`是選用的輸入。的輸入`permissions`必須是字串值。Windows 平台不支援這些選項。如果 Windows 平台上使用 `owner`、 和 `permissions`選項`group`，此動作模組會驗證並傳回錯誤。

此動作模組可以建立具有作業系統`umask`預設值所定義許可的 資料夾。如果您想要覆寫預設值，則必須設定 `umask` 值。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有在指定位置建立資料夾的許可。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| owner | 使用者名稱或 ID。 | String | 否 | 目前的使用者。 | N/A | Windows 不支援。 | 
| group | 群組名稱或 ID。 | String | 否 | 目前使用者的群組。 | N/A | Windows 不支援。 | 
| permissions | 資料夾許可。 | String | 否 | 0777 | N/A | Windows 不支援。 | 
| overwrite | 如果指定的檔案名稱已存在，請將此值設定為false防止預設截斷或覆寫檔案。 | Boolean | 否 | true | N/A | 是 | 

**輸入範例：建立資料夾 (Linux)**

```
  - name: CreatingFolderLinux
    action: CreateFolder
    inputs:
      - path: /Sample/MyFolder/
```

**輸入範例：建立資料夾 (Windows)**

```
  - name: CreatingFolderWindows
    action: CreateFolder
    inputs:
      - path: C:\MyFolder
```

**輸入範例：建立指定資料夾屬性的資料夾**

```
  - name: CreatingFolderWithFolderProperties
    action: CreateFolder
    inputs:
      - path: /Sample/MyFolder/Sample/
        owner: SampleOwnerName
        group: SampleGroupName
        permissions: 0777
      - path: /Sample/MyFolder/SampleFoler/
        permissions: 777
```

**輸入範例：如果有，請建立覆寫現有資料夾的資料夾。**

```
  - name: CreatingFolderWithOverwrite
    action: CreateFolder
    inputs:
      - path: /Sample/MyFolder/Sample/
        overwrite: true
```

**Output**  
無。

### CreateSymlink (Linux、Windows、macOS)
<a name="action-modules-createsymlink"></a>

**CreateSymlink** 動作模組會建立符號連結，或包含另一個檔案參考的檔案。Windows 平台不支援此模組。

`path` 和 `target`選項的輸入可以是絕對或相對路徑。如果 `path`選項的輸入是相對路徑，則會在建立連結時將其取代為絕對路徑。

根據預設，當具有指定名稱的連結已存在於指定的資料夾中時，動作模組會傳回錯誤。您可以將 `force`選項設定為 ，以覆寫此預設行為`true`。當 `force`選項設定為 時`true`，模組會覆寫現有的連結。

如果父資料夾不存在，動作模組預設會以遞迴方式建立資料夾。

發生下列情況時，動作模組會傳回錯誤：
+ 目標檔案在執行時間不存在。
+ 具有指定名稱的非符號連結檔案已存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| target | 符號連結指向的目標檔案路徑。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| force | 當具有相同名稱的連結已存在時，強制建立連結。 | Boolean | 否 | false | N/A | Windows 不支援。 | 

**輸入範例：建立符號連結，強制建立連結**

```
  - name: CreatingSymbolicLinkWithForce
    action: CreateSymlink
    inputs:
      - path: /Folder2/Symboliclink.txt
        target: /Folder/Sample.txt
        force: true
```

**輸入範例：建立不會強制建立連結的符號連結**

```
  - name: CreatingSymbolicLinkWithOutForce
    action: CreateSymlink
    inputs:
      - path: Symboliclink.txt
        target: /Folder/Sample.txt
```

**Output**  
無。

### DeleteFile (Linux、Windows、macOS)
<a name="action-modules-deletefile"></a>

**DeleteFile** 動作模組會刪除指定位置中的檔案。

的輸入`path`應該是有效的檔案路徑，或檔案名稱中包含萬用字元 (`*`) 的檔案路徑。在檔案名稱中指定萬用字元時，將刪除相同資料夾中與萬用字元相符的所有檔案。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行刪除操作的許可。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | 是 | 

**輸入範例：刪除單一檔案 (Linux)**

```
  - name: DeletingSingleFileLinux
    action: DeleteFile
    inputs:
      - path: /SampleFolder/MyFolder/Sample.txt
```

**輸入範例：刪除單一檔案 (Windows)**

```
  - name: DeletingSingleFileWindows
    action: DeleteFile
    inputs:
      - path: C:\SampleFolder\MyFolder\Sample.txt
```

**輸入範例：刪除結尾為 "log" (Linux) 的檔案**

```
  - name: DeletingFileEndingWithLogLinux
    action: DeleteFile
    inputs:
      - path: /SampleFolder/MyFolder/*log
```

**輸入範例：刪除結尾為 "log" (Windows) 的檔案**

```
  - name: DeletingFileEndingWithLogWindows
    action: DeleteFile
    inputs:
      - path: C:\SampleFolder\MyFolder\*log
```

**輸入範例：刪除指定資料夾中的所有檔案 (Linux)**

```
  - name: DeletingAllFilesInAFolderLinux
    action: DeleteFile
    inputs:
      - path: /SampleFolder/MyFolder/*
```

**輸入範例：刪除指定資料夾中的所有檔案 (Windows)**

```
  - name: DeletingAllFilesInAFolderWindows
    action: DeleteFile
    inputs:
      - path: C:\SampleFolder\MyFolder\*
```

**Output**  
無。

### DeleteFolder (Linux、Windows、macOS)
<a name="action-modules-deletefolder"></a>

**DeleteFolder** 動作模組會刪除資料夾。

如果資料夾不是空的，您必須將 `force`選項設定為 ，`true`以移除資料夾及其內容。如果您未將 `force`選項設定為 `true`，且您嘗試刪除的資料夾不是空的，動作模組會傳回錯誤。`force` 選項的預設值為 `false`。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行刪除操作的許可。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| force | 無論資料夾是否為空，都會移除資料夾。 | Boolean | 否 | false | N/A | 是 | 

**輸入範例：使用 `force`選項 (Linux) 刪除非空白的資料夾** 

```
  - name: DeletingFolderWithForceOptionLinux
    action: DeleteFolder
    inputs:
      - path: /Sample/MyFolder/Sample/
        force: true
```

**輸入範例：使用 `force`選項 (Windows) 刪除非空白的資料夾** 

```
  - name: DeletingFolderWithForceOptionWindows
    action: DeleteFolder
    inputs:
      - path: C:\Sample\MyFolder\Sample\
        force: true
```

**輸入範例：刪除資料夾 (Linux)** 

```
  - name: DeletingFolderWithOutForceLinux
    action: DeleteFolder
    inputs:
      - path: /Sample/MyFolder/Sample/
```

**輸入範例：刪除資料夾 (Windows)** 

```
  - name: DeletingFolderWithOutForce
    action: DeleteFolder
    inputs:
      - path: C:\Sample\MyFolder\Sample\
```

**Output**  
無。

### ListFiles (Linux、Windows、macOS)
<a name="action-modules-listfiles"></a>

**ListFiles** 動作模組會列出指定資料夾中的檔案。當遞迴選項設定為 時`true`，它會列出子資料夾中的檔案。根據預設，此模組不會列出子資料夾中的檔案。

若要列出名稱符合指定模式的所有檔案，請使用 `fileNamePattern`選項來提供模式。`fileNamePattern` 選項接受萬用字元 (`*`) 值。提供 `fileNamePattern` 時，會傳回符合指定檔案名稱格式的所有檔案。

發生下列情況時，動作模組會傳回錯誤：
+ 指定的資料夾在執行時間不存在。
+ 您沒有在指定的父資料夾中建立檔案或資料夾的許可。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| fileNamePattern | 要比對的模式，以列出名稱符合模式的所有檔案。 | String | 否 | N/A | N/A | 是 | 
| recursive | 以遞迴方式列出資料夾中的檔案。 | Boolean | 否 | false | N/A | 是 | 

**輸入範例：列出指定資料夾中的檔案 (Linux)**

```
  - name: ListingFilesInSampleFolderLinux
    action: ListFiles
    inputs:
      - path: /Sample/MyFolder/Sample
```

**輸入範例：列出指定資料夾中的檔案 (Windows)**

```
  - name: ListingFilesInSampleFolderWindows
    action: ListFiles
    inputs:
      - path: C:\Sample\MyFolder\Sample
```

**輸入範例：列出結尾為 "log" (Linux) 的檔案**

```
  - name: ListingFilesWithEndingWithLogLinux
    action: ListFiles
    inputs:
      - path: /Sample/MyFolder/
        fileNamePattern: *log
```

**輸入範例：列出結尾為 "log" (Windows) 的檔案**

```
  - name: ListingFilesWithEndingWithLogWindows
    action: ListFiles
    inputs:
      - path: C:\Sample\MyFolder\
        fileNamePattern: *log
```

**輸入範例：遞迴列出檔案**

```
  - name: ListingFilesRecursively
    action: ListFiles
    inputs:
      - path: /Sample/MyFolder/
        recursive: true
```


**Output**  

| 金鑰名稱 | 說明 | Type | 
| --- | --- | --- | 
| files | 檔案的清單。 | String | 

**輸出範例**

```
{
	"files": "/sample1.txt,/sample2.txt,/sample3.txt"
}
```

### MoveFile (Linux、Windows、macOS)
<a name="action-modules-movefile"></a>

**MoveFile** 動作模組會將檔案從指定的來源移至指定的目的地。

如果檔案已存在於指定的資料夾中，動作模組預設會覆寫現有的檔案。您可以將覆寫選項設定為 來覆寫此預設行為`false`。當覆寫選項設定為 `false`，且指定位置中已有具有指定名稱的檔案時，動作模組會傳回錯誤。此選項的運作方式與 Linux 中的 `mv`命令相同，預設會覆寫該命令。

來源檔案名稱可以包含萬用字元 (`*`)。只有在最後一個檔案路徑分隔符號 (`/` 或 `\`) 之後，才會接受萬用字元。如果來源檔案名稱中包含萬用字元，則符合萬用字元的所有檔案都會複製到目的地資料夾。如果您想要使用萬用字元移動多個檔案， `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 `\`) 結尾，這表示目的地輸入是資料夾。

如果目的地檔案名稱與來源檔案名稱不同，您可以使用 `destination`選項指定目的地檔案名稱。如果您未指定目的地檔案名稱，則會使用來源檔案名稱來建立目的地檔案。遵循最後一個檔案路徑分隔符號 (`/` 或 `\`) 的任何文字都會視為檔案名稱。如果您想要使用與來源檔案相同的檔案名稱，則 `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 ) 結尾`\`。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有在指定資料夾中建立檔案的許可。
+ 來源檔案在執行時間不存在。
+ 已有具有指定檔案名稱的資料夾，且 `overwrite`選項設定為 `false`。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| source | 來源檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| destination | 目的地檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| overwrite | 設定為 false 時，如果指定位置中已有具有指定名稱的檔案，則不會取代目的地檔案。 | Boolean | 否 | true | N/A | 是 | 

**輸入範例：移動檔案 (Linux)**

```
  - name: MovingAFileLinux
    action: MoveFile
    inputs:
      - source: /Sample/MyFolder/Sample.txt
        destination: /MyFolder/destinationFile.txt
```

**輸入範例：移動檔案 (Windows)**

```
  - name: MovingAFileWindows
    action: MoveFile
    inputs:
      - source: C:\Sample\MyFolder\Sample.txt
        destination: C:\MyFolder\destinationFile.txt
```

**輸入範例：使用來源檔案名稱 (Linux) 移動檔案**

```
  - name: MovingFileWithSourceFileNameLinux
    action: MoveFile
    inputs:
      - source: /Sample/MyFolder/Sample.txt
        destination: /MyFolder/
```

**輸入範例：使用來源檔案名稱 (Windows) 移動檔案**

```
  - name: MovingFileWithSourceFileNameWindows
    action: MoveFile
    inputs:
      - source: C:\Sample\MyFolder\Sample.txt
        destination: C:\MyFolder
```

**輸入範例：使用萬用字元 (Linux) 移動檔案**

```
  - name: MovingFilesWithWildCardLinux
    action: MoveFile
    inputs:
      - source: /Sample/MyFolder/Sample*
        destination: /MyFolder/
```

**輸入範例：使用萬用字元 (Windows) 移動檔案**

```
  - name: MovingFilesWithWildCardWindows
    action: MoveFile
    inputs:
      - source: C:\Sample\MyFolder\Sample*
        destination: C:\MyFolder
```

**輸入範例：在不覆寫的情況下移動檔案 (Linux)**

```
  - name: MovingFilesWithoutOverwriteLinux
    action: MoveFile
    inputs:
      - source: /Sample/MyFolder/Sample.txt
        destination: /MyFolder/destinationFile.txt
        overwrite: false
```

**輸入範例：在不覆寫的情況下移動檔案 (Windows)**

```
  - name: MovingFilesWithoutOverwrite
    action: MoveFile
    inputs:
      - source: C:\Sample\MyFolder\Sample.txt
        destination: C:\MyFolder\destinationFile.txt
        overwrite: false
```

**Output**  
無。

### MoveFolder (Linux、Windows、macOS)
<a name="action-modules-movefolder"></a>

**MoveFolder** 動作模組會將資料夾從指定的來源移至指定的目的地。`source` 選項的輸入是要移動的資料夾，`destination`而選項的輸入是來源資料夾內容被移動的資料夾。

如果目的地父資料夾或 `destination`選項的輸入在執行時間不存在，則模組的預設行為是在指定的目的地以遞迴方式建立資料夾。

如果與來源資料夾相同的資料夾已存在於目的地資料夾中，則動作模組預設會覆寫現有的資料夾。您可以將覆寫選項設定為 來覆寫此預設行為`false`。當覆寫選項設定為 `false`，且指定位置中已有具有指定名稱的資料夾時，動作模組將傳回錯誤。

來源資料夾名稱可以包含萬用字元 (`*`)。只有在最後一個檔案路徑分隔符號 (`/` 或 `\`) 之後，才會接受萬用字元。如果來源資料夾名稱中包含萬用字元，則符合萬用字元的所有資料夾都會複製到目的地資料夾。如果您想要使用萬用字元移動多個資料夾， `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 `\`) 結尾，這表示目的地輸入是資料夾。

如果目的地資料夾名稱與來源資料夾名稱不同，您可以使用 `destination`選項指定目的地資料夾名稱。如果您未指定目的地資料夾名稱，則會使用來源資料夾的名稱來建立目的地資料夾。最後一個檔案路徑分隔符號 (`/` 或 `\`) 之後的任何文字都會視為資料夾名稱。如果您想要使用與來源資料夾相同的資料夾名稱，則 `destination`選項的輸入必須以檔案路徑分隔符號 (`/` 或 ) 結尾`\`。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有在目的地資料夾中建立資料夾的許可。
+ 來源資料夾在執行時間不存在。
+ 已有具有指定名稱的資料夾，且 `overwrite`選項設定為 `false`。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| source | 來源資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| destination | 目的地資料夾路徑。 | String | 是 | N/A | N/A | 是 | 
| overwrite | 設定為 false 時，如果指定位置中已有具有指定名稱的資料夾，則不會取代目的地資料夾。 | Boolean | 否 | true | N/A | 是 | 

**輸入範例：移動資料夾 (Linux)**

```
  - name: MovingAFolderLinux
    action: MoveFolder
    inputs:
      - source: /Sample/MyFolder/SourceFolder
        destination: /MyFolder/destinationFolder
```

**輸入範例：移動資料夾 (Windows)**

```
  - name: MovingAFolderWindows
    action: MoveFolder
    inputs:
      - source: C:\Sample\MyFolder\SourceFolder
        destination: C:\MyFolder\destinationFolder
```

**輸入範例：使用來源資料夾名稱 (Linux) 移動資料夾**

```
  - name: MovingFolderWithSourceFolderNameLinux
    action: MoveFolder
    inputs:
      - source: /Sample/MyFolder/SampleFolder
        destination: /MyFolder/
```

**輸入範例：使用來源資料夾名稱 (Windows) 移動資料夾**

```
  - name: MovingFolderWithSourceFolderNameWindows
    action: MoveFolder
    inputs:
      - source: C:\Sample\MyFolder\SampleFolder
        destination: C:\MyFolder\
```

**輸入範例：使用萬用字元 (Linux) 移動資料夾**

```
  - name: MovingFoldersWithWildCardLinux
    action: MoveFolder
    inputs:
      - source: /Sample/MyFolder/Sample*
        destination: /MyFolder/
```

**輸入範例：使用萬用字元 (Windows) 移動資料夾**

```
  - name: MovingFoldersWithWildCardWindows
    action: MoveFolder
    inputs:
      - source: C:\Sample\MyFolder\Sample*
        destination: C:\MyFolder\
```

**輸入範例：在不覆寫的情況下移動資料夾 (Linux)**

```
  - name: MovingFoldersWithoutOverwriteLinux
    action: MoveFolder
    inputs:
      - source: /Sample/MyFolder/SampleFolder
    destination: /MyFolder/destinationFolder
    overwrite: false
```

**輸入範例：在不覆寫的情況下移動資料夾 (Windows)**

```
  - name: MovingFoldersWithoutOverwriteWindows
    action: MoveFolder
    inputs:
      - source: C:\Sample\MyFolder\SampleFolder
        destination: C:\MyFolder\destinationFolder
        overwrite: false
```

**Output**  
無。

### ReadFile (Linux、Windows、macOS)
<a name="action-modules-readfile"></a>

**ReadFile** 動作模組會讀取類型字串的文字檔案內容。此模組可用來讀取檔案的內容，以便透過鏈結或將資料讀取至`console.log`檔案的後續步驟中使用。如果指定的路徑是符號連結，則此模組會傳回目標檔案的內容。此模組僅支援文字檔案。

如果檔案編碼值與預設編碼 (`utf-8`) 值不同，您可以使用 `encoding`選項指定檔案編碼值。根據預設， `utf-16`和 `utf-32` 會假設使用小端點編碼。

根據預設，此模組無法將檔案內容列印至 `console.log` 檔案。您可以將 `printFileContent` 屬性設定為 來覆寫此設定`true`。

此模組只能傳回檔案的內容。它無法剖析檔案，例如 Excel 或 JSON 檔案。

發生下列情況時，動作模組會傳回錯誤：
+ 檔案在執行時間不存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| encoding | 編碼標準。 | String | 否 | utf8 | utf8、utf-8、utf16、utf-16、utf16-LEutf-16-LEutf16-BE、、utf-16-BE、utf32、utf-32、utf32-LEutf-32-LE、 utf32-BE和  utf-32-BE。編碼選項的值不區分大小寫。 | 是 | 
| printFileContent | 將檔案內容列印至 console.log 檔案。 | Boolean | 否 | false | N/A | 是。 | 

**輸入範例：讀取檔案 (Linux)**

```
  - name: ReadingFileLinux
    action: ReadFile
    inputs:
      - path: /home/UserName/SampleFile.txt
```

**輸入範例：讀取檔案 (Windows)**

```
  - name: ReadingFileWindows
    action: ReadFile
    inputs:
      - path: C:\Windows\WindowsUpdate.log
```

**輸入範例：讀取檔案並指定編碼標準**

```
  - name: ReadingFileWithFileEncoding
    action: ReadFile
    inputs:
      - path: /FolderName/SampleFile.txt
        encoding: UTF-32
```

**輸入範例：讀取檔案並列印至`console.log`檔案**

```
  - name: ReadingFileToConsole
    action: ReadFile
    inputs:
      - path: /home/UserName/SampleFile.txt
        printFileContent: true
```


**Output**  

| 欄位 | 說明 | Type | 
| --- | --- | --- | 
| content | 檔案內容。 | string | 

**輸出範例**

```
{
	"content" : "The file content"
}
```

### SetFileEncoding (Linux、Windows、macOS)
<a name="action-modules-setfileencoding"></a>

**SetFileEncoding** 動作模組會修改現有檔案的編碼屬性。此模組可以將檔案編碼從 `utf-8` 轉換為指定的編碼標準。根據預設， `utf-16`和 `utf-32` 假設為小端點編碼。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行指定修改的許可。
+ 檔案在執行時間不存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | 是 | 
| encoding | 編碼標準。 | String | 否 | utf8 | utf8、utf-8、utf16、utf-16、utf16-LEutf-16-LEutf16-BE、、utf-16-BE、utf32、utf-32、utf32-LEutf-32-LE、 utf32-BE和  utf-32-BE。編碼選項的值不區分大小寫。 | 是 | 

**輸入範例：設定檔案編碼屬性**

```
  - name: SettingFileEncodingProperty
    action: SetFileEncoding
    inputs:
      - path: /home/UserName/SampleFile.txt
        encoding: UTF-16
```

**Output**  
無。

### SetFileOwner (Linux、Windows、macOS)
<a name="action-modules-setfileowner"></a>

**SetFileOwner** 動作模組會修改現有檔案的 `owner`和`group`擁有者屬性。如果指定的檔案是符號連結，模組會修改來源檔案的 `owner` 屬性。Windows 平台不支援此模組。

此模組接受使用者和群組名稱做為輸入。如果未提供群組名稱，模組會將檔案的群組擁有者指派給使用者所屬的群組。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行指定修改的許可。
+ 指定的使用者或群組名稱在執行時間不存在。
+ 檔案在執行時間不存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| owner | 使用者名稱。 | string | 是 | N/A | N/A | Windows 不支援。 | 
| group | 使用者群組的名稱。 | String | 否 | 使用者所屬的群組名稱。 | N/A | Windows 不支援。 | 

**輸入範例：設定檔案擁有者屬性，而不指定使用者群組的名稱**

```
  - name: SettingFileOwnerPropertyNoGroup
    action: SetFileOwner
    inputs:
      - path: /home/UserName/SampleText.txt
        owner: LinuxUser
```

**輸入範例：透過指定擁有者和使用者群組來設定檔案擁有者屬性**

```
  - name: SettingFileOwnerProperty
    action: SetFileOwner
    inputs:
      - path: /home/UserName/SampleText.txt
        owner: LinuxUser
        group: LinuxUserGroup
```

**Output**  
無。

### SetFolderOwner (Linux、Windows、macOS)
<a name="action-modules-setfolderowner"></a>

**SetFolderOwner** 動作模組會遞迴修改現有資料夾的 `owner`和`group`擁有者屬性。根據預設，模組可以修改資料夾中所有內容的擁有權。您可以將 `recursive`選項設定為 `false`以覆寫此行為。Windows 平台不支援此模組。

此模組接受使用者和群組名稱做為輸入。如果未提供群組名稱，模組會將檔案的群組擁有者指派給使用者所屬的群組。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行指定修改的許可。
+ 指定的使用者或群組名稱在執行時間不存在。
+ 資料夾在執行時間不存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 資料夾路徑。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| owner | 使用者名稱。 | string | 是 | N/A | N/A | Windows 不支援。 | 
| group | 使用者群組的名稱。 | String | 否 | 使用者所屬的群組名稱。 | N/A | Windows 不支援。 | 
| recursive | 設定為 時，覆寫修改資料夾所有內容之擁有權的預設行為false。 | Boolean | 否 | true | N/A | Windows 不支援。 | 

**輸入範例：設定資料夾擁有者屬性，而不指定使用者群組的名稱**

```
  - name: SettingFolderPropertyWithOutGroup
    action: SetFolderOwner
    inputs:
      - path: /SampleFolder/
        owner: LinuxUser
```

**輸入範例：設定資料夾擁有者屬性，而不覆寫資料夾中所有內容的擁有權 **

```
  - name: SettingFolderPropertyWithOutRecursively
    action: SetFolderOwner
    inputs:
      - path: /SampleFolder/
        owner: LinuxUser
        recursive: false
```

**輸入範例：透過指定使用者群組的名稱來設定檔案擁有權屬性**

```
  - name: SettingFolderPropertyWithGroup
    action: SetFolderOwner
    inputs:
      - path: /SampleFolder/
        owner: LinuxUser
        group: LinuxUserGroup
```

**Output**  
無。

### SetFilePermissions (Linux、Windows、macOS)
<a name="action-modules-setfilepermissions"></a>

**SetFilePermissions** 動作模組會修改現有檔案`permissions`的 。Windows 平台不支援此模組。

的輸入`permissions`必須是字串值。

此動作模組可以建立具有作業系統預設 umask 值所定義許可的檔案 。如果您想要覆寫預設值，則必須設定 `umask` 值。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行指定修改的許可。
+ 檔案在執行時間不存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 檔案路徑。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| permissions | 檔案許可。 | String | 是 | N/A | N/A | Windows 不支援。 | 

**輸入範例：修改檔案許可**

```
  - name: ModifyingFilePermissions
    action: SetFilePermissions
    inputs:
      - path: /home/UserName/SampleFile.txt
        permissions: 766
```

**Output**  
無。

### SetFolderPermissions (Linux、Windows、macOS)
<a name="action-modules-setfolderpermissions"></a>

**SetFolderPermissions** 動作模組會遞迴修改現有資料夾及其所有子檔案和子資料夾`permissions`的 。根據預設，此模組可以修改指定資料夾之所有內容的許可。您可以將 `recursive`選項設定為 `false`以覆寫此行為。Windows 平台不支援此模組。

的輸入`permissions`必須是字串值。

此動作模組可根據作業系統的預設 umask 值修改許可。如果您想要覆寫預設值，則必須設定 `umask` 值。

發生下列情況時，動作模組會傳回錯誤：
+ 您沒有執行指定修改的許可。
+ 資料夾在執行時間不存在。
+ 動作模組在執行操作時遇到錯誤。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 在所有平台上支援 | 
| --- | --- | --- | --- | --- | --- | --- | 
| path | 資料夾路徑。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| permissions | 資料夾許可。 | String | 是 | N/A | N/A | Windows 不支援。 | 
| recursive | 設為 時，覆寫修改資料夾所有內容許可的預設行為false。 | Boolean | 否 | true | N/A | Windows 不支援。 | 

**輸入範例：設定資料夾許可**

```
  - name: SettingFolderPermissions
    action: SetFolderPermissions
    inputs:
      - path: SampleFolder/
        permissions: 0777
```

**輸入範例：設定資料夾許可，而不修改資料夾所有內容的許可**

```
  - name: SettingFolderPermissionsNoRecursive
    action: SetFolderPermissions
    inputs:
      - path: /home/UserName/SampleFolder/
        permissions: 777
        recursive: false
```

**Output**  
無。

## 軟體安裝動作
<a name="action-modules-software-install-actions"></a>

下一節說明安裝或解除安裝軟體的動作模組。

**IAM 要求**  
如果您的安裝下載路徑是 S3 URI，則與執行個體描述檔相關聯的 IAM 角色必須具有執行`S3Download`動作模組的許可。若要授予必要的許可，請將 `S3:GetObject` IAM 政策連接至與您執行個體描述檔相關聯的 IAM 角色，並指定儲存貯體的路徑。例如，`arn:aws:s3:::BucketName/*`)。

**複雜的 MSI 輸入**  
如果您的輸入字串包含雙引號字元 (`"`)，您必須使用下列其中一種方法來確保正確解譯：
+ 您可以在字串外部使用單引號 (') 來包含它，並在字串內部使用雙引號 (")，如下列範例所示。

  ```
  properties:
    COMPANYNAME: '"Acme ""Widgets"" and ""Gizmos."""'
  ```

  在這種情況下，如果您需要在字串內使用撇號，則必須將其逸出。這表示在撇號之前使用另一個單引號 (')。
+ 您可以在字串外部使用雙引號 (") 來包含它。您也可以使用反斜線字元 (`\`) 逸出字串內的任何雙引號，如下列範例所示。

  ```
  properties:
    COMPANYNAME: "\"Acme \"\"Widgets\"\" and \"\"Gizmos.\"\"\""
  ```

這兩種方法都會將 值傳遞`COMPANYNAME="Acme ""Widgets"" and ""Gizmos."""`至 **msiexec**命令。

**Topics**
+ [InstallMSI (Windows)](#action-modules-install-msi)
+ [UninstallMSI (Windows)](#action-modules-uninstall-msi)

### InstallMSI (Windows)
<a name="action-modules-install-msi"></a>

`InstallMSI` 動作模組會使用 MSI 檔案安裝 Windows 應用程式。您可以使用本機路徑、S3 物件 URI 或 Web URL 指定 MSI 檔案。重新啟動選項會設定系統的重新啟動行為。

AWS TOE 根據動作模組的輸入參數產生 **msiexec**命令。`path` (MSI 檔案位置） 和 `logFile`（日誌檔案位置） 輸入參數的值必須以引號 (") 括住。

下列 MSI 結束代碼視為成功：
+ 0 （成功）
+ 1614 (ERROR\$1PRODUCT\$1UNINSTALLED)
+ 1641 （重新啟動啟動）
+ 3010 （需要重新啟動）


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 
| --- | --- | --- | --- | --- | --- | 
| path |  使用下列其中一項指定 MSI 檔案位置： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html) 允許鏈結表達式。  | String | 是 | N/A | N/A | 
| reboot |  設定成功執行動作模組之後的系統重新啟動行為。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | String | 否 | Allow | Allow, Force, Skip | 
| logOptions |  指定用於 MSI 安裝記錄的選項。指定的旗標會與`/L`命令列參數一起傳遞至 MSI 安裝程式以啟用記錄。如果未指定旗標， AWS TOE 會使用預設值。 如需 MSI 日誌選項的詳細資訊，請參閱 Microsoft *Windows Installer* 產品文件中的[命令列選項](https://learn.microsoft.com/en-us/windows/win32/msi/command-line-options)。  | String | 否 | \$1VX | i,w,e,a,r,u,c,m,o,p,v,x,\$1,\$1,\$1 | 
| logFile |  日誌檔案位置的絕對或相對路徑。如果日誌檔案路徑不存在，則會建立。如果未提供日誌檔案路徑， AWS TOE 不會存放 MSI 安裝日誌。  | String | 否 | N/A | N/A | 
| properties |  MSI 記錄屬性索引鍵/值對 ，例如： `TARGETDIR: "C:\target\location"`   注意：不允許修改下列屬性： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | Map【String】字串 | 否 | N/A | N/A | 
| ignoreAuthenticodeSignatureErrors |  針對路徑中指定的安裝程式，忽略 Authenticode 簽章驗證錯誤的旗標。**Get-AuthenticodeSignature** 命令用於驗證安裝程式。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | Boolean | 否 | false | true, false | 
| allowUnsignedInstaller |  允許執行路徑中指定之未簽署安裝程式的旗標。**Get-AuthenticodeSignature** 命令用於驗證安裝程式。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | Boolean | 否 | false | true, false | 

**範例**  
下列範例顯示元件文件的輸入區段變化，視您的安裝路徑而定。

**輸入範例：本機文件路徑安裝**

```
- name: local-path-install
  steps:
    - name: LocalPathInstaller
      action: InstallMSI
      inputs:
        path: C:\sample.msi
        logFile: C:\msilogs\local-path-install.log
        logOptions: '*VX'
        reboot: Allow
        properties:
          COMPANYNAME: '"Amazon Web Services"'
        ignoreAuthenticodeSignatureErrors: true
        allowUnsignedInstaller: true
```

**輸入範例：Amazon S3 路徑安裝**

```
- name: s3-path-install
  steps:
    - name: S3PathInstaller
      action: InstallMSI
      inputs:
        path: s3://<bucket-name>/sample.msi
        logFile: s3-path-install.log
        reboot: Force
        ignoreAuthenticodeSignatureErrors: false
        allowUnsignedInstaller: true
```

**輸入範例：Web 路徑安裝**

```
- name: web-path-install
  steps:
    - name: WebPathInstaller
      action: InstallMSI
      inputs:
        path: https://<some-path>/sample.msi
        logFile: web-path-install.log
        reboot: Skip
        ignoreAuthenticodeSignatureErrors: true
        allowUnsignedInstaller: false
```

**Output**  
以下是動作`InstallMSI`模組輸出的範例。

```
{
	"logFile": "web-path-install.log",
	"msiExitCode": 0,
	"stdout": ""
}
```

### UninstallMSI (Windows)
<a name="action-modules-uninstall-msi"></a>

`UninstallMSI` 動作模組可讓您使用 MSI 檔案移除 Windows 應用程式。您可以使用本機檔案路徑、S3 物件 URI 或 Web URL 指定 MSI 檔案位置。重新啟動選項會設定系統的重新啟動行為。

AWS TOE 根據動作模組的輸入參數產生 **msiexec**命令。產生**msiexec**命令時，MSI 檔案位置 (`path`) 和日誌檔案位置 (`logFile`) 會以雙引號 (") 明確括住。

下列 MSI 結束代碼視為成功：
+ 0 （成功）
+ 1605 (ERROR\$1UNKNOWN\$1PRODUCT)
+ 1614 (ERROR\$1PRODUCT\$1UNINSTALLED)
+ 1641 （重新啟動啟動）
+ 3010 （需要重新啟動）


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設值 | 可接受值 | 
| --- | --- | --- | --- | --- | --- | 
| path |  使用下列其中一項指定 MSI 檔案位置： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html) 允許鏈結表達式。  | String | 是 | N/A | N/A | 
| reboot |  設定成功執行動作模組之後的系統重新啟動行為。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | String | 否 | Allow | Allow, Force, Skip | 
| logOptions |  指定用於 MSI 安裝記錄的選項。指定的旗標會與`/L`命令列參數一起傳遞至 MSI 安裝程式以啟用記錄。如果未指定旗標， AWS TOE 會使用預設值。 如需 MSI 日誌選項的詳細資訊，請參閱 Microsoft *Windows Installer* 產品文件中的[命令列選項](https://docs.microsoft.com/en-us/windows/win32/msi/command-line-options)。  | String | 否 | \$1VX | i,w,e,a,r,u,c,m,o,p,v,x,\$1,\$1,\$1 | 
| logFile |  日誌檔案位置的絕對或相對路徑。如果日誌檔案路徑不存在，則會建立。如果未提供日誌檔案路徑， AWS TOE 不會存放 MSI 安裝日誌。  | String | 否 | N/A | N/A | 
| properties |  MSI 記錄屬性索引鍵/值對 ，例如： `TARGETDIR: "C:\target\location"`   注意：不允許修改下列屬性： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | Map【String】字串 | 否 | N/A | N/A | 
| ignoreAuthenticodeSignatureErrors |  針對路徑中指定的安裝程式，忽略 Authenticode 簽章驗證錯誤的旗標。**Get-AuthenticodeSignature** 命令用於驗證安裝程式。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | Boolean | 否 | false | true, false | 
| allowUnsignedInstaller |  允許執行路徑中指定之未簽署安裝程式的旗標。**Get-AuthenticodeSignature** 命令用於驗證安裝程式。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html)  | Boolean | 否 | false | true, false | 

**範例**  
下列範例顯示元件文件的輸入區段變化，視您的安裝路徑而定。

**輸入範例：移除本機文件路徑安裝**

```
- name: local-path-uninstall
  steps:
    - name: LocalPathUninstaller
      action: UninstallMSI
      inputs:
        path: C:\sample.msi
        logFile: C:\msilogs\local-path-uninstall.log
        logOptions: '*VX'
        reboot: Allow
        properties:
          COMPANYNAME: '"Amazon Web Services"'
        ignoreAuthenticodeSignatureErrors: true
        allowUnsignedInstaller: true
```

**輸入範例：移除 Amazon S3 路徑安裝**

```
- name: s3-path-uninstall
  steps:
    - name: S3PathUninstaller
      action: UninstallMSI
      inputs:
        path: s3://<bucket-name>/sample.msi
        logFile: s3-path-uninstall.log
        reboot: Force
        ignoreAuthenticodeSignatureErrors: false
        allowUnsignedInstaller: true
```

**輸入範例：移除 Web 路徑安裝**

```
- name: web-path-uninstall
  steps:
    - name: WebPathUninstaller
      action: UninstallMSI
      inputs:
        path: https://<some-path>/sample.msi
        logFile: web-path-uninstall.log
        reboot: Skip
        ignoreAuthenticodeSignatureErrors: true
        allowUnsignedInstaller: false
```

**Output**  
以下是動作`UninstallMSI`模組輸出的範例。

```
{
	"logFile": "web-path-uninstall.log",
	"msiExitCode": 0,
	"stdout": ""
}
```

## 系統動作模組
<a name="action-modules-system-actions"></a>

下一節說明執行系統動作或更新系統設定的動作模組。

**Topics**
+ [重新啟動 (Linux、Windows)](#action-modules-reboot)
+ [SetRegistry (Windows)](#action-modules-setregistry)
+ [UpdateOS (Linux、Windows)](#action-modules-updateos)

### 重新啟動 (Linux、Windows)
<a name="action-modules-reboot"></a>

**重新啟動**動作模組會重新啟動執行個體。它具有可設定的選項，可延遲重新啟動的開始。根據預設， `delaySeconds` 會設定為 `0`，這表示沒有延遲。重新啟動動作模組不支援步驟逾時，因為它在執行個體重新啟動時不適用。

如果 Systems Manager 代理程式叫用應用程式，則會將結束碼 (`3010`適用於 Windows，`194`適用於 Linux) 交給 Systems Manager 代理程式。Systems Manager 代理程式會處理系統重新啟動，如[從指令碼重新啟動受管執行個體](https://docs.aws.amazon.com/systems-manager/latest/userguide/send-commands-reboot.html)中所述。

如果在主機上調用應用程式做為獨立程序，它會儲存目前的執行狀態、設定重新啟動後自動執行觸發程序，以在重新啟動後重新執行應用程式，然後重新啟動系統。

**重新啟動後自動執行觸發：**
+ **Windows**。 會使用在 自動執行的觸發條件來 AWS TOE 建立 Windows 任務排程器項目 `SystemStartup`
+ **Linux**。 在 crontab 中 AWS TOE 新增任務，該任務會在系統重新啟動後自動執行。

```
@reboot /download/path/awstoe run --document s3://bucket/key/doc.yaml
```

此觸發會在應用程式啟動時清除。

**重試**  
根據預設，重試次數上限會設定為 Systems Manager `CommandRetryLimit`。如果重新啟動次數超過重試限制，則自動化會失敗。您可以編輯 Systems Manager 代理程式組態檔案 () 來變更限制`Mds.CommandRetryLimit`。請參閱 Systems Manager 代理程式開放原始碼中的[執行期組態](https://github.com/aws/amazon-ssm-agent/blob/mainline/README.md#runtime-configuration)。

若要使用**重新啟動**動作模組，對於包含重新啟動的步驟 `exitcode`（例如，`3010`)，您必須以 執行應用程式二進位檔`sudo user`。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 預設 | 
| --- | --- | --- | --- | --- | 
| delaySeconds | 在開始重新啟動之前延遲特定的時間量。 | Integer |  否  |  `0`  | 

**輸入範例：重新啟動步驟**

```
  - name: RebootStep
    action: Reboot
    onFailure: Abort
    maxAttempts: 2
    inputs:
      delaySeconds: 60
```

**輸出**

無。

**重新啟動**模組完成後，Image Builder 會繼續執行建置中的下一個步驟。

### SetRegistry (Windows)
<a name="action-modules-setregistry"></a>

**SetRegistry** 動作模組接受輸入清單，並可讓您設定指定登錄機碼的值。如果登錄機碼不存在，則會在定義的路徑中建立。此功能僅適用於 Windows。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| path | 登錄機碼的路徑。 | String | 是 | 
| name | 登錄機碼的名稱。 | String | 是 | 
| value | 登錄機碼的值。 | String/Number/Array | 是 | 
| type | 登錄機碼的值類型。 | String | 是 | 

**支援的路徑字首**
+ `HKEY_CLASSES_ROOT / HKCR:`
+ `HKEY_USERS / HKU:`
+ `HKEY_LOCAL_MACHINE / HKLM:`
+ `HKEY_CURRENT_CONFIG / HKCC:`
+ `HKEY_CURRENT_USER / HKCU:`

**支援的 類型**
+ `BINARY`
+ `DWORD`
+ `QWORD`
+ `SZ`
+ `EXPAND_SZ`
+ `MULTI_SZ`

**輸入範例：設定登錄機碼值**

```
  - name: SetRegistryKeyValues
    action: SetRegistry
    maxAttempts: 3
    inputs:
      - path: HKLM:\SOFTWARE\MySoftWare
        name: MyName
        value: FirstVersionSoftware
        type: SZ
      - path: HKEY_CURRENT_USER\Software\Test
        name: Version
        value: 1.1
        type: DWORD
```

**輸出**

無。

### UpdateOS (Linux、Windows)
<a name="action-modules-updateos"></a>

**UpdateOS** 動作模組新增了安裝 Windows 和 Linux 更新的支援。預設會安裝所有可用的更新。或者，您可以為要安裝的動作模組設定一或多個特定更新清單。您也可以指定要從安裝中排除的更新。

如果同時提供「包含」和「排除」清單，則產生的更新清單只能包含未列在「排除」清單中的「包含」清單。

**注意**  
**UpdateOS** 不支援 Amazon Linux 2023 (AL2023)。建議您將基本 AMI 更新為每個版本隨附的新版本。如需其他替代方案，請參閱《*Amazon Linux 2023 使用者指南*》中的[控制從主要和次要版本收到的更新](https://docs.aws.amazon.com/linux/al2023/ug/deterministic-upgrades.html#controlling-release-updates)。
+ **Windows**。更新是從目標機器上設定的更新來源進行安裝。
+ **Linux**。應用程式會在 Linux 平台中檢查支援的套件管理員，並使用 `yum`或 `apt-get`套件管理員。如果都不支援，則會傳回錯誤。您應該具有執行 **UpdateOS** 動作模組的`sudo`許可。如果您沒有`sudo`許可，`error.Input`則會傳回 。


**Input**  

| 金鑰名稱 | 說明 | Type | 必要 | 
| --- | --- | --- | --- | 
| include |  對於 Windows，您可以指定下列項目： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html) 對於 Linux，您可以指定要包含在安裝更新清單中的一或多個套件。  | 字串清單 | 否 | 
| exclude |  對於 Windows，您可以指定下列項目： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/imagebuilder/latest/userguide/toe-action-modules.html) 對於 Linux，您可以指定要從安裝更新清單中排除的一或多個套件。  | 字串清單 | 否 | 

**輸入範例：新增安裝 Linux 更新的支援**

```
  - name: UpdateMyLinux
    action: UpdateOS
    onFailure: Abort
    maxAttempts: 3
    inputs:
      exclude:
        - ec2-hibinit-agent
```

**輸入範例：新增安裝 Windows 更新的支援**

```
  - name: UpdateWindowsOperatingSystem
    action: UpdateOS
    onFailure: Abort
    maxAttempts: 3
    inputs:
      include:
        - KB1234567
        - '*Security*'
```

**輸出**

無。