简体   繁体   中英

AWS S3 Files from Python

 from boto.s3.connection import S3Connection

 AWS_KEY = 'abc'
 AWS_SECRET = 'xyz'

 print AWS_KEY
 print AWS_SECRET

 aws_connection = S3Connection(AWS_KEY, AWS_SECRET)

 print aws_connection


 #Create the bucket in a specific region.

 bucket = aws_connection.create_bucket('mybucket0005',location='us-west-2')

This code i am running for creating bucket;but getting below Error,

Traceback (most recent call last):

File "<ipython-input-63-f14efbf83dc6>", line 16, in <module>
bucket = aws_connection.create_bucket('mybucket0005',location='us-west-2')

File "/usr/local/lib/python2.7/dist-packages/boto/s3/connection.py", line 625, in create_bucket
response.status, response.reason, body)

S3ResponseError: S3ResponseError: 403 Forbidden
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>InvalidAccessKeyId</Code><Message>The AWS Access Key Id you     provided does not exist in our records.</Message>
<AWSAccessKeyId>abc</AWSAccessKeyId><RequestId>930E9DC30F239D11</RequestId><HostId>xlaLEeS7C4KYgLOKOShF9uGhLgM+4OdFYiLGn7F5JvKty38kAir5vSNSDH7q5TWFPO/6BEjeHaA=</HostId></Error>

I want to Access AWS S3 Files from Python.Help me out.

The message in this case is quite explicit

The AWS Access Key Id you provided does not exist in our records.

There is no abc key. If you have an AWS account, go to the IAM console and take the key from there: http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html

Even better create a new user that will only be used for CLI. You need to make sure this user will have rights on your s3 bucket (if the goal is to manage that). Once you have the user created, create security credentials that you can use from your script.

Another point: DO NOT EXPOSE YOUR AWS KEY directly in your script. Check the Boto doc on how to manage your credentials and use them from your script.

Did you check if your AWS keys are correct? You can use Commandeer App to Test it out from the new/existing account screen. 从 Commandeer App 测试您的 AWS 凭证

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM