Info Re Multiple Flask Apps in One LightSail Container Service

0

assuming i'm correct that I'd be charged $15/month for each Container Service i am seeking a way to make each app available on one container service. since these are just for my portfolio, they won't get a lot of hits (possibly none). my idea was to have the url point to a general app that would have available all the deployment information/files for the apps and a user could select a link/push a button whatever and the app would make a lightsail api request to deploy the selected app. minutes later, that app would be active (and the general app would not be). i'm wondering how the api call would be validated, and also whether this would work. Thanks

  • I haven't done Flask app programming in a while, but I recall it being pretty modular and composable. E.g. you could probably just have one container service that has all your apps sitting on separate URL routes, like: /portfolio/app1, /portfolio/app2, /portfolio/app3, ...

  • that would involve a lot of work but maybe. throw all the static resources together, all the templates together, etc. multiple apps have an 'index.html' template and so i would have to rename these, and some inherit from a base.html and i would have to work that out etc. Then i would have to figure out how to handle the various route requests (every app has '/' -- i would have to work that out). i don't know i'm not a master of flask so maybe there's a way to do this i'll look into it. thanks for your comment [2nd edit] wow, 'master' is a non-inclusive word. but i was saying i'm NOT a master!

  • Here's a post that has an example of how to do this. The author even has exactly same purpose for this as you: portfolio site! https://peterhaas-me.medium.com/how-to-run-multiple-flask-applications-from-the-same-server-9ca2c0ad7bb3

    TL;DR: https://werkzeug.palletsprojects.com/en/2.0.x/middleware/dispatcher/

  • Pavel that looks great but I would have to pay Medium $50. Not just now ;) I'm currently going to look into nginx and see if I can have that redirect requests to a different port based on the url. But i don't really know how that would work. if you were willing to engage in some light copyright infringement you could send the story to me at myspam@cambiumsoftware.com

Ken
demandé il y a 23 jours338 vues
3 réponses
0

" how a multi-container app can be deployed on Lightsail container service" well I don't want to host a multi-container app, i want to host multiple small apps under one container-service.

This is the lightsail API i'm referring to: https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/Welcome.html

This allows you, in theory, to send commands to AWS outside of the ClI from your own computer. so i could send a request from an app. you evidently send a json in the request using GET or POST as specified in the api. but the json doesn't have authentication details so they'll just act on any request coming in? i could get a nice vps for $15 a month just trying the aws option

{ "containers": { "string" : { "command": [ "string" ], "environment": { "string" : "string" }, "image": "string", "ports": { "string" : "string" } } }, "publicEndpoint": { "containerName": "string", "containerPort": number, "healthCheck": { "healthyThreshold": number, "intervalSeconds": number, "path": "string", "successCodes": "string", "timeoutSeconds": number, "unhealthyThreshold": number } }, "serviceName": "string" }

Ken
répondu il y a 22 jours
  • Did you give the video a try? I'd recommend doing that since my terminology may not have matched yours, but the video still might turn out to be useful.

    ===

    I am familiar with Lightsail API :) What I meant was I couldn't clearly understand how you intend to use it or why would you need to, from the description of your idea.

    ===

    wrt, but the json doesn't have authentication details so they'll just act on any request coming in, not quite, the authentication is set in the request headers and unauthenticated requests generate an error response to that effect.

    Please refer https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html for how to configure credentials for AWS CLI calls.

0

Hi,

I am not sure I was able to follow the "making lightsail api requests" part, or the "how would api be validated" piece of your post.

However this video - https://www.youtube.com/watch?v=6S2brobgmBA&t=1921s from the Lightsail team demo's how a multi app setup can be deployed on Lightsail container service and will likely help guide you.

Attaching a screenshot of the video paused to show what the link links to :) screenshot of the video paused

Thanks.

profile pictureAWS
EXPERT
AWS-SUM
répondu il y a 23 jours
0

I was able to accomplish my goal by implementing the werkzeug middleware mentioned by Pavel in the comments.

https://werkzeug.palletsprojects.com/en/2.0.x/middleware/dispatcher/

This allowed me to make three apps (or more I suppose) available under one dispatcher app. Each sub app is reachable by a predefined tag on the url ie https://amazon.aws.com/somethingorother/flask_1/, .../flask_2/, ... /flask_3/ (although the first one is reachable via just the url). This means, I believe, that I'm only getting charged deployment time for one app rather than three. There will be next to no bandwidth expended since these are not production but rather for a portfolio.

The biggest challenge was that the requirements.txt had to work for all three flask apps. I also had to figure out that my db's were created in the dispatcher app instance file, not the individual app instance files.

I really didn't believe that this would work. But it did. hey hey. I guess the whole concept of containers is that if it works on your machine, it will work on their machine. Thanks AWS-SUM for pointing me to the Lightsail vid which helped me with the general concept.

Ken
répondu il y a 2 jours

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions