How to authenticate to Bluemix S3 Lite?

2019-07-24 02:39发布

I'm trying to use S3 API with Bluemix object storage using the following code:

import boto3, pprint, sys;
s3 = boto3.Session().client(
    service_name="s3",
    region_name="us-geo",
    endpoint_url="https://s3-api.us-geo.objectstorage.softlayer.net", 
    aws_access_key_id="auto-generated-apikey-<redacted>", 
    aws_secret_access_key="<redacted>"); 
pprint.pprint(s3.list_buckets());

but keep getting AccessDenied error:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access Denied</Message>
    <Resource></Resource>
    <RequestId><redacted></RequestId>
    <httpStatusCode>403</httpStatusCode>
</Error>

I took aws_access_key_id and aws_secret_access_key from the "Service Credentials" tab. I used similar code for AWS S3, and it worked. What am I missing?

1条回答
孤傲高冷的网名
2楼-- · 2019-07-24 02:43

The IAM-enabled cos uses a slightly different syntax for client creation that is supported by a fork of the boto3 library.

Here’s an example in the docs: https://console.bluemix.net/docs/services/cloud-object-storage/libraries/python.html

查看更多
登录 后发表回答