使用 的影像建置器範例 AWS CLI - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

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

使用 的影像建置器範例 AWS CLI

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

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

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

主題

動作

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

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

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

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

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 Image Builder 使用者指南中的使用 AWS CLI <https://docs.aws.amazon.com/imagebuilder/latest/userguide/managingWord-image-builder-cli.html>`__ 設定和管理 Word Image Builder 映像管道。 EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

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

AWS CLI

將資源政策套用至元件

下列put-component-policy命令會將資源政策套用至建置元件,以啟用建置元件的跨帳戶共用。我們建議您使用 RAM 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 設定和管理 Word Image Builder 映像管道EC2

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

AWS CLI

將資源政策套用至映像

下列put-image-policy命令會將資源政策套用至映像,以啟用映像的跨帳戶共用。我們建議您使用 RAM CLI create-resource-share。如果您使用 EC2 Image Builder CLI 命令 put-image-policy,您還必須使用 RAM CLI命令 promote-resource-share-create-from-policy,才能讓與資源共用的所有主體看見資源。

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 設定和管理 Word Image Builder 映像管道EC2

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

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

AWS CLI

將資源政策套用至映像配方

下列put-image-recipe-policy命令會將資源政策套用至映像配方,以啟用映像配方的跨帳戶共用。建議您使用 RAM 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

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

AWS CLI

標記資源

下列tag-resource範例會使用 EC2 檔案將資源新增至 JSON 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

  • 如需 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2

下列程式碼範例示範如何使用 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 設定和管理 Word Image Builder 映像管道EC2