Why are no Amazon S3 authentication handlers ready?

后端 未结 12 1991
广开言路
广开言路 2020-12-13 08:21

I have my $AWS_ACCESS_KEY_ID and $AWS_SECRET_ACCESS_KEY environment variables set properly, and I run this code:

import boto
conn = boto.connect_s3()
         


        
相关标签:
12条回答
  • 2020-12-13 08:58

    I found my answer here.

    On Unix: first setup aws config:

    #vim ~/.aws/config
    [default]
    region = Tokyo
    aws_access_key_id = xxxxxxxxxxxxxxxx
    aws_secret_access_key = xxxxxxxxxxxxxxxxx
    

    And set environment variables

    export AWS_ACCESS_KEY_ID="aws_access_key_id"
    export AWS_SECRET_ACCESS_KEY="aws_secret_access_key"
    
    0 讨论(0)
  • 2020-12-13 08:59

    I'm a newbie to both python and boto but was able to reproduce your error (or at least the last line of your error.)

    You are most likely failing to export your variables in bash. if you just define then, they're only valid in the current shell, export them and python inherits the value. Thus:

    $ AWS_ACCESS_KEY_ID="SDFGRVWGFVVDWSFGWERGBSDER"
    

    will not work unless you also add:

    $ export AWS_ACCESS_KEY_ID
    

    Or you can do it all on the same line:

    $ export AWS_ACCESS_KEY_ID="SDFGRVWGFVVDWSFGWERGBSDER"
    

    Likewise for the other value. You can also put this in your .bashrc (assuming bash is your shell and assuming you remember to export)

    0 讨论(0)
  • 2020-12-13 09:01

    I was having this issue with a flask application on ec2. I didn't want to put credentials in the application, but managed permission via IAM roles. That way can avoid hard-coding keys into code. Then I set a policy in the AWS console (I didn't even code it, I just used the policy generator)

    My code is exactly like OP's. The other solutions here are good but there is a way to grand permission without hard-coding access keys.

    1. Create an IAM security group that grants access to the S3 resource
    2. Give the policy to the EC2 instance
    3. Connect using nothing but boto.connect_s3() #no keys needed
    0 讨论(0)
  • 2020-12-13 09:03

    I had previously used s3-parallel-put successfully but it inexplicably stopped working, giving the error above. This despite having exported the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.

    The solution was to specify the the credentials in the boto config file:

    $ nano ~/.boto
    

    Enter the credentials like so:

    [Credentials]
    aws_access_key_id = KEY_ID
    aws_secret_access_key = SECRET_ACCESS_KEY
    
    0 讨论(0)
  • 2020-12-13 09:06

    See latest boto s3 introduction:

    from boto.s3.connection import S3Connection
    conn = S3Connection(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
    
    0 讨论(0)
  • 2020-12-13 09:07

    I see you call them AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY.

    When it seems they should be set as AWSAccessKeyId & AWSSecretKey.

    0 讨论(0)
提交回复
热议问题