These are the services I have used to build this project:
1. AWS Amplify: used to host the website using a HTML zip file.
2. AWS Lamba: Code used to run the math function.
3. API Gateway: To trigger the Lambda function that is accessible to the public using a URL.
4. Dynamo DB: Stored the results, date and time the math function was executed using a table.
5. AWS IAM: Set permissions on the execution role for Lambda.
Why the Project was built?
I chose to build this project to reinforce my learning of the cloud services Amazon offeres and to familiarise my self with how the architecture is set up as this was my first project. I managed to find a really good tutorial online by Tiny Technical Tutorials on YouTube. This helped get an understanding on how to navigate and set up the configurations so the services can work together seamlessly.
I first launched AWS Amplify and proceeded to deploy without Git provider. As I have kept all the files for this project on my local machine and no further changes will be made, there was no need to use a Git Provider for this project
I selected the drag and drop method to upload my zip folder containing the HTML file. The HTML file contained the layout design for the web application. Then I saved and deployed it successfully.
Then I moved to the next part of the building process. I had to add the math function to the web application for it to calculate within a serverless method. For this I launched AWS Lambda. I gave the Lambda function a name and selected the lastest Python version and clicked creat function.
Once the function was created successfully, I replaced the deafault Python code with JSON utility package and Python math library so the calculation can be performed. Then I saved the code using CTRL+S (this did not mean the code was deployed, this is why the prompt has been shown. Then I clicked deploy and test.
Once in the “create new test event” menu, I gave the test event a name and replaced the starter code with the math values I want the function to calculate in our test environment. I entered two numerical values, this is not specific, any numbers can be entered here. We have configured our test environment. Then click save to move on to the next step.
Then click “Test” to check if it worked. As you can see, when we set up the test environment to calculate 2 to the power of 3, it has returned the result of 8 which is correct. In simple terms, the math problem was 2x2x2.
Next, I used the API Gateway to create a URL for the users to be able to trigger the function from a public endpoint. I used REST API and click “build” and it has brought me to this page. So gave the API a name and clicked “Create API”.
I set up the method as a POST so that it can be called. After this has been set up, I enabled CORS so that API and Lambda domains can access resources from one domain to another without issues as they run from different domains.
I then deployed the API which brought me back to this menu where it has generated the URL we just set up. I then copied this URL to a note pad for later use.
At this point, the flow will work like this: Method Request>Integration Request>Integration Response>Method Response for the user.
Now to test this, I have entered the two values which has returned the correct result So now the math function can be triggered using an API call which mean API Gateway and AWS Lambda are connected.
To store the results on a database, I am using DynamoDB which is a non-relational database. After launching this service, I created a table, gave it a name, gave the partition key name as ID and kept everything else the same. After creating the table, I clicked into it which brought me to the above screen showing all the general information of the table. Here I found the ARN number which I copied to my notepad, which will be needed to give permission to our DynamoDB table using IAM policies later on.
Now, in the IAM policy page, Lambda functions are given permission to perform these actions you see in the list on the DynamoDB table. Using the JSON code format, the policy is configured. I then pasted the ARN I copied, shown in the previous diagram, so DynamoDB can make changes to the table.
Now I am setting up my Lambda function to directly connect to the database. So back in AWS Lambda tab, I clicked on the code icon and added my Python code. These packages will also insert the date and time of when the math function was used. Then I CTRL+S to save the current state and deploy to push out the changes. Next step is to test.
When testing, I received an error message. Access was denied when calling the PutItem that. This meant that Lambda cannot write to the DynamoDB table. To diagnose this problem, I went back a step and realised the name of my Dynamo table did not match the name on my Lambda fuction so permission was not being granted.
Once I fixed the error, I ran the test again which returned the correct result of the math equation.
As can be seen above, the result return time and date is being recorded on the Dynamo table.
This is the HTML and CSS code for the design of the the webpage. Pasted my URL so the call API code can pass through API Gateway to return the result.
This is the final product where the base number and exponent number is being calculated and returns the result to the user on the front end. On the back end the response are being recorded on the Dynamo table with result, date and time.