A simple fortune teller app using AWS Lambda & AWS API GW Steps:
- Go to AWS Lambda: Choose "Author from Scratch" Give the funtion a name & choose Python 3.11
- Add the code in the Lambda Function: It is a simple function, that generates random numbers, and based on the random generated, an answer is given "yes, no, maybe"
- Click deploy, then Test The test result should be something like the below: by clicking on "Test" the message will keep chaning based on the random number generated.
- Then now we need to create the API
- Go to API Gateway service, and click on HTTP API
- Add the integration to be "Lambda" & choose the name of the function, set an API Name, then click next.
- Choose the method "GET"
- Go to "Routes", "Configure" to add a parameter.
- Mapping type will be "All incoming requests", parameter to modify will be "querystring.question", modification type "Append", value "$request.querystring.question" ^ "question" could be changed with whatever word.
- You need to take a note of this, because this what will we add in the Invoking URL:
- go to APIs, click on the fortune teller API, there is no need to click deploy, because "auto deploy" was enabled when we created the API.
- Take the invoke URL, paste it in the browser, and add the following: /FortuneTellerApp?question="Should I go out today?" The invoke URL would be something like this: https://3rreln8oee.execute-api.us-east-1.amazonaws.com/dev so the full URL would be https://3rreln8oee.execute-api.us-east-1.amazonaws.com/dev/FortuneTellerApp?question="Should I go out today?"
- You will get an answer like the below: By refershing , and changing the question, we should receive random answers to the question.