使用 Image Builder 示例 AWS CLI - AWS Command Line Interface

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

使用 Image Builder 示例 AWS CLI

下列程式碼範例說明如何透過 AWS Command Line Interface 搭配 Image Builder 使用來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數,但您可以在其相關情境和跨服務範例中查看內容中的動作。

Scenarios (案例) 是向您展示如何呼叫相同服務中的多個函數來完成特定任務的程式碼範例。

每個範例都包含一個連結 GitHub,您可以在其中找到如何在內容中設定和執行程式碼的指示。

主題

動作

下列程式碼範例會示範如何使用create-component

AWS CLI

建立元件的步驟

下列create-component範例會建立使用 JSON 文件檔案的元件,並參考已上傳至 Amazon S3 儲存貯體的 YAML 格式的元件文件。

aws imagebuilder create-component \ --cli-input-json file://create-component.json

create-component.json 的內容:

{ "name": "MyExampleComponent", "semanticVersion": "2019.12.02", "description": "An example component that builds, validates and tests an image", "changeDescription": "Initial version.", "platform": "Windows", "uri": "s3://s3-bucket-name/s3-bucket-path/component.yaml" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "componentBuildVersionArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/examplecomponent/2019.12.02/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateComponent中的。

下列程式碼範例會示範如何使用create-distribution-configuration

AWS CLI

若要建立發佈組態

下列create-distribution-configuration範例會使用 JSON 檔案建立散發組態。

aws imagebuilder create-distribution-configuration \ --cli-input-json file:/create-distribution-configuration.json

create-distribution-configuration.json 的內容:

{ "name": "MyExampleDistribution", "description": "Copies AMI to eu-west-1", "distributions": [ { "region": "us-west-2", "amiDistributionConfiguration": { "name": "Name {{imagebuilder:buildDate}}", "description": "An example image name with parameter references", "amiTags": { "KeyName": "{{ssm:parameter_name}}" }, "launchPermission": { "userIds": [ "123456789012" ] } } }, { "region": "eu-west-1", "amiDistributionConfiguration": { "name": "My {{imagebuilder:buildVersion}} image {{imagebuilder:buildDate}}", "amiTags": { "KeyName": "Value" }, "launchPermission": { "userIds": [ "123456789012" ] } } } ] }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "distributionConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用create-image-pipeline

AWS CLI

若要建立影像管線

下列create-image-pipeline範例會使用 JSON 檔案建立影像管線。

aws imagebuilder create-image-pipeline \ --cli-input-json file://create-image-pipeline.json

create-image-pipeline.json 的內容:

{ "name": "MyWindows2016Pipeline", "description": "Builds Windows 2016 Images", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "distributionConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "imageTestsConfiguration": { "imageTestsEnabled": true, "timeoutMinutes": 60 }, "schedule": { "scheduleExpression": "cron(0 0 * * SUN)", "pipelineExecutionStartCondition": "EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE" }, "status": "ENABLED" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "imagePipelineArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用create-image-recipe

AWS CLI

若要建立配方

下列create-image-recipe範例會使用 JSON 檔案建立影像方案。元件會依照指定的順序進行安裝。

aws imagebuilder create-image-recipe \ --cli-input-json file://create-image-recipe.json

create-image-recipe.json 的內容:

{ "name": "MyBasicRecipe", "description": "This example image recipe creates a Windows 2016 image.", "semanticVersion": "2019.12.03", "components": [ { "componentArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myexamplecomponent/2019.12.02/1" }, { "componentArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myimportedcomponent/1.0.0/1" } ], "parentImage": "arn:aws:imagebuilder:us-west-2:aws:image/windows-server-2016-english-full-base-x86/xxxx.x.x" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用create-image

AWS CLI

建立影像的步驟

下列create-image範例會建立影像。

aws imagebuilder create-image \ --image-recipe-arn arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03 \ --infrastructure-configuration-arn arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "imageBuildVersionArn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考CreateImage中的。

下列程式碼範例會示範如何使用create-infrastructure-configuration

AWS CLI

若要建立基礎結構組態

下列create-infrastructure-configuration範例會使用 JSON 檔案建立基礎結構組態。

aws imagebuilder create-infrastructure-configuration \ --cli-input-json file://create-infrastructure-configuration.json

create-infrastructure-configuration.json 的內容:

{ "name": "MyExampleInfrastructure", "description": "An example that will retain instances of failed builds", "instanceTypes": [ "m5.large", "m5.xlarge" ], "instanceProfileName": "EC2InstanceProfileForImageBuilder", "securityGroupIds": [ "sg-a1b2c3d4" ], "subnetId": "subnet-a1b2c3d4", "logging": { "s3Logs": { "s3BucketName": "bucket-name", "s3KeyPrefix": "bucket-path" } }, "keyPair": "key-pair-name", "terminateInstanceOnFailure": false, "snsTopicArn": "arn:aws:sns:us-west-2:123456789012:sns-topic-name" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用delete-component

AWS CLI

刪除元件的步驟

下列delete-component範例會指定元件建置版本的 ARN,以刪除元件組建版本。

aws imagebuilder delete-component \ --component-build-version-arn arn:aws:imagebuilder:us-west-2:123456789012:component/myexamplecomponent/2019.12.02/1

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "componentBuildVersionArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myexamplecomponent/2019.12.02/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteComponent中的。

下列程式碼範例會示範如何使用delete-image-pipeline

AWS CLI

若要刪除影像管線

下列delete-image-pipeline範例會透過指定影像管線的 ARN 來刪除影像管線。

aws imagebuilder delete-image-pipeline \ --image-pipeline-arn arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/my-example-pipeline

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imagePipelineArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用delete-image-recipe

AWS CLI

若要刪除影像配方

下列delete-image-recipe範例會透過指定影像方案 ARN 來刪除影像方案。

aws imagebuilder delete-image-recipe \ --image-recipe-arn arn:aws:imagebuilder:us-east-1:123456789012:image-recipe/mybasicrecipe/2019.12.03

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用delete-image

AWS CLI

若要刪除影像

下列delete-image範例會透過指定映像檔的 ARN 來刪除映像建置版本。

aws imagebuilder delete-image \ --image-build-version-arn arn:aws:imagebuilder:us-west-2:123456789012:image/my-example-image/2019.12.02/1

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageBuildVersionArn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考DeleteImage中的。

下列程式碼範例會示範如何使用delete-infrastructure-configuration

AWS CLI

刪除基礎結構組態

下列delete-infrastructure-configuration範例會透過指定影像管線的 ARN 來刪除影像管線。

aws imagebuilder delete-infrastructure-configuration \ --infrastructure-configuration-arn arn:aws:imagebuilder:us-east-1:123456789012:infrastructure-configuration/myexampleinfrastructure

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用get-component-policy

AWS CLI

取得元件原則詳細資料

下列get-component-policy範例會指定元件原則的 ARN,列出元件原則的詳細資訊。

aws imagebuilder get-component-policy \ --component-arn arn:aws:imagebuilder:us-west-2:123456789012:component/my-example-component/2019.12.03/1

輸出:

{ "Policy": "{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetComponent", "imagebuilder:ListComponents" ], "Resource": [ "arn:aws:imagebuilder:us-west-2:123456789012:component/my-example-component/2019.12.03/1" ] } ] }" }

如需詳細資訊,請參閱 EC2 managing-image-builder-cli Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。https://docs.aws.amazon.com/imagebuilder/latest/userguide/

下列程式碼範例會示範如何使用get-component

AWS CLI

取得元件詳細資訊

下列get-component範例會藉由指定元件的 ARN 來列出元件的詳細資訊。

aws imagebuilder get-component \ --component-build-version-arn arn:aws:imagebuilder:us-west-2:123456789012:component/component-name/1.0.0/1

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "component": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:component/component-name/1.0.0/1", "name": "component-name", "version": "1.0.0", "type": "TEST", "platform": "Linux", "owner": "123456789012", "data": "name: HelloWorldTestingDocument\ndescription: This is hello world testing document.\nschemaVersion: 1.0\n\nphases:\n - name: test\n steps:\n - name: HelloWorldStep\n action: ExecuteBash\n inputs:\n commands:\n - echo \"Hello World! Test.\"\n", "encrypted": true, "dateCreated": "2020-01-27T20:43:30.306Z", "tags": {} } }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetComponent中的。

下列程式碼範例會示範如何使用get-distribution-configuration

AWS CLI

若要取得發佈組態的詳細資料

下列get-distribution-configuration範例會透過指定發佈組態的 ARN 來顯示發佈組態的詳細資訊。

aws imagebuilder get-distribution-configuration \ --distribution-configuration-arn arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "distributionConfiguration": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "name": "MyExampleDistribution", "description": "Copies AMI to eu-west-1 and exports to S3", "distributions": [ { "region": "us-west-2", "amiDistributionConfiguration": { "name": "Name {{imagebuilder:buildDate}}", "description": "An example image name with parameter references", "amiTags": { "KeyName": "{{ssm:parameter_name}}" }, "launchPermission": { "userIds": [ "123456789012" ] } } }, { "region": "eu-west-1", "amiDistributionConfiguration": { "name": "My {{imagebuilder:buildVersion}} image {{imagebuilder:buildDate}}", "amiTags": { "KeyName": "Value" }, "launchPermission": { "userIds": [ "123456789012" ] } } } ], "dateCreated": "2020-02-19T18:40:10.529Z", "tags": {} } }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用get-image-pipeline

AWS CLI

取得影像管線詳細資訊

下列get-image-pipeline範例會透過指定影像管線的 ARN 來列出影像管線的詳細資訊。

aws imagebuilder get-image-pipeline \ --image-pipeline-arn arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imagePipeline": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline", "name": "MyWindows2016Pipeline", "description": "Builds Windows 2016 Images", "platform": "Windows", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "distributionConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "imageTestsConfiguration": { "imageTestsEnabled": true, "timeoutMinutes": 60 }, "schedule": { "scheduleExpression": "cron(0 0 * * SUN)", "pipelineExecutionStartCondition": "EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE" }, "status": "ENABLED", "dateCreated": "2020-02-19T19:04:01.253Z", "dateUpdated": "2020-02-19T19:04:01.253Z", "tags": {} } }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetImagePipeline中的。

下列程式碼範例會示範如何使用get-image-policy

AWS CLI

取得影像策略詳細資料

下列get-image-policy範例會藉由指定影像原則的 ARN 來列出其詳細資訊。

aws imagebuilder get-image-policy \ --image-arn arn:aws:imagebuilder:us-west-2:123456789012:image/my-example-image/2019.12.03/1

輸出:

{ "Policy": "{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetImage", "imagebuilder:ListImages" ], "Resource": [ "arn:aws:imagebuilder:us-west-2:123456789012:image/my-example-image/2019.12.03/1" ] } ] }" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetImagePolicy中的。

下列程式碼範例會示範如何使用get-image-recipe-policy

AWS CLI

取得圖片配方政策詳細資料

下列get-image-recipe-policy範例會指定影像方案原則的 ARN,列出其詳細資訊。

aws imagebuilder get-image-recipe-policy \ --image-recipe-arn arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/my-example-image-recipe/2019.12.03/1

輸出:

{ "Policy": "{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetImageRecipe", "imagebuilder:ListImageRecipes" ], "Resource": [ "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/my-example-image-recipe/2019.12.03/1" ] } ] }" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用get-image

AWS CLI

取得影像詳細資料

下列get-image範例會藉由指定影像的 ARN 來列出影像的詳細資訊。

aws imagebuilder get-image \ --image-build-version-arn arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/1

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "image": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/1", "name": "MyBasicRecipe", "version": "2019.12.03/1", "platform": "Windows", "state": { "status": "BUILDING" }, "imageRecipe": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03", "name": "MyBasicRecipe", "description": "This example image recipe creates a Windows 2016 image.", "platform": "Windows", "version": "2019.12.03", "components": [ { "componentArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myexamplecomponent/2019.12.02/1" }, { "componentArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myimportedcomponent/1.0.0/1" } ], "parentImage": "arn:aws:imagebuilder:us-west-2:aws:image/windows-server-2016-english-full-base-x86/2019.12.17/1", "dateCreated": "2020-02-14T19:46:16.904Z", "tags": {} }, "infrastructureConfiguration": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "name": "MyExampleInfrastructure", "description": "An example that will retain instances of failed builds", "instanceTypes": [ "m5.large", "m5.xlarge" ], "instanceProfileName": "EC2InstanceProfileForImageFactory", "securityGroupIds": [ "sg-a1b2c3d4" ], "subnetId": "subnet-a1b2c3d4", "logging": { "s3Logs": { "s3BucketName": "bucket-name", "s3KeyPrefix": "bucket-path" } }, "keyPair": "Sam", "terminateInstanceOnFailure": false, "snsTopicArn": "arn:aws:sns:us-west-2:123456789012:sns-name", "dateCreated": "2020-02-14T21:21:05.098Z", "tags": {} }, "imageTestsConfiguration": { "imageTestsEnabled": true, "timeoutMinutes": 720 }, "dateCreated": "2020-02-14T23:14:13.597Z", "outputResources": { "amis": [] }, "tags": {} } }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考GetImage中的。

下列程式碼範例會示範如何使用get-infrastructure-configuration

AWS CLI

取得基礎結構組態詳細資

下列get-infrastructure-configuration範例會指定基礎結構組態的 ARN,列出基礎結構組態的詳細資訊。

aws imagebuilder get-infrastructure-configuration \ --infrastructure-configuration-arn arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "infrastructureConfiguration": { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "name": "MyExampleInfrastructure", "description": "An example that will retain instances of failed builds", "instanceTypes": [ "m5.large", "m5.xlarge" ], "instanceProfileName": "EC2InstanceProfileForImageBuilder", "securityGroupIds": [ "sg-a48c95ef" ], "subnetId": "subnet-a48c95ef", "logging": { "s3Logs": { "s3BucketName": "bucket-name", "s3KeyPrefix": "bucket-path" } }, "keyPair": "Name", "terminateInstanceOnFailure": false, "snsTopicArn": "arn:aws:sns:us-west-2:123456789012:sns-name", "dateCreated": "2020-02-19T19:11:51.858Z", "tags": {} } }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用import-component

AWS CLI

匯入元件

下列import-component範例會使用 JSON 檔案匯入預先存在的指令碼。

aws imagebuilder import-component \ --cli-input-json file://import-component.json

import-component.json 的內容:

{ "name": "MyImportedComponent", "semanticVersion": "1.0.0", "description": "An example of how to import a component", "changeDescription": "First commit message.", "format": "SHELL", "platform": "Windows", "type": "BUILD", "uri": "s3://s3-bucket-name/s3-bucket-path/component.yaml" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "componentBuildVersionArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myimportedcomponent/1.0.0/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ImportComponent中的。

下列程式碼範例會示範如何使用list-component-build-versions

AWS CLI

若要列出元件建置版本

下列list-component-build-versions範例會列出具有特定語意版本的元件建置版本。

aws imagebuilder list-component-build-versions --component-version-arn arn:aws:imagebuilder:us-west-2:123456789012:component/myexamplecomponent/2019.12.02

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "componentSummaryList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:component/myexamplecomponent/2019.12.02/1", "name": "MyExampleComponent", "version": "2019.12.02", "platform": "Windows", "type": "BUILD", "owner": "123456789012", "description": "An example component that builds, validates and tests an image", "changeDescription": "Initial version.", "dateCreated": "2020-02-19T18:53:45.940Z", "tags": { "KeyName": "KeyValue" } } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用list-components

AWS CLI

若要列出所有元件語意版本

下列list-components範例會列出您有權存取的所有元件語意版本。您可以選擇篩選是否列出您擁有、Amazon 擁有的元件,還是其他帳戶與您共用的元件。

aws imagebuilder list-components

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "componentVersionList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:component/component-name/1.0.0", "name": "component-name", "version": "1.0.0", "platform": "Linux", "type": "TEST", "owner": "123456789012", "dateCreated": "2020-01-27T20:43:30.306Z" } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListComponents中的。

下列程式碼範例會示範如何使用list-distribution-configurations

AWS CLI

若要列出分配

下列list-distribution-configurations範例會列出您所有的發行版。

aws imagebuilder list-distribution-configurations

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "distributionConfigurationSummaryList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "name": "MyExampleDistribution", "description": "Copies AMI to eu-west-1 and exports to S3", "dateCreated": "2020-02-19T18:40:10.529Z", "tags": { "KeyName": "KeyValue" } } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用list-image-build-versions

AWS CLI

若要列出映像建置版本

下列list-image-build-versions範例會列出所有具有語意版本的映像建置版本。

aws imagebuilder list-image-build-versions \ --image-version-arn arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageSummaryList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/7", "name": "MyBasicRecipe", "version": "2019.12.03/7", "platform": "Windows", "state": { "status": "FAILED", "reason": "Can't start SSM Automation for arn arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/7 during building. Parameter \"iamInstanceProfileName\" has a null value." }, "owner": "123456789012", "dateCreated": "2020-02-19T18:56:11.511Z", "outputResources": { "amis": [] }, "tags": {} }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/6", "name": "MyBasicRecipe", "version": "2019.12.03/6", "platform": "Windows", "state": { "status": "FAILED", "reason": "An internal error has occurred." }, "owner": "123456789012", "dateCreated": "2020-02-18T22:49:08.142Z", "outputResources": { "amis": [ { "region": "us-west-2", "image": "ami-a1b2c3d4567890ab", "name": "MyBasicRecipe 2020-02-18T22-49-38.704Z", "description": "This example image recipe creates a Windows 2016 image." }, { "region": "us-west-2", "image": "ami-a1b2c3d4567890ab", "name": "Name 2020-02-18T22-49-08.131Z", "description": "Copies AMI to eu-west-2 and exports to S3" }, { "region": "eu-west-2", "image": "ami-a1b2c3d4567890ab", "name": "My 6 image 2020-02-18T22-49-08.131Z", "description": "Copies AMI to eu-west-2 and exports to S3" } ] }, "tags": {} }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/5", "name": "MyBasicRecipe", "version": "2019.12.03/5", "platform": "Windows", "state": { "status": "AVAILABLE" }, "owner": "123456789012", "dateCreated": "2020-02-18T16:51:48.403Z", "outputResources": { "amis": [ { "region": "us-west-2", "image": "ami-a1b2c3d4567890ab", "name": "MyBasicRecipe 2020-02-18T16-52-18.965Z", "description": "This example image recipe creates a Windows 2016 image." } ] }, "tags": {} }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/4", "name": "MyBasicRecipe", "version": "2019.12.03/4", "platform": "Windows", "state": { "status": "AVAILABLE" }, "owner": "123456789012", "dateCreated": "2020-02-18T16:50:01.827Z", "outputResources": { "amis": [ { "region": "us-west-2", "image": "ami-a1b2c3d4567890ab", "name": "MyBasicRecipe 2020-02-18T16-50-32.280Z", "description": "This example image recipe creates a Windows 2016 image." } ] }, "tags": {} }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/3", "name": "MyBasicRecipe", "version": "2019.12.03/3", "platform": "Windows", "state": { "status": "AVAILABLE" }, "owner": "123456789012", "dateCreated": "2020-02-14T23:14:13.597Z", "outputResources": { "amis": [ { "region": "us-west-2", "image": "ami-a1b2c3d4567890ab", "name": "MyBasicRecipe 2020-02-14T23-14-44.243Z", "description": "This example image recipe creates a Windows 2016 image." } ] }, "tags": {} }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/2", "name": "MyBasicRecipe", "version": "2019.12.03/2", "platform": "Windows", "state": { "status": "FAILED", "reason": "SSM execution 'a1b2c3d4-5678-90ab-cdef-EXAMPLE11111' failed with status = 'Failed' and failure message = 'Step fails when it is verifying the command has completed. Command a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 returns unexpected invocation result: \n{Status=[Failed], ResponseCode=[1], Output=[\n----------ERROR-------\nfailed to run commands: exit status 1], OutputPayload=[{\"Status\":\"Failed\",\"ResponseCode\":1,\"Output\":\"\\n----------ERROR-------\\nfailed to run commands: exit status 1\",\"CommandId\":\"a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\"}], CommandId=[a1b2c3d4-5678-90ab-cdef-EXAMPLE11111]}. Please refer to Automation Service Troubleshooting Guide for more diagnosis details.'" }, "owner": "123456789012", "dateCreated": "2020-02-14T22:57:42.593Z", "outputResources": { "amis": [] }, "tags": {} } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用list-image-pipeline-images

AWS CLI

列出影像配管管線影像

下列list-image-pipeline-images範例會列出由特定影像管線建立的所有影像。

aws imagebuilder list-image-pipeline-images \ --image-pipeline-arn arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imagePipelineList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline", "name": "MyWindows2016Pipeline", "description": "Builds Windows 2016 Images", "platform": "Windows", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "distributionConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "imageTestsConfiguration": { "imageTestsEnabled": true, "timeoutMinutes": 60 }, "schedule": { "scheduleExpression": "cron(0 0 * * SUN)", "pipelineExecutionStartCondition": "EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE" }, "status": "ENABLED", "dateCreated": "2020-02-19T19:04:01.253Z", "dateUpdated": "2020-02-19T19:04:01.253Z", "tags": { "KeyName": "KeyValue" } }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/sam", "name": "PipelineName", "platform": "Linux", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/recipe-name-a1b2c3d45678/1.0.0", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/infrastructureconfiguration-name-a1b2c3d45678", "imageTestsConfiguration": { "imageTestsEnabled": true, "timeoutMinutes": 720 }, "status": "ENABLED", "dateCreated": "2019-12-16T18:19:02.068Z", "dateUpdated": "2019-12-16T18:19:02.068Z", "tags": { "KeyName": "KeyValue" } } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用list-image-recipes

AWS CLI

列出圖片食譜

下列list-image-recipes範例會列出您所有的影像配方。

aws imagebuilder list-image-recipes

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageRecipeSummaryList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03", "name": "MyBasicRecipe", "platform": "Windows", "owner": "123456789012", "parentImage": "arn:aws:imagebuilder:us-west-2:aws:image/windows-server-2016-english-full-base-x86/2019.x.x", "dateCreated": "2020-02-19T18:54:25.975Z", "tags": { "KeyName": "KeyValue" } }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/recipe-name-a1b2c3d45678/1.0.0", "name": "recipe-name-a1b2c3d45678", "platform": "Linux", "owner": "123456789012", "parentImage": "arn:aws:imagebuilder:us-west-2:aws:image/amazon-linux-2-x86/2019.11.21", "dateCreated": "2019-12-16T18:19:00.120Z", "tags": { "KeyName": "KeyValue" } } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListImageRecipes中的。

下列程式碼範例會示範如何使用list-images

AWS CLI

列出影像的步驟

下列list-images範例會列出您有權存取的所有語意版本。

aws imagebuilder list-images

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageVersionList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03", "name": "MyBasicRecipe", "version": "2019.12.03", "platform": "Windows", "owner": "123456789012", "dateCreated": "2020-02-14T21:29:18.810Z" } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考ListImages中的。

下列程式碼範例會示範如何使用list-infrastructure-configurations

AWS CLI

列出基礎架構組態

下列list-infrastructure-configurations範例會列出您所有的基礎結構組態。

aws imagebuilder list-infrastructure-configurations

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "infrastructureConfigurationSummaryList": [ { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "name": "MyExampleInfrastructure", "description": "An example that will retain instances of failed builds", "dateCreated": "2020-02-19T19:11:51.858Z", "tags": {} }, { "arn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/infrastructureconfiguration-name-a1b2c3d45678", "name": "infrastructureConfiguration-name-a1b2c3d45678", "dateCreated": "2019-12-16T18:19:01.038Z", "tags": { "KeyName": "KeyValue" } } ] }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用list-tags-for-resource

AWS CLI

列出特定資源的標籤

下列list-tags-for-resource範例會列出特定資源的所有標籤。

aws imagebuilder list-tags-for-resource \ --resource-arn arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline

輸出:

{ "tags": { "KeyName": "KeyValue" } }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用put-component-policy

AWS CLI

若要將資源策略套用至元件

下列put-component-policy命令會將資源策略套用至組建元件,以啟用組建元件的跨帳戶共用。我們建議您使用記憶體 CLI 指令create-resource-share。如果您使用 EC2 Image Builder CLI 命令put-component-policy,您還必須使用 RAM CLI 命令promote-resource-share-create-from-policy,以便共用資源的所有主體都可以看到資源。

aws imagebuilder put-component-policy \ --component-arn arn:aws:imagebuilder:us-west-2:123456789012:component/examplecomponent/2019.12.02/1 \ --policy '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetComponent", "imagebuilder:ListComponents" ], "Resource": [ "arn:aws:imagebuilder:us-west-2:123456789012:component/examplecomponent/2019.12.02/1" ] } ] }'

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "componentArn": "arn:aws:imagebuilder:us-west-2:123456789012:component/examplecomponent/2019.12.02/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用put-image-policy

AWS CLI

若要將資源策略套用至映像

下列put-image-policy命令會將資源策略套用至映像檔,以啟用映像檔的跨帳戶共用。我們建議您使用記憶體 CLI 指令 create-resource-share。如果您使用 EC2 Image Builder CLI 命令 put-image-policy,您還必須使用 RAM CLI 命令 promote-resource-share-create來自政策,以便與其共用資源的所有主體都可以看到資源。

aws imagebuilder put-image-policy \ --image-arn arn:aws:imagebuilder:us-west-2:123456789012:image/example-image/2019.12.02/1 \ --policy '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetImage", "imagebuilder:ListImages" ], "Resource": [ "arn:aws:imagebuilder:us-west-2:123456789012:image/example-image/2019.12.02/1" ] } ] }'

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageArn": "arn:aws:imagebuilder:us-west-2:123456789012:image/example-image/2019.12.02/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考PutImagePolicy中的。

下列程式碼範例會示範如何使用put-image-recipe-policy

AWS CLI

若要將資源策略套用至影像方案

下列put-image-recipe-policy命令會將資源策略套用至映像配方,以啟用映像配方的跨帳戶共用。我們建議您使用記憶體 CLI 指令create-resource-share。如果您使用 EC2 Image Builder CLI 命令put-image-recipe-policy,您還必須使用 RAM CLI 命令promote-resource-share-create-from-policy,以便共用資源的所有主體都可以看到資源。

aws imagebuilder put-image-recipe-policy \ --image-recipe-arn arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/example-image-recipe/2019.12.02 \ --policy '{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetImageRecipe", "imagebuilder:ListImageRecipes" ], "Resource": [ "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/example-image-recipe/2019.12.02" ] } ] }'

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/example-image-recipe/2019.12.02/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用start-image-pipeline-execution

AWS CLI

手動啟動影像管線

下列start-image-pipeline-execution範例會手動啟動映像管線。

aws imagebuilder start-image-pipeline-execution \ --image-pipeline-arn arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "clientToken": "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "imageBuildVersionArn": "arn:aws:imagebuilder:us-west-2:123456789012:image/mybasicrecipe/2019.12.03/1" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用tag-resource

AWS CLI

標記資源的步驟

下列tag-resource範例會使用 JSON 檔案將資源新增至 EC2 Image Builder 並加上標記。

aws imagebuilder tag-resource \ --cli-input-json file://tag-resource.json

tag-resource.json 的內容:

{ "resourceArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline", "tags": { "KeyName: "KeyValue" } }

此命令不會產生輸出。

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考TagResource中的。

下列程式碼範例會示範如何使用untag-resource

AWS CLI

若要從資源中移除標籤

下列untag-resource範例會使用 JSON 檔案從資源中移除標籤。

aws imagebuilder untag-resource \ --cli-input-json file://tag-resource.json

untag-resource.json 的內容:

{ "resourceArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline", "tagKeys": [ "KeyName" ] }

此命令不會產生輸出。

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

  • 如需 API 詳細資訊,請參閱AWS CLI 命令參考UntagResource中的。

下列程式碼範例會示範如何使用update-distribution-configuration

AWS CLI

若要更新發佈組態

下列update-distribution-configuration範例會使用 JSON 檔案更新散發組態。

aws imagebuilder update-distribution-configuration \ --cli-input-json file://update-distribution-configuration.json

update-distribution-configuration.json 的內容:

{ "distributionConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "description": "Copies AMI to eu-west-2 and exports to S3", "distributions": [ { "region": "us-west-2", "amiDistributionConfiguration": { "name": "Name {{imagebuilder:buildDate}}", "description": "An example image name with parameter references" } }, { "region": "eu-west-2", "amiDistributionConfiguration": { "name": "My {{imagebuilder:buildVersion}} image {{imagebuilder:buildDate}}" } } ] }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用update-image-pipeline

AWS CLI

若要更新映像管線

下列update-image-pipeline範例會使用 JSON 檔案更新映像管線。

aws imagebuilder update-image-pipeline \ --cli-input-json file://update-image-pipeline.json

update-image-pipeline.json 的內容:

{ "imagePipelineArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-pipeline/mywindows2016pipeline", "imageRecipeArn": "arn:aws:imagebuilder:us-west-2:123456789012:image-recipe/mybasicrecipe/2019.12.03", "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "distributionConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:distribution-configuration/myexampledistribution", "imageTestsConfiguration": { "imageTestsEnabled": true, "timeoutMinutes": 120 }, "schedule": { "scheduleExpression": "cron(0 0 * * MON)", "pipelineExecutionStartCondition": "EXPRESSION_MATCH_AND_DEPENDENCY_UPDATES_AVAILABLE" }, "status": "DISABLED" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。

下列程式碼範例會示範如何使用update-infrastructure-configuration

AWS CLI

更新基礎架構組態

下列update-infrastructure-configuration範例會使用 JSON 檔案更新基礎結構組態。

aws imagebuilder update-infrastructure-configuration \ --cli-input-json file:/update-infrastructure-configuration.json

update-infrastructure-configuration.json 的內容:

{ "infrastructureConfigurationArn": "arn:aws:imagebuilder:us-west-2:123456789012:infrastructure-configuration/myexampleinfrastructure", "description": "An example that will terminate instances of failed builds", "instanceTypes": [ "m5.large", "m5.2xlarge" ], "instanceProfileName": "EC2InstanceProfileForImageFactory", "securityGroupIds": [ "sg-a48c95ef" ], "subnetId": "subnet-a48c95ef", "logging": { "s3Logs": { "s3BucketName": "bucket-name", "s3KeyPrefix": "bucket-path" } }, "terminateInstanceOnFailure": true, "snsTopicArn": "arn:aws:sns:us-west-2:123456789012:sns-name" }

輸出:

{ "requestId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

如需詳細資訊,請參閱 EC2 Image Builder 使用者指南中的使用 AWS CLI 設定和管理 EC2 Image Builder 映像管道。