无法使用ruby脚本从amazon s3中删除文件 [英] unable to delete file from amazon s3 using ruby script
问题描述
我使用 aws-sdk-ruby 删除保存在存储桶中的文件在我的亚马逊s3帐户,但我不明白为什么我能够使用下面的代码从S3存储桶中删除所需的文件。
I am using aws-sdk-ruby for deleting a file saved in a bucket in my amazon s3 account, but i can't figure out why i am able to delete the desired file from S3 bucket using the following code.
这是我的代码
this is my code
require 'aws-sdk-v1'
require 'aws-sdk'
ENV['AWS_ACCESS_KEY_ID'] = "XXXXXXX"
ENV["AWS_SECRET_ACCESS_KEY"] = '/ZZZZZZZZ'
ENV['AWS_REGION'] = 'us-east-1'
s3 = Aws::S3::Resource.new
bucket = s3.bucket('some-bucket')
obj = bucket.object('https://s3.amazonaws.com/some-bucket/38ac8226-fa72-4aee-8c3d-a34a1db77b91/some_image.jpg')
obj.delete
推荐答案
查看文档( http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html )我认为它应该看起来像这样(注意方括号,并且对象的键不包括域,而不是创建 Aws :: S3 :: Resource $ c的对象$ c $>创建
AWS :: S3
类的对象):
Looking at the documentation (http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/S3Object.html) I think it should look like this (note the square brackets and that the object's key does not include the domain and instead of creating object of Aws::S3::Resource
create object of AWS::S3
class):
bucket = s3.buckets['some-bucket']
obj = bucket.objects['38ac8226-fa72-4aee-8c3d-a34a1db77b91/some_image.jpg']
obj.delete
这篇关于无法使用ruby脚本从amazon s3中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!