Flask AWS V5

1 minute read

Here it is, ugly and working and I am so proud

NOTE: Before doing below, follow this jazz … but don’t specifiy flask type and only use pip3 for installing and freezing requirements step-by-step coming soon :)

CURRENT PROJECT is v5-aws-flask

NLTK on AWS (so we can use it with a Python Flask app!)

QUICK OVERVIEW:

FOR LOCAL:

ssh into your instance with eb ssh Download python3 Install NLTK python » import nltk python » nltk.download()

FOR NON-LOCAL

Download the NLTK data you need Unzip it into appropriate folder (e.g. nltk_data/tokenizers/punkt) more info here data zips here Migrate that folder to the S3 bucket that already belongs with your app environment (for me that was s3://elasticbeanstalk-us-west-2-386305625872/flask-tutorial-v5-env/nltk_data) Create a file .ebextensions look here for examples Add the below to the file

###

ebextensions

(make a file .ebextensions): Put this in there (We likely don’t need the first command)

commands:
  01_download_nltk_data:
    command: "python3 -m pip install nltk"
  
  02_copy_nltk_data:
    command: "aws s3 cp s3://elasticbeanstalk-us-west-2-386305625872/flask-tutorial-v5-env/nltk_data /usr/local/share/nltk_data --recursive"

What eventually worked for me: This But I didn’t have to make an environment variable, I just did the commands line… Which makes me wonder if it was adding this line to the paths (see ‘ADDED PATHS’ below) that helped? DOCUMENTING LITERALLY EVERYTHING so I can reproduce effectively Same same

Things that didn’t work for me: Changing where NLTK would look for the data

Resources: I scanned this

Added Paths

I added str('/root/nltk_data'), to this code block found in v5-aws-flask/v5-virt/lib/python3.7/site-packages/nltk/data.py

else:
    # Common locations on UNIX & OS X:
    path += [
        os.path.join(sys.prefix, str('nltk_data')),
        os.path.join(sys.prefix, str('share'), str('nltk_data')),
        os.path.join(sys.prefix, str('lib'), str('nltk_data')),
        str('/usr/share/nltk_data'),
        str('/usr/local/share/nltk_data'),
        str('/usr/lib/nltk_data'),
        str('/usr/local/lib/nltk_data'),
        str('/root/nltk_data'),
    ]

NEXT STEPS: read this aws sync?

NOTE TO FUTURE SELF:

  1. Calm down
  2. Check the logs in Elastic Beanstalk

Updated: