2015-11-04 41 views
1

交互我有一个瓶的应用程序看起来像这样:部署瓶应用通过弹性魔豆与S3

from flask import Flask 
import boto3 

application = Flask(__name__) 

@application.route("/") 
def home(): 
    return "Server successfully loaded" 

@application.route("/app") 
def frontend_from_aws(): 
    s3 = boto3.resource("s3") 
    frontend = s3.Object(bucket_name = "my_bucket", key = "frontend.html") 
    return frontend.get()["Body"].read() 

if __name__ == "__main__": 
    application.debug = True 
    application.run() 

一切完美的作品时,我在本地测试,但是当我的应用程序部署到弹性魔豆第二端点给出了一个内部服务器错误:

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

我没看到什么惊人的记录,虽然我不能完全肯定我会知道去哪里找。有任何想法吗?


更新:作为一个测试,我frontend.html移动到不同的水桶,并相应修改了“/应用”端点,而神秘它能正常工作。显然这与原始存储桶的设置有关。有人知道正确的设置可能是什么吗?

回答

0

我发现了一个快速而肮脏的解决方案:IAM策略(AWS控制台 - >身份验证&访问管理 - >策略)。有一个名为AmazonS3FullAccess的现有策略,在我将aws-elasticbeanstalk-ec2-role附加到它后,我的应用程序就可以随意读取和写入S3。我猜想通过创建自定义角色和策略可以实现更微妙的访问管理,但这对我的目的来说足够好。

0

您是否在Elastc Beanstalk实例上设置了AWS凭证,因为它们在本地计算机上(即在〜/ .aws/credentials中)?

+0

大约一年前,我创建了我的Elastic Beanstalk实例和另一个S3存储桶(应用程序在其上工作),但我不记得我做了什么配置。你有没有参考资料可以解释需要做什么? –