I tried to establish connection to my aws s3 account like this in my irb console -
AWS::S3::Base.establish_connection!(:access_key_id => 'my access key', :secret_access_key => 'my secret key', :server => "s3-ap-southeast-1.amazonaws.com")
And it works well and prompt this -
=> #<AWS::S3::Connection:0x8cd86d0 @options={:server=>"s3-ap-southeast-1.amazonaws.com", :port=>80, :access_key_id=>"my access key", :secret_access_key=>"my secret key"}, @access_key_id="my access key", @secret_access_key="my secret key", @http=#<Net::HTTP s3-ap-southeast-1.amazonaws.com:80 open=false>>
I have a bucket which is based on "Singapore Region" and for that endpoint i.e. server is: s3-ap-southeast-1.amazonaws.com So when I try to access it using this command -
AWS::S3::Service.buckets
it fetches all buckets in my account correctly -
=> [#<AWS::S3::Bucket:0x8d291fc @attributes={"name"=>"bucket1", "creation_date"=>2011-06-28 10:08:58 UTC}, @object_cache=[]>, #<AWS::S3::Bucket:0x8d291c0 @attributes={"name"=>"bucket2", "creation_date"=>2011-07-04 07:15:21 UTC}, @object_cache=[]>, #<AWS::S3::Bucket:0x8d29184 @attributes={"name"=>"bucket3", "creation_date"=>2011-07-04 07:39:21 UTC}, @object_cache=[]>]
where as bucket1 belongs to Singapore Region and other 2 to US Region. So, when I do this -
AWS::S3::Bucket.find("bucket1")
it shows me this error:
AWS::S3::PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/error.rb:38:in `raise' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:72:in `request' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/base.rb:88:in `get' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:102:in `find' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:145:in `objects' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:313:in `reload!' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:242:in `objects' from /home/surya/.rvm/gems/ruby-1.9.2-p180/gems/aws-s3-0.6.2/lib/aws/s3/bucket.rb:253:in `each' from (irb):5 from /home/surya/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'
I don't understand the reason why this is happening cause yesterday same thing was working well. Any guess?? am I missing something here??
The "403 Access Denied" error can occur due to the following reasons: Your AWS Identity and Access Management (IAM) user or role doesn't have permissions for both s3:GetBucketPolicy and s3:PutBucketPolicy. The bucket policy denies your IAM identity permission for s3:GetBucketPolicy and s3:PutBucketPolicy.
Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object. In the objects list, choose the name of the object for which you want to set permissions. Choose Permissions.
To get access to your bucket again, sign in to the Amazon S3 console as the AWS account root user, and then delete the bucket policy. Warning: Don't use the root user for everyday tasks. Limit the use of these credentials to only the tasks that require you to sign in as the root user.
Before you connect, try using
AWS::S3::DEFAULT_HOST.replace "s3-ap-southeast-1.amazonaws.com"
Another thing you can do (although this isn't really a good solution) is to access the bucket with the array index
AWS::S3::Bucket.list[0]
If anyone is getting the issue where you are trying to do different regions for different platforms, you can setup your config like this:
AWS.config({ :region => 'us-west-2', :access_key_id => ENV["AWS_ACCESS_KEY_ID"], :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"], :s3 => { :region => 'us-east-1' } })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With