Causes of "403 AccessDenied" or "The OwnerId that your Access Key Id associated to is forbidden" errors
When you call an SDK or an API, a "403 AccessDenied" or "The OwnerId that your Access Key Id associated to is forbidden for this operation" error is typically caused by cross-region queue access, an incorrect OwnerId, or incorrectly configured RAM user permissions.
Issue
When you use an SDK or call an API to access Simple Message Queue (formerly MNS), the following error is returned:
[Error Code]:403 AccessDenied [Message]:The OwnerId that your Access Key Id associated to is forbidden for this operation.
Causes
This error can be caused by any of the following:
-
Accessing a Simple Message Queue (formerly MNS) queue across regions.
-
If you use a private network endpoint, both the producer and consumer must be deployed on ECS instances in the same region as the queue. Otherwise, the error occurs.
-
If you use a public network endpoint, the producer and consumer can be deployed on-premises or on ECS instances in any region with public access enabled.
-
-
The OwnerId is incorrectly configured. The OwnerId is your Alibaba Cloud account ID. To find your account ID, log in to the SMQ console and hover over your profile avatar in the upper-right corner.
-
An invalid RAM user is used, or the RAM user's permissions are incorrectly configured.
-
When you call an HTTP API, the request URL does not match the request header. For details, see the More information section.
-
A non-official SDK is used.
Solution
Follow these steps to troubleshoot the issue:
-
Log in to the SMQ console. Switch to the region where your MNS instance is located and click Queues to confirm that your Simple Message Queue (formerly MNS) instance exists. In the Actions column, click Details. On the details page, find the endpoint information in the Endpoint section.
NoteIn the endpoint address, the numeric string before
.mnsis the OwnerId.The Endpoint section displays two types of endpoints: a public access endpoint in the format
http(s)://<OwnerId>.mns.<region>.aliyuncs.comand a private access endpoint in the formathttp(s)://<OwnerId>.mns.<region>-internal.aliyuncs.com. -
Verify that the endpoint addresses and OwnerId used by the producer and consumer are correct.
-
Verify that your producer and consumer deployments meet the following requirements and adjust your configuration if necessary.
-
If you use a private network endpoint, the producer and consumer must be deployed on ECS instances in the same region as the queue.
-
If you use a public network endpoint, the producer and consumer can be deployed on-premises or on ECS instances in any region with public access enabled.
-
-
If you use a RAM user to access the Simple Message Queue (formerly MNS) instance, check the permission policy of the RAM user. For example, if a policy grants access to the resources in the following code block, but the RAM user attempts to access the
/queues/busi-msn/messagesqueue, the request fails due to a permission mismatch. For more information about how to configure a RAM user, see Create a RAM user."Resource": [ "acs:mns:*:*:/queues", "acs:mns:*:*:/queues/busi-test", "acs:mns:*:*:/queues/busi-test/*" -
If the error persists after you complete the preceding steps, the cause might be a non-official SDK or a mismatch between the URL and the header in an HTTP API call. For details, see the More information section.
More information
Simple Message Queue (formerly MNS) was known as MQS before its commercial release. The endpoint format differs before and after the commercial release.
-
Before commercial release, the endpoint address was
http://y9g.mqs-cn-beijing.aliyuncs.com/. -
After commercial release, the endpoint address is
http://44404.mns.cn-beijing.aliyuncs.com/.
The preceding endpoint addresses are examples only. Use your actual endpoints. In this topic, http://y9g.mqs-cn-beijing.aliyuncs.com/ is referred to as the old endpoint, and http://44404.mns.cn-beijing.aliyuncs.com/ is referred to as the new endpoint.
After its commercial release, Simple Message Queue (formerly MNS) introduced a new protocol version while remaining backward compatible with the old version. The service uses the x-mns-version HTTP header to distinguish between protocol versions.
-
If a request includes the
x-mns-version: 2015-06-06header, the service uses the new protocol to process the request. -
If a request includes an
x-mqs-version: xxxx-xx-xxheader, the service uses the old protocol to process the request.
Therefore, you must follow these rules when you use Simple Message Queue (formerly MNS):
-
When you call an HTTP API, the request URL must correspond to the version specified in the header. If you use a new endpoint URL with an old version header such as
x-mqs-version: xxxx-xx-xx, the service returns an error. -
Use official Alibaba Cloud SDKs. Third-party SDKs might not distinguish between old and new endpoint formats, which can cause issues when using a new endpoint. Official SDKs provide guaranteed support and offer batch operations such as
BatchSendMessageandBatchReceiveMessage. These features, which are unavailable in many third-party SDKs, improve message processing efficiency. If you prefer not to change your existing code and must use a third-party SDK (not recommended), contact Alibaba Cloud technical support to obtain an old endpoint.