• Register
0 votes
207 views

Problem :

I want to delete the uploaded image files with the AWS-SDK-Core Ruby Gem.

I have the below code:

require 'aws-sdk-core'
def pull_picture(picture)
    Aws.config = {
        :access_key_id => ENV["AWS_ACCESS_KEY_ID"],
        :secret_access_key => ENV["AWS_SECRET_ACCESS_KEY"],
        :region => 'us-west-2'
    }
    s3 = Aws::S3::Client.new
    test = s3.get_object(
        :bucket => ENV["AWS_S3_BUCKET"],
        :key => picture.image_url.split('/')[-2],   
    )
end

But I am getting the below error:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

I am sure that the region is correct as if I try to change it to us-east-1, the below error comes up:

The specified key does not exist.

May I know how can I resolve this issue?

6 5 3
7,540 points

1 Answer

0 votes

Solution :

I had faced the similar kind of error in the recent past as my bucket was in region us-west-2 and my URL pattern had the bucketname in the path. When I changed my URL pattern to have bucketname as URL subdomain to grab the files and it just worked for me.

e.g. My previous URL was as follows:

https://s3.amazonaws.com/bucketname/filePath/filename

Then I replaced it as follows :

https://bucketname.s3.amazonaws.com/filePath/filename

 OR

I also have faced the same issue in the past. After a lot of research I found that the root cause of issue was with my com.amazonaws dependencies. After I added the dependencies my error got disappeared.

9 7 4
38,600 points

Related questions

0 votes
1 answer 10 views
10 views
Problem: I am trying to create a Security Group using the AWS SDK but it is failing to authenticate it. For a very specific Access Key and Secret Key I have already provided the Administrative rights and then also it fails to validate. I also tried ... .java:1146) at com.sunil.demo.ec2.SetupEC2.createSecurityGroup(SetupEC2.java:84) at com.sunil.demo.ec2.SetupEC2.main(SetupEC2.java:25)
asked Aug 24 Raphael Pacheco 4.9k points
0 votes
1 answer 152 views
152 views
Problem : I am trying to install the gem using gem install mygem or update a RubyGems using gem update --system, and it fails with below error: ERROR:  While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory. Does anyone have the idea how to fix this error?
asked Jan 22 jwilliam 3.9k points
0 votes
2 answers 370 views
370 views
Problem : I am facing following AWS error the authorization mechanism you have provided is not supported. please use aws4-hmac-sha256.
asked Nov 16, 2019 peterlaw 6.9k points