2015-11-04 76 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存儲桶(應用程序在其上工作),但我不記得我做了什麼配置。你有沒有參考資料可以解釋需要做什麼? –