本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
手動設定以開發自訂元件 AWS TOE
AWS 任務協調器和執行器 (AWS TOE) 應用程式是獨立的應用程式,可在元件定義架構中建立、驗證和執行指令。 AWS 服務可用 AWS TOE 來協調工作流程、安裝軟體、修改系統組態,以及測試映像檔組建。
請依照下列步驟手動安裝 AWS TOE 應用程式,並將其用作獨立應用程式來開發自訂元件。如果您使用 Image Builder 主控台或 AWS CLI 指令來建立自訂元件,Image Builder 會為您處理這些步驟。如需詳細資訊,請參閱 使用 Image Builder 立自訂元件。
步驟 1:安裝 AWS TOE
若要在本機開發元件,請下載並安裝 AWS TOE 應用程式。
-
下載 AWS TOE 應用程式
若要安裝 AWS TOE,請選擇適合您架構和平台的下載連結。如需應用程式下載連結的完整清單,請參閱 AWS TOE 下載
重要
AWS 正逐步取消對 TLS 版本 1.0 和 1.1 版的支援。若要存取 S3 儲存貯體以進行 AWS TOE 下載,您的用戶端軟體必須使用 TLS 1.2 版或更新版本。如需詳細資訊,請參閱此AWS 安全性部落格文章
。 -
驗證簽名
驗證下載的步驟取決於您在安裝 AWS TOE 應用程式之後執行應用程式的伺服器平台。若要驗證您在 Linux 伺服器上的下載,請參閱在 Linux 上驗證簽名。若要確認您在 Windows 伺服器上的下載作業,請參閱驗證視窗上的簽名。
重要
AWS TOE 直接從其下載位置調用。不需要單獨的安裝步驟。這也意味著 AWS TOE 可以對本地環境進行更改。
為了確保您在元件開發期間隔離變更,建議您使用 EC2 執行個體來開發和測試 AWS TOE 元件。
步驟 2:設定 AWS 認證
AWS TOE 執行任務時 AWS 服務,需要 AWS 登入資料才能連線到其他資料 CloudWatch,例如 Amazon S3 和 Amazon,例如:
-
從使用者提供的 Amazon S3 路徑下載 AWS TOE 文件。
-
運行
S3Download
或S3Upload
動作模塊。 -
啟用時 CloudWatch,將記錄串流至。
如果您在 EC2 執行個體 AWS TOE 上執行,則執行 AWS TOE 會使用與連接至 EC2 執行個體的 IAM 角色相同的許可。
如需適用於 EC2 的 IAM 角色的詳細資訊,請參閱適用於 Amazon EC2 的 IAM 角色。
下列範例顯示如何使用AWS_ACCESS_KEY_ID
和AWS_SECRET_ACCESS_KEY
環境變數設定 AWS 認證。
若要在 Linux、macOS 或 Unix 上設定這些變數,請使用export
。
$
export AWS_ACCESS_KEY_ID=your_access_key_id
$
export AWS_SECRET_ACCESS_KEY=your_secret_access_key
若要在 Windows 上使用設定這些變數 PowerShell,請使用$env
。
C:\>
$env:AWS_ACCESS_KEY_ID=your_access_key_id
C:\>
$env:AWS_SECRET_ACCESS_KEY=your_secret_access_key
若要使用命令提示字元在 Windows 上設定這些變數,請使用set
。
C:\>
set AWS_ACCESS_KEY_ID=your_access_key_id
C:\>
set AWS_SECRET_ACCESS_KEY=your_secret_access_key
步驟 3:在本機開發元件文件
AWS TOE 元件是使用純文字 YAML 文件建立的。如需文件語法的詳細資訊,請參閱使用自訂 AWS TOE 元件的元件文件架構。
以下是 Hello World 組件文檔的示例,以幫助您開始使用。
hello-world-windows.yml
.
name: Hello World description: This is Hello World testing document for Windows. schemaVersion: 1.0 phases: - name: build steps: - name: HelloWorldStep action: ExecutePowerShell inputs: commands: - Write-Host 'Hello World from the build phase.' - name: validate steps: - name: HelloWorldStep action: ExecutePowerShell inputs: commands: - Write-Host 'Hello World from the validate phase.' - name: test steps: - name: HelloWorldStep action: ExecutePowerShell inputs: commands: - Write-Host 'Hello World from the test phase.'
hello-world-linux.yml
.
name: Hello World description: This is hello world testing document for Linux. schemaVersion: 1.0 phases: - name: build steps: - name: HelloWorldStep action: ExecuteBash inputs: commands: - echo 'Hello World from the build phase.' - name: validate steps: - name: HelloWorldStep action: ExecuteBash inputs: commands: - echo 'Hello World from the validate phase.' - name: test steps: - name: HelloWorldStep action: ExecuteBash inputs: commands: - echo 'Hello World from the test phase.'
步驟 4:驗證 AWS TOE 元件
您可以使 AWS TOE
用應用程式在本機驗證 AWS TOE 元件的語法。下列範例顯示 AWS TOE 應用程式validate
命令,以驗證元件的語法而不執行元件。
注意
AWS TOE 應用程式只能驗證目前作業系統的元件語法。例如,awstoe.exe
在 Windows 上執行時,您無法驗證使用ExecuteBash
動作模組之 Linux 文件的語法。
Windows
C:\>
awstoe.exe validate --documents C:\Users\user\Documents\hello-world.yml
Linux
$
awstoe validate --documents /home/user/hello-world.yml
步驟 5:執行 AWS TOE 元件
AWS TOE 應用程序可以使用--phases
命令行參數運行指定文檔的一個或多個階段。支援的--phases
值為build
validate
、和test
。可以將多個相位值輸入為逗號分隔值。
當您提供階段清單時,應用程式會依 AWS TOE 序執行每個文件的指定階段。例如, AWS TOE 執行的build
和validate
階段document1.yaml
,然後執行的build
和validate
階段document2.yaml
。
為確保您的日誌安全存放並保留以便進行故障診斷,建議您在 Amazon S3 中設定日誌儲存。在 Image Builder 中,用於發佈日誌的 Amazon S3 位置是在基礎設施組態中指定的。如需基礎結構組態的詳細資訊,請參閱 管理 EC2 Image Builder 基礎設施組
如果未提供階段清單, AWS TOE 應用程式會依照 YAML 文件中列出的順序執行所有階段。
若要在單一或多個文件中執行特定階段,請使用下列指令。
單相
awstoe run --documents hello-world.yml --phases build
多個階段
awstoe run --documents hello-world.yml --phases build,test
文件執行
在單一文件中執行所有階段
awstoe run --documents
documentName
.yaml
在多個文檔中運行所有階段
awstoe run --documents
documentName1
.yaml,documentName2
.yaml
輸入 Amazon S3 資訊以從使用者定義的本機路徑上傳 AWS TOE 日誌 (建議使用)
awstoe run --documents
documentName
.yaml --log-s3-bucket-name <S3Bucket> --log-s3-key-prefix <S3KeyPrefix> --log-s3-bucket-owner <S3BucketOwner> --log-directory <local_path>
在單個文檔中運行所有階段,並在控制台上顯示所有日誌
awstoe run --documents
documentName
.yaml --trace
範例 命令
awstoe run --documents s3://bucket/key/doc.yaml --phases build,validate
使用唯一 ID 執行文件
awstoe run --documents <documentName>.yaml --execution-id <user provided id> --phases <comma separated list of phases>
取得協助 AWS TOE
awstoe --help