从EC2实例本地访问Amazon S3存储桶 [英] Local access to Amazon S3 Bucket from EC2 instance

查看:897
本文介绍了从EC2实例本地访问Amazon S3存储桶的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一区域有一个EC2实例和一个S3存储桶。存储桶中包含我的EC2实例定期使用的相当大的文件(5-20​​mb)。

I have an EC2 instance and an S3 bucket in the same region. The bucket contains reasonably large (5-20mb) files that are used regularly by my EC2 instance.

我想以编程方式在EC2实例上打开文件(使用python) 。像这样:

I want to programatically open the file on my EC2 instance (using python). Like so:

file_from_s3 = open('http://s3.amazonaws.com/my-bucket-name/my-file-name')

但是使用 http URL远程访问文件似乎效率很低,当然,这意味着每次我要使用该文件时,都要将该文件下载到服务器。

But using a "http" URL to access the file remotely seems grossly inefficient, surely this would mean downloading the file to the server every time I want to use it.

我想知道的是,有什么办法可以在本地访问S3文件吗?从我的EC2实例中获取,例如:

What I want to know is, is there a way I can access S3 files locally from my EC2 instance, for example:

file_from_s3 = open('s3://my-bucket-name/my-file-name')

我自己找不到解决方案,我们将不胜感激,谢谢

I can't find a solution myself, any help would be appreciated, thank you.

推荐答案

无论做什么,该对象都会在后台从S3下载到EC2实例中。那是无法避免的。

Whatever you do the object will be downloaded behind the scenes from S3 into your EC2 instance. That cannot be avoided.

如果要将存储桶中的文件视为本地文件,则需要为FUSE安装多个S3文件系统插件中的任何一个(例如:s3fs-fuse )。或者,您可以使用 boto 通过python代码轻松访问S3对象。

If you want to treat files in the bucket as local files you need to install any one of several S3 filesystem plugins for FUSE (example : s3fs-fuse ). Alternatively you can use boto for easy access to S3 objects via python code.

这篇关于从EC2实例本地访问Amazon S3存储桶的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆