Symbolic links let you access frequently used objects in a bucket through shortcuts, similar to shortcuts in Windows. This topic describes how to create and get symbolic links using the OSS SDK for Python V2.
Prerequisites
Before you begin, ensure that you have:
An OSS bucket in your target region
The
oss:PutObjectpermission to create symbolic linksThe
oss:GetObjectpermission to get symbolic links
For details on granting permissions, see Grant custom permissions to a RAM user.
Usage notes
Note: The sample code uses the China (Hangzhou) region (cn-hangzhou) with a public endpoint. If you access OSS from another Alibaba Cloud service in the same region, use an internal endpoint instead. For supported regions and endpoints, see OSS regions and endpoints.Method definitions
put_symlink(request: PutSymlinkRequest, **kwargs) → PutSymlinkResult
get_symlink(request: GetSymlinkRequest, **kwargs) → GetSymlinkResultFor the complete method definitions, see put_symlink and get_symlink.
Request parameters
PutSymlinkRequest — see PutSymlinkRequest
| Parameter | Description |
|---|---|
bucket | The name of the bucket. |
key | The name of the symbolic link object. |
target | The name of the target object the symbolic link points to. |
GetSymlinkRequest — see GetSymlinkRequest
| Parameter | Description |
|---|---|
bucket | The name of the bucket. |
key | The name of the symbolic link object. |
Return values
| Type | Description |
|---|---|
PutSymlinkResult | The return value for creating a symbolic link. See PutSymlinkResult. |
GetSymlinkResult | The return value for getting a symbolic link. See GetSymlinkResult. |
Get a symbolic link
import argparse
import alibabacloud_oss_v2 as oss
parser = argparse.ArgumentParser(description="get symlink sample")
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--key', help='The name of the object.', required=True)
def main():
args = parser.parse_args()
# Load credentials from environment variables
credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()
cfg = oss.config.load_default()
cfg.credentials_provider = credentials_provider
cfg.region = args.region
if args.endpoint is not None:
cfg.endpoint = args.endpoint
client = oss.Client(cfg)
result = client.get_symlink(oss.GetSymlinkRequest(
bucket=args.bucket,
key=args.key,
))
print(f'status code: {result.status_code},'
f' request id: {result.request_id},'
f' version id: {result.version_id},'
f' target: {result.target},'
f' etag: {result.etag},'
)
if __name__ == "__main__":
main()For the complete sample, see get_symlink.py.