简体   繁体   English

如何使用 wget 从 S3 存储桶下载文件?

[英]How can I download a file from an S3 bucket with wget?

I can push some content to an S3 bucket with my credentials through S3cmd tool with s3cmd put contentfile S3://test_bucket/test_file我可以使用我的凭据通过 S3cmd 工具将一些内容推送到 S3 存储桶,使用 s3cmd put contentfile S3://test_bucket/test_file

Question is, I am required to download the content from this bucket in other computers that don't have s3cmd installed on them, BUT they have wget installed.问题是,我需要在其他没有安装 s3cmd 但安装了 wget 的计算机上从此存储桶中下载内容。

when I try to download some content from my bucket with wget I get this:当我尝试使用 wget 从我的存储桶中下载一些内容时,我得到了这个:

 https://s3.amazonaws.com/test_bucket/test_file
--2013-08-14 18:17:40--  `https`://s3.amazonaws.com/test_bucket/test_file
Resolving s3.amazonaws.com (s3.amazonaws.com)... [ip_here]
Connecting to s3.amazonaws.com (s3.amazonaws.com)|ip_here|:port... connected.
HTTP request sent, awaiting response... 403 Forbidden
`2013`-08-14 18:17:40 ERROR 403: Forbidden.

I have manually made this bucket public through the Amazon AWS web console.我已经通过 Amazon AWS Web 控制台手动公开了这个存储桶。

Question is : How can I download content from an S3 bucket with wget?问题是:如何使用 wget 从 S3 存储桶下载内容? into a txt local file?到一个txt本地文件?

You should be able to access it from a url created as follows:您应该能够从如下创建的 url 访问它:

http://{bucket-name}.s3.amazonaws.com/<path-to-file>

Now, say your s3 file path is:现在,假设您的 s3 文件路径是:

s3://test-bucket/test-folder/test-file.txt

You should be able to wget this file with following url:您应该能够使用以下网址获取此文件:

http://test-bucket.s3.amazonaws.com/test-folder/test-file.txt

  1. Go to S3 console转到 S3 控制台

  2. Select your object选择您的对象

  3. Click 'Object Actions'单击“对象操作”

  4. Choose 'Download As'选择“下载为”

  5. Use your mouse right-click to 'Copy Link Address'使用鼠标右键单击“复制链接地址”

  6. Then use the command:然后使用命令:

    wget --no-check-certificate --no-proxy 'http://your_bucket.s3.amazonaws.com/your-copied-link-address.jpg'

AWS cli has a 'presign' command that one can use to get a temporary public URL to a private s3 resource. AWS cli 有一个“presign”命令,可用于获取私有 s3 资源的临时公共 URL。

aws s3 presign s3://private_resource

You can then use wget to download the resource using the presigned URL.然后,您可以使用 wget 使用预签名 URL 下载资源。

Got it ... If you upload a file in an S3 bucket with S3CMD with the --acl public flag then one shall be able to download the file from S3 with wget easily ...明白了...如果您使用带有 --acl 公共标志的 S3CMD 将文件上传到 S3 存储桶中,则可以使用 wget 从 S3 轻松下载文件...

Conclusion: In order to download with wget, first of one needs to upload the content in S3 with s3cmd put --acl public --guess-mime-type <test_file> s3://test_bucket/test_file结论:为了使用 wget 下载,首先需要使用s3cmd put --acl public --guess-mime-type <test_file> s3://test_bucket/test_file上传 S3 中的内容

alternatively you can try:或者,您可以尝试:

s3cmd setacl --acl-public --guess-mime-type s3://test_bucket/test_file

notice the setacl flag above.注意上面的 setacl 标志。 THAT WILL set the file in s3 accessible publicly then you can execute the wget http://s3.amazonaws.com/test_bucket/test_file这将在 s3 中设置可公开访问的文件,然后您可以执行wget http://s3.amazonaws.com/test_bucket/test_file

I had the same situation for couple of times.我有几次同样的情况。 It's the fastest and the easiest way to download any file from AWS using CLI is next command:使用 CLI 从 AWS 下载任何文件的最快和最简单的方法是下一个命令:

aws s3 cp s3://bucket/dump.zip dump.zip

File downloaded way faster than via wget, at least if you are outside of US.文件下载的速度比通过 wget 快,至少如果您在美国境外。

I had the same error and I solved it by adding a Security Groups Inbound rule:我有同样的错误,我通过添加安全组入站规则解决了它:

HTTPS type at port 443 to my IP address ( as I'm the only one accessing it ) for the subnet my instance was in.我的实例所在子网的 HTTPS 类型在端口 443 到我的 IP 地址(因为我是唯一一个访问它的人)。

Hope it helps anyone who forgot to include this希望它可以帮助任何忘记包含此内容的人

Please make sure that the read permission has been given correctly.请确保已正确授予读取权限。

If you do not want to enter any account/password, just by wget command without any password, make sure the permission is like the following setting shows.如果您不想输入任何帐户/密码,只需通过 wget 命令不输入任何密码,确保权限类似于以下设置所示。

By Amazon S3 -> Buckets -> Permisions - Edit Check the Object for "Everyone (public access)" and save changes.通过 Amazon S3 -> 存储桶 -> 权限 - 编辑 检查对象是否为“所有人(公共访问)”并保存更改。 permission setting like this - screenshot像这样的权限设置 - 截图

or choose the objest and go to "Actions" -> "Make public", would do the same thing under permission settings.或选择对象并转到“操作”->“公开”,在权限设置下会做同样的事情。

incase you do not have access to install aws client on ur Linux machine try below method.如果您无权在您的 Linux 机器上安装 aws 客户端,请尝试以下方法。

  • got to the bucket and click on download as button.到桶并单击下载为按钮。 copy the link generated.复制生成的链接。
  • execute command below执行下面的命令

    wget --no-check-certificate --no-proxy --user=username --ask-password -O "download url" wget --no-check-certificate --no-proxy --user=username --ask-password -O "下载地址"

Thanks谢谢

you have made the bucket public, you need to also make the object public.您已将存储桶公开,您还需要将对象公开。 also, the wget command doesn't work with the S3:// address, you need to find the object's URL in AWS web console.此外,wget 命令不适用于 S3:// 地址,您需要在 AWS Web 控制台中找到对象的 URL。

I know I'm too late to this post.我知道我写这篇文章太晚了。 But thought I'll add something no one mentioned here.但我想我会在这里添加一些没有人提到的东西。

If you're creating a presigned s3 URL for wget, make sure you're running aws cli v2.如果您要为 wget 创建预签名的 s3 URL,请确保您正在运行 aws cli v2。 I ran into the same issue and realized s3 had this problem我遇到了同样的问题并意识到 s3 有这个问题

Requests specifying Server Side Encryption with AWS KMS managed keys require AWS Signature Version 4

This gets resolved once you presign on aws cli v2一旦您在 aws cli v2 上签名,此问题就会得到解决

The simplest way to do that is to disable Block all public firstly.最简单的方法是首先禁用Block all public

  1. Hit your bucket name >> go to Permissions >> Block public access (bucket settings)点击您的存储桶名称>>转到权限>>阻止公共访问(存储桶设置) 在此处输入图像描述

  2. If it is on >> hit Edit >> Uncheck the box, then click on Save changes如果它打开>>点击编辑>>取消选中该框,然后单击保存更改在此处输入图像描述

  3. Now hit the object name >> Object action >> Make public using ACL >> then confirm Make public现在点击对象名称>>对象操作>>使用ACL公开>>然后确认公开在此处输入图像描述

  4. After that, copy the Object URL , and proceed to download之后,复制Object URL ,然后继续下载在此处输入图像描述

I hope it helps the future askers.我希望它对未来的提问者有所帮助。 Cheers干杯

I had the same mistake我有同样的错误

I did the following :我做了以下事情:

  1. created IAM role > AWS Service type > AmazonS3FullAccess policy inside在里面创建了 IAM 角色 > AWS 服务类型 > AmazonS3FullAccess 策略
  2. applied this role to the EC2 instance将此角色应用于 EC2 实例
  3. in the the Security Groups opened inbound HTTP and HTTPS to Anywhere-IPv4在安全组中打开入站 HTTP 和 HTTPS 到 Anywhere-IPv4
  4. made the S3 bucket public公开 S3 存储桶
  5. profit!利润! wget works! wget 有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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