全部產品
Search
文件中心

Resource Management:CreateResourceShare - 建立共用單元

更新時間:Oct 13, 2025

建立共用單元。

介面說明

阿里雲資源共用(Resource Sharing)支援將一個帳號下的指定資源共用給一個或多個目標帳號使用。更多資訊,請參見資源共用概述

本文將提供一個樣本,在cn-hangzhou地區,使用資來源目錄管理帳號建立一個名為test的共用單元,將 VPC 交換器vsw-bp183p93qs667muql****共用給資來源目錄內的成員172050525300****

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

下表是API對應的授權資訊,可以在RAM權限原則語句的Action元素中使用,用來給RAM使用者或RAM角色授予調用此API的許可權。具體說明如下:

  • 操作:是指具體的許可權點。

  • 存取層級:是指每個操作的存取層級,取值為寫入(Write)、讀取(Read)或列出(List)。

  • 資源類型:是指操作中支援授權的資源類型。具體說明如下:

    • 對於必選的資源類型,用前面加 * 表示。

    • 對於不支援資源級授權的操作,用全部資源表示。

  • 條件關鍵字:是指雲產品自身定義的條件關鍵字。

  • 關聯操作:是指成功執行操作所需要的其他許可權。操作者必須同時具備關聯操作的許可權,操作才能成功。

操作

存取層級

資源類型

條件關鍵字

關聯操作

resourcesharing:CreateResourceShare

create

*全部資源

*

  • resourcesharing:RequestedAllowExternalTargets
  • resourcesharing:Target
  • resourcesharing:RequestedResourceType
  • resourcesharing:ResourceArn

請求參數

名稱

類型

必填

描述

樣本值

ResourceShareName

string

共用單元名稱。

長度範圍:1~50 個字元。

格式:允許輸入英文字母、數字、中文、半形句號(.)、底線(_)或短劃線(-)。

test

Resources

array<object>

共用資源列表。

object

共用資源列表。

ResourceId

string

共用資源 ID。

N 的取值範圍:1~5,即每次最多添加 5 個共用資源。

說明

Resources.N.ResourceIdResources.N.ResourceType成對出現,需要同時設定。

vsw-bp183p93qs667muql****

ResourceType

string

共用資源類型。

N 的取值範圍:1~5,即每次最多添加 5 個共用資源。

支援共用的資源類型,請參見支援資源共用的雲端服務

說明

Resources.N.ResourceIdResources.N.ResourceType成對出現,需要同時設定。

VSwitch

Targets

array

資源使用者。

172050525300****

string

資源使用者。取值:

  • AllowExternalTargetsfalse時,資源使用者可以為資來源目錄 ID、資源夾 ID 或成員 ID。

  • AllowExternalTargetstrue時,資源使用者可以為阿里雲帳號 ID、資來源目錄 ID、資源夾 ID、成員 ID 或阿里雲服務。

更多資訊,請參見資源共用方式查看資來源目錄 ID查看資源夾 ID查看成員 ID

N 的取值範圍:1~5,即每次最多添加 5 個資源使用者。

172050525300****

ResourceArns

array

共用資源 ARN 列表。

N 的取值範圍:1~5,即每次最多添加 5 個共用資源。

string

共用資源 ARN。

說明

資源 ARN 格式請參見支援資源共用的雲端服務

acs:vpc:cn-shanghai:103755469187****:vswitch/vsw-uf62b11ue4m8oz2di****

PermissionNames

array

共用許可權名稱。為空白時,系統自動綁定資源類型關聯的預設許可權。具體資訊,請參見許可權庫

string

共用許可權名稱。為空白時,系統自動綁定資源類型關聯的預設許可權。具體資訊,請參見許可權庫

AliyunRSDefaultPermissionVSwitch

AllowExternalTargets

boolean

是否允許共用給資來源目錄外的帳號。取值:

  • false(預設值):僅允許資來源目錄內共用。

  • true:允許共用給任意帳號。

false

ResourceGroupId

string

資源群組 ID。

rg-aekz5nlvlak****

TargetProperties

array<object>

資源使用者屬性。

說明

僅當資源使用者為阿里雲服務時可以設定該參數。

object

資源使用者屬性。

說明

僅當資源使用者為阿里雲服務時可以設定該參數。

Property

string

資源使用者屬性參數。例如:您可以設定資源共用的時間段。timeRangeType取值:

  • timeRange:指定時間段。

  • day:全天。

說明

TargetProperties.N.TargetIdTargetProperties.N.Property成對出現,需要同時設定。

{ "timeRange":{ "timeRangeType":"timeRange", "beginAtTime":"00:00", "timezone":"UTC+8", "endAtTime":"19:59" } }

TargetId

string

資源使用者 ID。

說明

TargetProperties.N.TargetIdTargetProperties.N.Property成對出現,需要同時設定。

172050525300****

Tag

array<object>

標籤列表。最多可以綁定 20 個標籤。

object

標籤列表。

Key

string

標籤鍵。

說明

最多支援 128 個字元,不能以aliyunacs:開頭,不能包含http://或者https://

k1

Value

string

標籤值。

說明

最多支援 128 個字元,不能以acs:開頭,不能包含http://或者https://

v1

返回參數

名稱

類型

描述

樣本值

object

返回參數。

RequestId

string

請求 ID。

2C3FA051-61DC-4F3E-81E9-E4830524DF4B

ResourceShare

object

共用單元資訊。

AllowExternalTargets

boolean

是否允許共用給資來源目錄外的帳號。取值:

  • false:僅允許資來源目錄內共用。

  • true:允許共用給任意帳號。

false

CreateTime

string

共用單元建立時間。

2020-12-03T08:02:22.413Z

ResourceShareId

string

共用單元 ID。

rs-qSkW1HBY****

ResourceShareName

string

共用單元名稱。

test

ResourceShareOwner

string

共用單元歸屬者。

151266687691****

ResourceShareStatus

string

共用單元狀態。取值:

  • Active:已啟用。

  • Pending:待確認。

  • Deleting:刪除中。

  • Deleted:已刪除。

說明

Deleted 狀態的共用單元記錄,會在 48~96 小時內被系統自動刪除。

Active

UpdateTime

string

共用單元更新時間。

2020-12-03T08:02:22.413Z

樣本

正常返回樣本

JSON格式

{
  "RequestId": "2C3FA051-61DC-4F3E-81E9-E4830524DF4B",
  "ResourceShare": {
    "AllowExternalTargets": false,
    "CreateTime": "2020-12-03T08:02:22.413Z",
    "ResourceShareId": "rs-qSkW1HBY****",
    "ResourceShareName": "test",
    "ResourceShareOwner": "151266687691****",
    "ResourceShareStatus": "Active",
    "UpdateTime": "2020-12-03T08:02:22.413Z"
  }
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 InvalidParameter.ResourceShareName The ResourceShareName is invalid. 共用單元名稱無效。
400 InvalidParameter.ResourceShareName.Length The maximum length of ResourceShareName exceeds 50 characters. 共用單元名稱字數超長(最大50字元)。
400 InvalidParameter.Resources The Resources is invalid. 選定的共用資源無效。
400 InvalidParameter.Resources.Duplicate The Resources contains duplicate values. 選定的共用資源有重複項。
400 InvalidParameter.Resources.Length The maximum number of Resources exceeds 5. 選定的共用資源數量超限(最大5個)。
400 InvalidParameter.Targets The Targets is invalid. 資源使用者的參數不符合規則。
400 InvalidParameter.Targets.Duplicate The Targets contains duplicate values. 資源使用者有重複項。
400 InvalidParameter.Targets.Length The maximum number of Targets exceeds 5. 資源使用者數量超限(最大5個)。
400 InvalidTarget The shared target does not exist in the resource directory. 資源使用者不在資來源目錄內。
400 InvalidParameter The specified parameter is invalid. 參數無效。
400 MissingParameter.ResourceShareName You must specify ResourceShareName. 共用單元名稱缺失。
400 InvalidParameter.ResourceType The ResourceType is invalid. 傳入的資源類型錯誤。
400 InvalidParameter.PermissionNames.Duplicate The PermissionNames duplicate values. 參數PermissionNames重複。
400 InvalidParameter.PermissionNames.Length The maximum length of PermissionNames exceeds quota limit. PermissionNames長度超限。
400 InvalidParameter.TargetProperties The TargetProperties is invalid. TargetProperties參數無效。
400 InvalidParameter.TargetProperties.Duplicate The TargetProperties contains duplicate values. TargetProperties包含重複的參數。
400 InvalidParameter.TargetProperties.Length The TargetProperties beyond the length limit. TargetProperties數量超過限制。
400 InvalidParameter.ResourceArns The ResourceArns is invalid. ResourceArns參數無效。
400 InvalidParameter.ResourceArns.Duplicate The ResourceArns contains duplicate values. 資源ARN參數有重複項。
400 InvalidParameter.ResourceArns.Length The ResourceArns beyond the length limit. 資源ARN數量超限(最大5個)。
400 InvalidParameter.ResourceConflict Both Resources and ResourceArns cannot be specified simultaneously. Please provide only one of these parameters. Resources 和 ResourceArns 不能同時指定。請僅提供其中一個參數。
400 NotSupport.ResourceType.ResourcesParameter The Resources parameter does not support this resource type. Please use ResourceArns instead. 當前資源類型不支援Resources參數,請使用ResourceArns參數。
404 EntityNotExists.Permission The resource share permission does not exist. 共用許可權不存在。
409 NotEnableSharingWithResourceDirectory You have not enabled sharing with your Resource Directory. 未開啟與資來源目錄組織的共用。
409 AccountNotInResourceDirectory The account is not a master or a member of a resource directory. 資源使用者不在資來源目錄內。
409 QuotaExceeded.ResourceShare.Count The maximum number of ResourceShare exceeds the limit. 共用單元數量超出限制。
409 EntityAlreadyExists.ResourceShare The specified resource share ID already exists. 共用單元ID已存在。
409 QuotaExceeded.SharedResource.Count The maximum number of shared resources per account exceeds the limit. 共用的資源超出單個帳號最大限制。
409 ShareWithYourself You cannot share resources with yourself. 資源使用者不能是自己。
409 NotManagementAccount Only the management account of the service is allowed to share such resources. 當前資源類型僅支援資來源目錄的管理帳號共用資源。如仍需使用當前帳號,請聯絡管理帳號將當前帳號設定為當前資源類型所屬可信服務的委派管理員帳號。
409 QuotaExceeded.PendingInvitations The maximum number of pending invitations exceeds the limit. 邀請數量超出限制。
409 InvalidTarget.LegalEntityMismatch The target account does not have the same legal entity as the resource owner account. 共用目標帳號的企業名稱與共用者不一致。
409 ExternalTargetsNotAllowed.ResourceType The resource share includes resource types that cannot be shared with accounts outside the resource directory. 共用單元中包含不支援組織外共用的資源類型。
409 InvalidTarget.SiteMismatch Cross-site resource sharing is not supported. 共用目標帳號與共用者網站不一致。
409 NotSupport.Service.ExistInOtherResourceShare The resource type has been shared to the target service through other resourceShare. Please share it in the same resourceShare. 此資源類型已經通過其他共用單元共用給目標雲端服務,請在同一個共用單元中共用。
409 NotSupport.Service.AssociateConflict The same resource cannot be shared repeatedly to the target service. 同一個資源不允許重複共用給目標雲端服務。

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情