DEV Community

Discussion on: Python to React

 
smammar profile image
SMAmmar

Sure @jordan Lee, It would really help me

Thread Thread
 
jkhaui profile image
Jordy Lee

Sure :) But a heads-up first: please make sure you're willing to spend a bit of time learning AWS Lambda + API gateway and check that it's relevant to your needs. I don't want to accidentally send you down the wrong path if there's a better way to do it.

Anyway, here's the repo: github.com/jkhaui/serverless-pytho...

  1. Use the command npm i serverless -g to install the serverless framework globally.
  2. Clone the repo I sent you and follow instructions. Run serverless offline to edit your Python script locally. Test the API at localhost:4000
  3. If all goes well, use serverless deploy to host it on AWS Lambda. An endpoint URL should also be created automatically through API gateway.

Any questions/problems, let me know. Also, you'll be prompted for your AWS credentials at some point during these steps

Thread Thread
 
jkhaui profile image
Jordy Lee

Oh and btw, you can delete all the Spacy code in handler.py and also delete the directory en_core_web_sm-2.1.0. That's just for demo purposes.

Put your Python script in handler.py. This is the code that will let your script be accessed as an API:

    response = {
        'statusCode': 200,
        'headers': {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*',
        },
        'body': json.dumps(entities)
    }

    return response
Thread Thread
 
smammar profile image
SMAmmar

sure Jordan, First I will also look into the alternatives. But I highly appreciate the help you provided :).Wish you good luck in your future endeavors.

Thread Thread
 
jkhaui profile image
Jordy Lee

No problem :) Thank you, and best of luck with your app too.