Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅
中国的 Amazon Web Services 服务入门
(PDF)。
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
创建一个 Amazon RAM 共享您的映像生成器资源的资源
要共享映像生成器组件、图像或配方,必须将其添加到 Amazon Resource Access Manager 资源共享。资源共享指定要共享的资源以及与您共享这些资源的使用者。
可以提供以下选项用于共享资源。
选项 1:创建 RAM 资源共享
创建 RAM 资源共享时,只需一步即可共享您所拥有的组件、映像或配方。使用以下方法之一创建资源共享:
-
控制台
要使用创建资源共享 Amazon RAM 控制台,请参阅 分享 Amazon 你拥有的资源 在 Amazon RAM 用户指南。
-
Amazon CLI
要使用创建资源共享 Amazon RAM 命令行界面,运行 创建资源共享 命令在 Amazon CLI。
-
PowerShell
使用创建资源共享 Amazon Tools for PowerShell,运行 New-RAMResourceShare 来自 cmdlet AWS.Tools.RAM 模块。
共享资源的第二个选项涉及两个步骤,在中运行命令 Amazon CLI 要么 Amazon Tools for PowerShell 两者兼而有之。第一步使用映像生成器命令将基于资源的策略应用于共享资源。第二步将资源升级为 RAM 资源共享,这样与您共享该资源的所有委托人都可以看到该资源。
-
应用资源策略
要成功应用资源策略,必须确保与之共享的账户有权访问任何基础资源。
对于您可以共享的每种资源类型,选择所用工具的选项卡。
在 PowerShell 示例,每个 cmdlet 都采用资源的亚马逊资源名称 (ARN) 和策略文档。这个 Policy 参数将策略 JSON 作为字符串。每个示例都将策略存储在 $policy 变量作为这里的单引号字符串。
Image
您可以将资源策略应用于映像,以允许其他用户在其配方中作为基础映像使用该映像。
- Amazon CLI
-
为了识别 Amazon 要与之共享图像的负责人,运行 放置图片政策 中的映像生成器命令 Amazon CLI:
aws imagebuilder put-image-policy \
--image-arn arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-image/2019.12.03/1 \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetImage",
"imagebuilder:ListImages"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-image/2019.12.03/1"
]
}
]
}'
- PowerShell
-
为了识别 Amazon 要与之共享图像的负责人,运行 Write-EC2IBImagePolicy cmdlet:
$policy = @'
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetImage",
"imagebuilder:ListImages"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-image/2019.12.03/1"
]
}
]
}
'@
Write-EC2IBImagePolicy -ImageArn arn:aws:imagebuilder:us-west-2:111122223333:image/my-example-image/2019.12.03/1 `
-Policy $policy
组件
您可以将资源策略应用于构建或测试组件,以启用跨账户共享。此政策允许其他账户在其配方中使用您的组件。与您共享的账户必须具有访问该组件引用的任何资源的权限。例如,该组件可能会引用私有存储库中的文件。
- Amazon CLI
-
为了识别 Amazon 要与之共享组件的负责人,运行 放置组件策略 中的映像生成器命令 Amazon CLI:
aws imagebuilder put-component-policy \
--component-arn arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-component/2019.12.03/1 \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetComponent",
"imagebuilder:ListComponents"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-component/2019.12.03/1"
]
}
]
}'
- PowerShell
-
为了识别 Amazon 要与之共享组件的负责人,运行 Write-EC2IBComponentPolicy cmdlet:
$policy = @'
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetComponent",
"imagebuilder:ListComponents"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-component/2019.12.03/1"
]
}
]
}
'@
Write-EC2IBComponentPolicy -ComponentArn arn:aws:imagebuilder:us-west-2:111122223333:component/my-example-component/2019.12.03/1 `
-Policy $policy
映像配方
您可以将资源策略应用于映像配方,以便启用跨账户共享。该政策允许其他账户使用你的食谱在其账户中创建图片。与您共享的账户必须具有访问配方引用的任何资源的权限。这些可以包括基础映像和选定的组件。
- Amazon CLI
-
为了识别 Amazon 要与之共享图像配方的负责人,运行 放置图片食谱政策 中的映像生成器命令 Amazon CLI:
aws imagebuilder put-image-recipe-policy \
--image-recipe-arn arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-image-recipe/2019.12.03 \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetImageRecipe",
"imagebuilder:ListImageRecipes"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-image-recipe/2019.12.03"
]
}
]
}'
- PowerShell
-
为了识别 Amazon 要与之共享图像配方的负责人,运行 Write-EC2IBImageRecipePolicy cmdlet:
$policy = @'
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetImageRecipe",
"imagebuilder:ListImageRecipes"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-image-recipe/2019.12.03"
]
}
]
}
'@
Write-EC2IBImageRecipePolicy -ImageRecipeArn arn:aws:imagebuilder:us-west-2:111122223333:image-recipe/my-example-image-recipe/2019.12.03 `
-Policy $policy
容器配方
您可以将资源策略应用于容器配方,以便启用跨账户共享。该政策允许其他账户使用你的食谱在其账户中创建图片。与您共享的账户必须具有访问配方引用的任何资源的权限。这些可以包括基础映像和选定的组件。
- Amazon CLI
-
为了识别 Amazon 要与之共享容器配方的负责人,运行 放置容器配方政策 中的映像生成器命令 Amazon CLI:
aws imagebuilder put-container-recipe-policy \
--container-recipe-arn arn:aws:imagebuilder:us-west-2:111122223333:container-recipe/my-example-container-recipe/2021.12.03 \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetContainerRecipe",
"imagebuilder:ListContainerRecipes"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:container-recipe/my-example-container-recipe/2021.12.03"
]
}
]
}'
- PowerShell
-
为了识别 Amazon 要与之共享容器配方的负责人,运行 Write-EC2IBContainerRecipePolicy cmdlet:
$policy = @'
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"444455556666"
]
},
"Action": [
"imagebuilder:GetContainerRecipe",
"imagebuilder:ListContainerRecipes"
],
"Resource": [
"arn:aws:imagebuilder:us-west-2:111122223333:container-recipe/my-example-container-recipe/2021.12.03"
]
}
]
}
'@
Write-EC2IBContainerRecipePolicy -ContainerRecipeArn arn:aws:imagebuilder:us-west-2:111122223333:container-recipe/my-example-container-recipe/2021.12.03 `
-Policy $policy
为了设置正确的策略来共享和取消共享某个资源,资源所有者必须具有 imagebuilder:put* 权限。
-
提升为 RAM 资源共享
要使与之共享该资源的所有委托人可见,请运行 促进根据策略创建的资源共享 Amazon RAM 命令在 Amazon CLI。
促进资源共享 Amazon Tools for PowerShell,运行 Convert-RAMPolicyBasedResourceShareToPromoted 来自 cmdlet AWS.Tools.RAM 模块。