Can't deploy a flask application to the web with AWS amplify - amazon-web-services

I've been doing backend programming for years but I've now decided to finally tackle frontend. I've watched two tutorials on using AWS amplify and one thing I don't understand is that I can only get my app to run on my localhost when I type
flask run
or
python flask_app.py
I have my code published on Github and AWS amplify says that it successfully reads it. However I don't see why the app would deploy to my webpage when I never actually run the flask app. I'm assuming that AWS amplify puts the code from github onto a Linux machine but don't I have to SSH into that machine and write: python flask_app.py?
I'm not receiving any error messages but my webpage is still blank and I'm guessing that that is because I see no reason why any of the files would be executed if they are just sitting there on some computer out there. Also, should I be concerned about this? In both of the tutorials I have watched there is an additional check mark which says 'verified' but not in my case.
Here is my code:
from flask import Flask, render_template
app = Flask(__name__)
#app.route('/')
#app.route('/home')
def home():
return "Help me be swank"
#app.route('/about')
def about():
return "I'm swank"
app.run(debug=1)

Related

Is it alright to use multiple backend frameworks with one database in a virtual machine

I'm wondering if I could use multiple backend frameworks, using only 1 database in a VM instance in production without any problems. For example, I wanna keep Django Admin and its authentication rest API services, while using FastAPI for other things, possibly even ExpressJs in the future.
I want to achieve this because different frameworks have different strengths and available third-party libraries in their ecosystems.
I know NGINX as a reverse proxy and a load balancer will control the traffic load and directions to different endpoints. Still, would there be any conflicts in the database or anything I should be watching out for?
Thank you!
You can create a dedicated path and mount it on app init. It works with flask, so I guess django should work as well
Here's an example taken from the docs
from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
from flask import Flask, escape, request
flask_app = Flask(__name__)
#flask_app.route("/")
def flask_main():
name = request.args.get("name", "World")
return f"Hello, {escape(name)} from Flask!"
app = FastAPI()
#app.get("/v2")
def read_main():
return {"message": "Hello World"}
app.mount("/v1", WSGIMiddleware(flask_app))
See the documentation at https://fastapi.tiangolo.com/advanced/wsgi/

My Django App only works on heroku when server is running locally

I have built an app using react and django. After deploying the app on heroku, when I open it the frontend works fine. However when i try to do any action that sends requests to the backend I get errors. The only time the requests work fine is when the django backend is running locally. I hsve been looking allover for solutions and have not been able to find any solutions. In my settings.py The heroku domain name is added to the allowed hosts
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', 'barkbnb-demo.herokuapp.com']
If anyone can point me in the right direction on where to begin looking for solving the issue that would be greatly appreciated.
Thanks!
Check your request string in React app when you call your backend. It looks like it uses local address there.

Failed to register a ServiceWorker. The script resource is behind a redirect, which is disallowed

I wanna make a flutter web app and deploy it to AWS.
After researching it looks like using AWS Amplify is the easiest way so I try it, however after I successfully deploy it, it only shows a white screen with this showing on the log after I inspect:
However the web app show up just fine on my GitHub page and Codemagic, you can see it on rezyfr.github.io and fl-blog.codemagic.app. And here is my amplify yaml file:
Is anyone ever experience this and found the solution? Or anyone have a better way to deploy flutter web on AWS?

Does Tweepy Streaming API work on Google App Engine?

I'm trying to use the Tweepy Library to follow a user. This means using the Streaming API. I'm using the Google App Engine SDK release: "1.9.40". Everything works on my Dev server but when I deploy to Production, it stops working. I don't get an error.
Basically what is happening is - the code I have in on_status is not being triggered. I added a checkpoint and it is not being printed to the log file. But on Dev, it is being triggered.
def on_status(self, status):
decoded = json.loads(status)
logger.info(decoded) # Checkpoint
I saw some older posts (2013...) that said streaming is not supported on App Engine but I just want to confirm if that is still the case in 2016. And if it is not supported, how come it works on the Dev env? Finally, what are my alternatives?
Thanks
App Engine does not support streaming. You can use a Compute Engine instance instead.

Django: Send regularly updates over websocket

We are currently developing an application with django and django-omnibus (websockets).
We need to send regularly updates from the server (django) to all connected clients via websockets.
The problem is, that we can't use cron or something related to do the work. I've written a manage.py command but through some limitations it seems omnibus can't send the message to the websocket if launcher by python manage.py updateclients.
I know that django is not designed for this kind of stuff but is there a way to send the updates within the running django instance itself?
Thanks for help!
Is the reason you can't use cron because your hosting environment doesn't have cron? ...or because "it seems omnibus can't send the message to the websocket if launcher by python manage.py" ?
If you simply don't have cron then you need to find an alternative such as https://apscheduler.readthedocs.org/en/latest/ or Celery also provides scheduled tasks.
But if the problem is the other side: "a way to send the updates within the running django instance itself" then I would suggest a simple option is to add an HTTP API to your Django app.
For example:
# views.py
from django.core.management import call_command
def update_clients(request):
call_command('updateclients')
return HttpResponse(status=204)
Then on your crontab you can do something like:
curl 127.0.0.1/internalapi/update_clients
...and this way your updateclients code can run within the Django instance that has the active connection to the omnibus tornado server.
You probably want some access control on this url, either via your webserver or something like this:
https://djangosnippets.org/snippets/2095/