I was keen to implement my website in python (using flask) but my shared host didn't host python websites. Since amazon web services (aws) has a years free hosting I thought I'd give implementing the website the go while migrating to aws.
Here's some things that were far more work than they should be:
Amazon doesn't have an easy way to force https only. To achieve this it appears to be necessary to alter the configuration for the server itself. I actually gave up on this as it was substantially easier to force https on the specific pages I needed than get http to redirect to https.
This problem came about because url_for()
seems to always return http
. There are some ways to fix this but the suggested solutions didn't work for me. In the end I just added the _external
and _scheme
variables to all url_for
calls. A pain, but it's not much code and the website won't be changing much.
This led to a further issue: getting flask to host https locally. The necessary documentation is a little buried, but well explained else where. I ended up making the code for this dependent on my config debug setting.
if (application.config['DEBUG']):
context = ('../openssl/server.crt', '../openssl/privatekey.pem')
application.run('0.0.0.0', port=8100, ssl_context=context)
I use a variety of python modules one of which uses libffi
. Apparently getting libffi
installed on an instance is simple. Of course the answer didn't work for me... and I have yet to figure out why. What I ended up using is
container_commands:
install_libffi:
command: yum install libffi-devel