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

使用 AWS CLI 的 Image Builder 示例

以下代码示例演示了如何将 AWS Command Line Interface与 Image Builder 结合使用,来执行操作和实现常见场景。

操作 是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示了如何使用 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 镜像管道

  • 有关 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 设置和管理 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 镜像管道

  • 有关 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 设置和管理 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 Image Builder 用户指南》中的“使用 AWS CLI 设置和管理 EC2 Image Builder 镜像管道”<https://docs.aws.amazon.com/imagebuilder/latest/userguide/managing-image-builder-cli.html>

  • 有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 GetComponentPolicy

以下代码示例演示了如何使用 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 命令将资源策略应用于一个生成组件,以启用跨账户的生成组件共享。我们建议您使用 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 设置和管理 EC2 Image Builder 镜像管道

  • 有关 API 详细信息,请参阅《AWS CLI 命令参考》中的 PutComponentPolicy

以下代码示例演示了如何使用 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 设置和管理 EC2 Image Builder 镜像管道

  • 有关 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 设置和管理 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 镜像管道