-4

I'm very new to the serverless and backend world. I've been looking at tutorials on youtube and on serverless-stack.com (which is really good btw) and they mostly seem to cover React frontend applications and use NodeJS in their AWS Lambda functions.

I want to use Python for my Lambda functions. I'm unsure about how React communicates with those lambda functions (I'm using API Gateway if that makes any difference).

For example, if I I had a note taking application and I wanted to create a new note on DynamoDB, how do I pass the variable from React containing the contents of the note to my Python Lambda function that handles the note creation in DynamoDB?

2
  • A lambda is just a piece of code (function) which runs on a cloud machine. Unlike a normal server process, it is stopped after execution. It can be exposed to the outside in a number of ways, normally as a HTTP endpoint (URL) that triggers the execution of the function. I'd recommend to read a tutorial; most of the questions would go away.
    – 9000
    Dec 27, 2019 at 19:53
  • 1
    Yeah thanks, I realised from the answers below that I had a misunderstanding of how data gets pulled to the frontend because I didn't know what exactly a HTTP request looked like. Once they mentioned the terminology, I knew what to search for and it clicked! Cheers. Dec 27, 2019 at 21:41

2 Answers 2

1

It sounds like you want to submit a form from your front end. I don’t know how React works, but they probably POST the form data to an endpoint you specify, and they probably let you choose between form encoding and json encoding

Your endpoint is provided by API gateway, which lets you forward the request to your Lambda function. Your lambda will write to dynamo and then return some kind of success response to API gateway, which passes it on to the client

API gateway lets you transform the messages it receives, in both directions if I recall correctly.

0

React is a JavaScript library designed to render a front end. I'm confused why it would ever be considered for server side processing. Since you said the server was NodeJS, then the logic was written in JavaScript, and perhaps the YouTube channel presenters have some sort of special use for React on the server side.

Python AWS Lambda functions have a callback to handle the request and perform the lambda's function. You can use standard Python in this scenario, without any need for React in this scenario. In fact I would recommend keeping the lambda function to just using Python.

At my company we use React for the Single Page Application (SPA) front-end code we build, and call microservices that simply return JSON. We could just as well call AWS Lambda functions instead of microservices and the application would function similarly.

4
  • Ah I should've been clearer in my question. I understand that react is frontend. I'm just wondering how they (Python and React) would interact with each other. For example, if I stored some user info from a form as a React variable (is that how it's done?) then how do I pass that info to the Lambda function? The point is that I have no idea how to get info (e.g. user input) from the frontend to the backend if that makes sense. Happy to clarify further if needed. Dec 26, 2019 at 4:46
  • A Lambda function is accessed just like any MicroService. You make an HTTP call from your front-end code, and get a JSON response. The only difference is how you deploy your code. Dec 26, 2019 at 5:11
  • So when making this HTTP call, are you passing in a JSON object with the user input values? Dec 26, 2019 at 5:16
  • Just like you would with a web service. Think of it this way. A microservice has a few related endpoints you can call. A Lambda only has one. That's the only real difference between the two. Dec 26, 2019 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.