All Products
Search
Document Center

Resource Management:AssociateResourceShare

Last Updated:Dec 15, 2025

Associates resources or principals with a resource share.

Operation description

This topic provides an example of how to add the vSwitch vsw-bp183p93qs667muql**** to the resource share rs-6GRmdD3X**** in the cn-hangzhou region and share it with member 172050525300**** of a resource directory.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

resourcesharing:AssociateResourceShare

update

*All Resource

*

  • resourcesharing:Target

  • resourcesharing:RequestedResourceType

  • resourcesharing:ResourceArn

None

Request parameters

Parameter

Type

Required

Description

Example

ResourceShareId

string

Yes

The ID of the resource share.

rs-6GRmdD3X****

Resources

array<object>

No

The shared resources.

object

No

The shared resources.

ResourceType

string

No

The type of the shared resource.

The value of N can be from 1 to 5. This means that you can add up to 5 shared resources at a time.

For more information about the resource types that can be shared, see Services that work with Resource Sharing.

Note

Resources.N.ResourceId and Resources.N.ResourceType must be specified in pairs.

VSwitch

ResourceId

string

No

The ID of the shared resource.

The value of N can be from 1 to 5. This means that you can add up to 5 shared resources at a time.

Note

Resources.N.ResourceId and Resources.N.ResourceType must be specified in pairs.

vsw-bp183p93qs667muql****

Targets

array

No

The principals.

172050525300****

string

No

The principal. Valid values:

  • If you set AllowExternalTargets to false, you can share resources only within your resource directory. The principal can be the ID of a resource directory, folder, or member.

  • If you set AllowExternalTargets to true, you can share resources with any account. The principal can be the ID of an Alibaba Cloud account, resource directory, folder, or member, or the name of an Alibaba Cloud service.

For more information, see Resource Sharing overview, View the ID of a resource directory, View the ID of a folder, or View the ID of a member.

The value of N can be from 1 to 5. This means that you can add up to 5 principals at a time.

172050525300****

ResourceArns

array

No

The Alibaba Cloud Resource Names (ARNs) of the shared resources.

The value of N can be from 1 to 5. This means that you can add up to 5 shared resources at a time.

string

No

The ARN of the shared resource.

Note

For more information about the format of an ARN, see Services that work with Resource Sharing.

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

PermissionNames

array

No

The permissions. If you do not specify this parameter, the system automatically associates the default permission with the resource type. For more information, see Permission library.

string

No

The permission. If you do not specify this parameter, the system automatically associates the default permission with the resource type. For more information, see Permission library.

AliyunRSDefaultPermissionVSwitch

TargetProperties

array<object>

No

The properties of the principals.

Note

This parameter is available only when the principal is an Alibaba Cloud service.

object

No

The properties of the principal.

Note

This parameter is available only when the principal is an Alibaba Cloud service.

TargetId

string

No

The ID of the principal.

Note

TargetProperties.N.TargetId and TargetProperties.N.Property must be specified in pairs.

172050525300****

Property

string

No

The properties of the principal. For example, you can specify a time range for the resource sharing. Valid values of timeRangeType:

  • timeRange: A specified time range.

  • day: The whole day.

Note

TargetProperties.N.TargetId and TargetProperties.N.Property must be specified in pairs.

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

Response elements

Element

Type

Description

Example

object

The response parameters.

RequestId

string

The ID of the request.

111FB84A-60A9-403E-9067-E55D7EE95BD1

ResourceShareAssociations

array<object>

The information about the resources or principals that are associated with the resource share.

object

The information about the resources or principals that are associated with the resource share.

UpdateTime

string

The time when the association was updated.

  • If you set AssociationType to Resource, the value of this parameter is the time when the shared resource was updated.

  • If you set AssociationType to Target, the value of this parameter is the time when the principal was updated.

2020-12-04T09:40:41.246Z

ResourceArn

string

The ARN of the associated resource.

Note

This parameter is not available when the value of AssociationType is Target.

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

ResourceShareName

string

The name of the resource share.

test

CreateTime

string

The time when the association was created. This parameter is returned in the following situations:

  • If you set AssociationType to Resource, the value of this parameter is the time when the shared resource was associated.

  • If you set AssociationType to Target, the value of this parameter is the time when the principal was associated.

2020-12-04T09:40:41.246Z

EntityType

string

The type of the associated entity. Valid values:

  • If the entity is a resource, the value of this parameter is the type of the resource. For more information, see Services that work with Resource Sharing.

  • If the entity is a principal, the value of this parameter is Account.

VSwitch

ResourceShareId

string

The ID of the resource share.

rs-6GRmdD3X****

AssociationStatusMessage

string

The reason why the association failed.

The reason for the association failure.

AssociationType

string

The type of the association. Valid values:

  • Resource: A resource.

  • Target: A principal.

Resource

AssociationStatus

string

The status of the association. Valid values:

  • Associating: The association is being created.

  • Associated: The association is created.

  • Failed: The association failed.

  • Disassociating: The entity is being disassociated..

  • Disassociated: The entity is disassociated.

Note

The system deletes the records of entities in the Failed or Disassociated state within 48 to 96 hours.

Associating

TargetProperty

string

The properties of the principal. For example, the time range within which the resource is shared.

Note

This parameter is returned only when the principal is an Alibaba Cloud service.

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

EntityId

string

The ID of the associated entity. Valid values:

  • If you set AssociationType to Resource, the value of this parameter is the ID of the resource.

  • If you set AssociationType to Target, the value of this parameter is the ID of the principal.

vsw-bp183p93qs667muql****

Examples

Success response

JSON format

{
  "RequestId": "111FB84A-60A9-403E-9067-E55D7EE95BD1",
  "ResourceShareAssociations": [
    {
      "UpdateTime": "2020-12-04T09:40:41.246Z",
      "ResourceArn": "acs:vpc:cn-shanghai:103755469187****:vswitch/vsw-uf62b11ue4m8oz2di****",
      "ResourceShareName": "test",
      "CreateTime": "2020-12-04T09:40:41.246Z",
      "EntityType": "VSwitch",
      "ResourceShareId": "rs-6GRmdD3X****",
      "AssociationStatusMessage": "The reason for the association failure.",
      "AssociationType": "Resource",
      "AssociationStatus": "Associating",
      "TargetProperty": "{\n    \"plan\":{\n        \"timeRangeType\":\"timeRange\",\n        \"beginAtTime\":\"00:00\",\n        \"timezone\":\"UTC+8\",\n        \"endAtTime\":\"19:59\"\n    }\n}",
      "EntityId": "vsw-bp183p93qs667muql****"
    }
  ]
}

Error codes

HTTP status code

Error code

Error message

Description

400

MissingParameter.ResourceShareId

You must specify ResourceShareId.

You must specify ResourceShareId.

400

InvalidParameter.ResourceShareId

The ResourceShareId is invalid.

The ResourceShareId parameter is invalid.

400

InvalidParameter.Resources

The Resources is invalid.

The specified shared resource is invalid.

400

InvalidParameter.Resources.Duplicate

The Resources contains duplicate values.

The specified Resources parameter contains duplicate values.

400

InvalidParameter.Resources.Length

The maximum number of Resources exceeds 5.

The number of specified shared resources cannot exceed 5.

400

InvalidParameter.Targets

The Targets is invalid.

The specified Targets parameter is invalid.

400

InvalidParameter.Targets.Duplicate

The Targets contains duplicate values.

The specified Targets parameter contains duplicate values.

400

InvalidParameter.Targets.Length

The maximum number of Targets exceeds 5.

The number of Targets values cannot exceed 5.

400

InvalidTarget

The shared target does not exist in the resource directory.

The specified Targets value is not a member in the resource directory.

400

ResourceAndTargetBothEmpty

Either a resource or a shared target must be specified.

You must specify a resource or a resource account.

400

InvalidParameter

The specified parameter is invalid.

The specified parameter is invalid.

400

InvalidParameter.ResourceType

The ResourceType is invalid.

The specified ResourceType parameter is invalid.

400

InvalidParameter.PermissionNames.Duplicate

The PermissionNames duplicate values.

Duplicate values are specified for the PermissionNames parameter.

400

InvalidParameter.PermissionNames.Length

The maximum length of PermissionNames exceeds quota limit.

The length of the value specified for the PermissionNames parameter exceeds the limit.

400

InvalidParameter.TargetProperties

The TargetProperties is invalid.

The TargetProperties is invalid.

400

InvalidParameter.TargetProperties.Duplicate

The TargetProperties contains duplicate values.

TargetProperties contains duplicate parameters.

400

InvalidParameter.TargetProperties.Length

The TargetProperties beyond the length limit.

The TargetProperties beyond the length limit.

400

InvalidParameter.ResourceArns

The ResourceArns is invalid.

The ResourceArns parameter is invalid.

400

InvalidParameter.ResourceArns.Duplicate

The ResourceArns contains duplicate values.

The ResourceArns contains duplicate values.

400

InvalidParameter.ResourceArns.Length

The ResourceArns beyond the length limit.

The maximum number of ResourceArns exceeds 5.

400

InvalidParameter.ResourceConflict

Both Resources and ResourceArns cannot be specified simultaneously. Please provide only one of these parameters.

Both Resources and ResourceArns cannot be specified simultaneously. Please provide only one of these parameters.

400

NotSupport.ResourceType.ResourcesParameter

The Resources parameter does not support this resource type. Please use ResourceArns instead.

The Resources parameter does not support this resource type. Please use ResourceArns instead.

404

EntityNotExists.ResourceShare

The resource share does not exist in the current account.

The resource share does not exist in the current account.

404

EntityNotExists.Permission

The resource share permission does not exist.

You do not have the required permissions.

409

NotEnableSharingWithResourceDirectory

You have not enabled sharing with your Resource Directory.

You have not enabled sharing with Resource Directory.

409

AccountNotInResourceDirectory

The account is not a master or a member of a resource directory.

The specified Targets value is not a member in the resource directory.

409

ResourceShareStatusMismatchAction

The status of the resource share does not allow the specified operation.

The status of the resource share does not allow the specified operation.

409

QuotaExceeded.SharedResource.Count

The maximum number of shared resources per account exceeds the limit.

The maximum number of Resources values per account is exceeded.

409

ShareWithYourself

You cannot share resources with yourself.

You cannot share resources with yourself.

409

AssociateConflict

You cannot perform the operation while disassociation operation is being performed.

The association operation is not supported while an disassociation is being performed.

409

NotManagementAccount

Only the management account of the service is allowed to share such resources.

Only the management account of the resource directory can be used to share the current type of resource. If you still want to use the current account, contact the owner of the management account to configure the current account as a delegated administrator account of the trusted service to which the resource belongs.

409

QuotaExceeded.PendingInvitations

The maximum number of pending invitations exceeds the limit.

The number of invitations exceeds the upper limit.

409

InvalidTarget.LegalEntityMismatch

The target account does not have the same legal entity as the resource owner account.

The enterprise name of the principal is inconsistent with that of the resource owner.

409

ExternalTargetsNotAllowed.ResourceType

The resource share includes resource types that cannot be shared with accounts outside the resource directory.

The resource share contains resources that do not support this operation.

409

InvalidTarget.SiteMismatch

Cross-site resource sharing is not supported.

The principal and resource owner are registered at different sites.

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.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.