I am new to web development and I am aware that this is a fairly basic question.
I have a poll that creates a custom link after the poll is created with the user’s email. The poll data is stored in an AWS DynamoDB table. I want to be able to customize the HTML of the website to reflect personalized data for the user using Javascript variables from data in the DynamoDB table.
How can this be done? I think it has something to do with URL queries but I honestly don’t know what to do.
I’ve looked everywhere online. Help would be very much appreciated!
2
Answers
The simple answer is create a lambda function with an exposed URL that securely identifies the user somehow and then, using that user information, queries your dynamodb table and returns a response with the relevant information.
The complex answer requires a lot of research into each of these mentioned services: creating a lambda; researching secure authentication and hooking up to cognito; setting up a dynamodb table; and adding permissions to your lambda so that it has the appropriate role/permissions to access both your cognito service and your dynamodb table.
I’d start with just getting a lambda set up with a URL and static return value, and getting your HTML page to work with that response.
For this to work you will need to update your websites JavaScript code to retrieve the user information from DynamoDB.
You will need to be able to obtain enough information from user to gain their information from your table.
Query Params
For example, if your table has a partition key of user_id then you would need your link to look like this:
https://www.mywebsite.com?user_id=123
Obtain the
user_id
from the query param in the URL:https://stackabuse.com/get-query-string-values-in-javascript/
Retrieve user details
Do a GetItem from DynamoDB
https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-table-read-write.html
Then show the data on the webpage using variables in JS