Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
scroll top