- Create a to host a webpage
- Invoke the math functionality
- Do some math
- Store the math result
- Handle permissions
- Create a new AWS account with IAM user
- Install the AWS CLI and setup the toolkit in VSCode
- Create an
index_original.htmlfile and zip it - Open the AWS console and search for
Amplify - Select
Host your web app - Deploy without git provider
- Upload the zip file
- Name the app
- Enter
devfor the environment name - Upload the zip file
- Open up
Lambdain the AWS console - Create a new function
- Select
Author from scratch - Name the function
- Select
Python 3.9as the runtime - Everything else is default, then create function
- Scroll down to the
Code Sourcesection - Copy the code from
PowerOfMathFunction - Lambda.pyinto the editor - Test the function
-
- Create a new event
-
- Name it
PowerOfMathTestEvent
- Name it
-
- update the dictionary at the bottom to use
baseandexponentas the keys and then assign numbers to them
- update the dictionary at the bottom to use
- Save and deploy
- Go to the
API Gatewayservice in the AWS console - Select
REST API - Select
REST,New API, and name itPowerOfMathAPI - Create API
- Select
ActionsandCreate Method(Make sure thatResourcesis selected on the left) - Select
POSTand thencheckmark - Select
Lambda Functionand then select thePowerOfMathFunctionthat was created earlier - Save and see the gateway permission window
- Under the actions menu select
Enable CORS - Select
Enable CORS and replace existing CORS headers - Select
ActionsandDeploy API - Select
New Stageand name itdev -
- Save the URL gateway up at the top:
https://XXXXXXXXXX.execute-api.us-east-1.amazonaws.com/dev
- Save the URL gateway up at the top:
- Select
Resourceson the left and then select thePOSTmethod - Select the blue lightning bolt to test the API
- Go to the
DynamoDBservice in the AWS console - Create table
- Name it
PowerOfMathDatabase - Name the partition/primary key
IDand make it a string - Select the table that was just created
- Select
Additional infounder theGeneral Informationsection underOverview - Copy the
ARNand save it for later:arn:aws:dynamodb:us-east-1:123456789012:table/PowerOfMathTable
- Go back the the Lambda function and select
ConfigurationthenPermissions - Select the role
- Under Permissions policies slect
Add Permissionand then selectCreate inline policy - Copy in the JSON from
Lambda Function Policy.txt - Update the
Resourceto theARNfrom the DynamoDB table - Review Policy and then name it
PowerOfMathPolicy
- Go to the Code tab in the Lambda function
- Replace the code with the code from
PowerOfMathFunction - Lambda Final - Click
Deploy - Run the test again and see the result in the DynamoDB table
-
- Open the
PowerOfMathTableand select theExplore table itemsbutton
- Open the
-
- There should now be a new entry in the table
- Copy in the URL from the gateway created earlier into the
index.htmlfile - Create a new zip file with the updated
index.htmlfile - Go back to the
Amplifyconsole and reupload the zip file - The webpage will redeploy on it's own
- The domain should be the same
- Do not want any surprise bills
- Go to the
Amplifyconsole and selectActionsandDelete app - Go to
DynamoDB, select the table from the list of tables, and then clickDelete - Go to
Lambda, select the function from the list of functions, and then clickDelete - Go to
API Gateway, click theActionsbutton and selectDelete API