You can configure a symbolic link to point to a frequently accessed object in the target bucket for easier object retrieval. After configuring a symbolic link for an object, you can use the symbolic link to quickly access the object. A symbolic link works in a similar manner as the shortcut in Windows. This topic describes how to manage symbolic links in a versioning-enabled bucket.

Create a symbolic link

A symbolic link can have multiple versions. When you create a symbolic link in a versioning-enabled bucket,the version ID of the link is automatically generated by OSS and is returned as the x-oss-version-id header in the response. You can create a symbolic link and point it to the current version of the target object.
Note In a versioning-enabled bucket, a symbolic link cannot be created for a delete marker.
The following code provides an example on how to create a symbolic link in a versioning-enabled bucket:
# -*- coding: utf-8 -*-
import oss2

# Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console.
auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>')
# The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint.
bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')

objectName = '<yourTargetObjectName>'
symlink = '<yourSymlink>'

# Upload a symbolic link.
result = bucket.put_symlink(objectName, symlink)
# View the version ID of the uploaded symbolic link.
print('symlink versionid:', result.versionid)

For more information about how to create a symbolic link, see PutSymlink.

Obtain a symbolic link

By default, GetSymlink obtains the current version of the target symbolic link. You can specify the version ID in the request to obtain the specified version of a symbolic link. If the current version of the target symbolic link is a delete marker, OSS returns the 404 Not Found error and includes oss-delete-marker = true and x-oss-version-id in the response header.
Note You must have the read permission on a symbolic link to obtain it.
The following code provides an example on how to obtain a symbolic link:
# -*- coding: utf-8 -*-
import oss2

# Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console.
auth = oss2.Auth('<yourAccessKeyId>', '<yourAccessKeySecret>')
# The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint.
bucket = oss2.Bucket(auth, 'http://oss-cn-hangzhou.aliyuncs.com', '<yourBucketName>')

symlink = '<yourSymlink>'

# Obtain the symbolic link with the specified version ID.
params = dict()
params['versionId'] = ‘yourSymlinkVersionId>’
result = bucket.get_symlink(symlink, params=params)
# View the version ID of the returned symbolic link.
print('get symlink versionid:', result.versionid)

For more information about how to obtain a symbolic link, see GetSymlink.