

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

# 為您的 Image Builder 資源建立 AWS RAM 資源共享
<a name="manage-shared-resources-share"></a>

若要共用映像建置器元件、映像或配方，您必須將其新增至 AWS Resource Access Manager 資源共用。資源共用會指定要共用的資源，以及與其共用的消費者。

下列選項可用於共用您的 資源。

## 選項 1：建立 RAM 資源共享
<a name="share-opt1-create-resource-share"></a>

當您建立 RAM 資源共享時，您可以在單一步驟中共享您擁有的元件、映像或配方。使用下列其中一種方法來建立資源共享：
+ 

**主控台**  
若要使用 AWS RAM 主控台建立資源共享，請參閱*AWS RAM 《 使用者指南*》中的[共享您擁有 AWS 的資源](https://docs.aws.amazon.com/ram/latest/userguide/working-with-sharing.html#working-with-sharing-create)。
+ 

**AWS CLI**  
若要使用 AWS RAM 命令列界面建立資源共享，請在 中執行 **[create-resource-share](https://docs.aws.amazon.com/cli/latest/reference/ram/create-resource-share.html)**命令 AWS CLI。

## 選項 2：套用資源政策並提升為現有的資源共享
<a name="share-opt2-promote-resource-share"></a>

共用資源的第二個選項包含兩個步驟，在 中 AWS CLI 為兩者執行命令。第一步使用 中的映像建置器命令 AWS CLI ，將資源型政策套用至共用資源。第二個步驟使用 中的 **[promote-resource-share-created-from-policy](https://docs.aws.amazon.com/cli/latest/reference/ram/promote-resource-share-created-from-policy.html)** AWS RAM 命令將資源提升為 RAM 資源共享 AWS CLI ，以確保與您共用資源的所有主體都可看見該資源。

1. 

**套用資源政策**

   若要成功套用資源政策，您必須確保要共用的帳戶具有存取任何基礎資源的許可。

   選擇與適用命令的資源類型相符的標籤。

------
#### [ Image ]

   您可以將資源政策套用至映像，以允許其他人在其配方中使用它做為基礎映像。

   在 中執行**[put-image-policy](https://docs.aws.amazon.com/cli/latest/reference//imagebuilder/put-image-policy.html)**映像建置器命令 AWS CLI，以識別要共用映像的 AWS 委託人。

   ```
   aws imagebuilder put-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" ] } ] }'
   ```

------
#### [ Component ]

   您可以將資源政策套用至建置或測試元件，以啟用跨帳戶共用。此命令提供其他帳戶在其配方中使用您的元件的許可。若要成功套用資源政策，您必須確保您共用的帳戶具有存取共用元件所參考之任何資源的許可，例如私有儲存庫上託管的檔案。

   在 中執行 **[put-component-policy](https://docs.aws.amazon.com/cli/latest/reference//imagebuilder/put-component-policy.html)** Image Builder 命令 AWS CLI，以識別要共用元件的 AWS 委託人。

   ```
   aws imagebuilder put-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" ] } ] }'
   ```

------
#### [ Image recipe ]

   您可以將資源政策套用至映像配方，以啟用跨帳戶共用。此命令提供其他帳戶使用配方在其帳戶中建立映像的許可。若要成功套用資源政策，您必須確保要共用的帳戶具有存取配方參考之任何資源的許可，例如基礎映像或選取的元件。

   在 中執行**[put-image-recipe-policy](https://docs.aws.amazon.com/cli/latest/reference//imagebuilder/put-image-recipe-policy.html)**映像建置器命令 AWS CLI，以識別要共用映像的 AWS 委託人。

   ```
   aws imagebuilder put-image-recipe-policy --image-recipe-arn arn:aws:imagebuilder:us-west-{{2:123456789012}}:image-recipe/{{my-example-image-recipe}}/2019.12.03 --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" ] } ] }'
   ```

------
#### [ Container recipe ]

   您可以將資源政策套用至容器配方，以啟用跨帳戶共用。此命令提供其他帳戶使用配方在其帳戶中建立映像的許可。若要成功套用資源政策，您必須確保要共用的帳戶具有存取配方參考之任何資源的許可，例如基礎映像或選取的元件。

   在 中執行**[put-container-recipe-policy](https://docs.aws.amazon.com/cli/latest/reference//imagebuilder/put-container-recipe-policy.html)**映像建置器命令 AWS CLI，以識別要共用映像的 AWS 委託人。

   ```
   aws imagebuilder put-container-recipe-policy --container-recipe-arn arn:aws:imagebuilder:us-west-{{2:123456789012}}:container-recipe/{{my-example-container-recipe}}/2021.12.03 --policy '{ "Version": "2012-10-17",		 	 	  "Statement": [ { "Effect": "Allow", "Principal": { "AWS": [ "123456789012" ] }, "Action": [ "imagebuilder:GetContainerRecipe", "imagebuilder:ListContainerRecipes" ], "Resource": [ "arn:aws:imagebuilder:us-west-{{2:123456789012}}:container-recipe/{{my-example-container-recipe}}/2021.12.03" ] } ] }'
   ```

------
**注意**  
若要設定正確的共用和取消共用資源政策，資源擁有者必須具有 `imagebuilder:put*` 許可。

1. 

**提升為 RAM 資源共享**

   為了確保與您共用資源的所有主體都可看見資源，請在 中執行 **[promote-resource-share-created-from-policy](https://docs.aws.amazon.com/cli/latest/reference/ram/promote-resource-share-created-from-policy.html)** AWS RAM 命令 AWS CLI。