1

I asked something similar to this question and I haven't gotten any responses that help. So, I have decided to simplify things as much as I can with the following:

I have developed a python flask application and deployed to a beanstalk worker tier python environment. The issue is I can't figure out how to print or log or write anything anywhere. I need to debug this application and the only way I know how to do that is by printing to either the console or a log file to see exactly what is going on. When I run the application locally I can print to the console, write to files, and log with zero problems, it is just when I deploy it to the beanstalk environment that nothing happens. I have SSHed into the ec2 instance where I have application deployed and searched practically every file and I find that nothing was written by my python script anywhere.

This question probably seems absolutely stupid but can someone please provide me with an example of a python flask application that will run on a beanstalk worker environment that just prints "Hello World" to some file that I can find on the ec2 instance? Please include what should be written the requirements.txt file and any *.config files in the .ebextensions folder.

Thank You

2 Answers2

1

There is a python+flask on beanstalk example on AWS Application Management Blog:

http://blogs.aws.amazon.com/application-management/post/Tx1Y8QSQRL1KQZC/Elastic-Beanstalk-Video-Tutorial-Worker-Tier

http://blogs.aws.amazon.com/application-management/post/Tx36JL4GPZR4G98/A-Sample-App-For-Startups

For the logging issues, i'd suggest:

  • Check your /var/log/eb-cfn-init.log (and other log files in this directory), if a .config command is failing you will see which and why there.

  • In your .config commands, output messages to a different log file so you see exactly where your bootstrap failed in your own file.

  • Add you application log file to EB Log Snapshots (/opt/elasticbeanstalk/tasks/taillogs.d/) and EB S3 log rotation (/opt/elasticbeanstalk/tasks/publishlogs.d/). See other files in these directories for examples.

Julio Faerman
  • 13,228
  • 9
  • 57
  • 75
  • I have already seen that example. I have modeled a lot of what I am doing off that process, but I am doing something completely different, and I need to debug it. Therefore, since there is no place where they log or print to a file, it does not help me. As for the remainder of your suggestions, there is no error message in any of the logs, and lastly I have no problem ssh ing to the ec2 instance, so adding the logs to the EB Log Snapshots is of no use to me. – user3749757 Jun 25 '14 at 19:03
  • Suggestion 2 may help. Append to your own log files (cmd >> /my/log), then you can see the files on the isntance or on EB Snapshots or on S3. – Julio Faerman Jun 25 '14 at 20:14
1

Here is another simple python app that you can try. The one in the blog will work as well but this shows a minimal example of an app that prints messages received from SQS to a file on the EC2 instance.

Your app source folder should have the following files:

application.py

import os
import time
import flask
import json

application = flask.Flask(__name__)
start_time = time.time()

counter_file = '/tmp/worker_role.tmp'


@application.route('/', methods=['GET', 'POST'])
def hello_world():
   if flask.request.method == 'POST':
        with open(counter_file, 'a') as f:
            f.write(flask.request.data + "\n")
        return flask.Response(status=200)

if __name__ == '__main__':
    application.run(host='0.0.0.0', debug=True)

requirements.txt

Flask==0.9
Werkzeug==0.8.3

.ebextensions/01-login.config

option_settings:
    - namespace: aws:autoscaling:launchconfiguration
      option_name: EC2KeyName
      value: your-key-name

Launch a worker tier 1.1 environment with a Python 2.7 solution stack. I tested with (64bit Amazon Linux 2014.03 v1.0.4 running Python 2.7).

Wait for the environment to go green. After it goes green click on the queue URL as visible in the console. This will take you to the SQS console page. Right click on the queue and click on "Send a message". Then type the following message: {"hello" : "world"}.

SSH to the EC2 instance and open the file /tmp/worker_role.tmp. You should be able to see your message in this file.

Make sure you have IAM policies correctly configured for using Worker Role environments. For more information on IAM policies refer this answer: https://stackoverflow.com/a/23942498/161628

Community
  • 1
  • 1
Rohit Banga
  • 18,458
  • 31
  • 113
  • 191