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

本文档 AWS CLI 仅适用于版本 1。有关版本 2 的文档 AWS CLI,请参阅版本 2 用户指南

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用的 Image Builder 示例 AWS CLI

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

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

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

主题

操作

以下代码示例显示了如何使用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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" ] } ] }" }

有关更多信息,请参阅 Im EC2 age Builder 用户指南中的使用 AWS CLI < https://docs.aws.amazon.com/imagebuilder/ latest/userguide/managing-image-builder-cli .html>`__ 设置和管理 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": {} } }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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": {} } }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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": {} } }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" ] } ] }" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" ] } ] }" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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": {} } }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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": {} } }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" } } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" } } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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": {} } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" } } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" } } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" } } ] }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" } }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用put-component-policy

AWS CLI

将资源策略应用于组件

以下put-component-policy命令将资源策略应用于构建组件,以实现构建组件的跨账户共享。我们建议您使用该RAMCLI命令create-resource-share。如果使用 EC2 Image Builder CLI RAM CLI 命令put-component-policy,则还必须使用该命令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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用put-image-policy

AWS CLI

将资源策略应用于图像

以下put-image-policy命令将资源策略应用于图像以实现跨账户共享图像。我们建议您使用该RAMCLI命令 create-resource-share。如果使用 Im EC2 age Builder CLI 命令 put-image-policy,则还必须使用RAMCLI命令 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用put-image-recipe-policy

AWS CLI

将资源策略应用于图像配方

以下put-image-recipe-policy命令将资源策略应用于图像配方,以启用图像配方的跨账户共享。我们建议您使用该RAMCLI命令create-resource-share。如果使用 EC2 Image Builder CLI RAM CLI 命令put-image-recipe-policy,则还必须使用该命令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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" } }

此命令不生成任何输出。

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" ] }

此命令不生成任何输出。

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。

以下代码示例显示了如何使用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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age 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" }

有关更多信息,请参阅《EC2Image Builder 用户指南》 AWS CLI中的 “使用设置和管理 Im EC2 age Builder 图像管道”。