Ride Sharing App Using AWS Services
Project Description:
This project focuses on building a ride sharing app within the AWS ecosystem. The goal is to streamline the handling of images by automatically resizing them and transferring them to a designated storage location while keeping stakeholders informed through notifications. Key AWS services, such as Lambda, S3, and SNS, are used to orchestrate this workflow.
AWS Services to be used:
- Codecommit
- Amplify
- Cognito
- Lambda
- IAM
- API Gateway
- DynamoDB
Key Features:
- All the code is provided by AWS and we need a way to get it into a source control system
- We need to be able to handle permissions for the code
- A place to host the website and also make updates
- A way for users to register and login
- We need some ride sharing functionality
- Somewhere to store and return the ride results
- We need a way to invoke the ride sharing functionality from the browser
Steps :
Step 1 : Create a new repository in AWS CodeCommit
For getting the html,css, and javascript, we will not be typing anything from scratch as aws has provided the codes for us. So we will be taking that code and creating a codecommit repo and copy the code into our repo where we can work with it
Step 2 : Add a policy to an IAM user to allow access to CodeCommit
-
Go to IAM user
-
Navigate to the permissions tab and click on add permissions
-
Attach the policies directly
4.You then search for codecomitpoweruser
-
Add permissions
This will give codecommit the access we need
Step 3 : Create Git credentials to allow HTTPS connections to CodeCommit
-
Go to security credentials
-
Scroll down to the https git credentials for AWS CodeCommit
-
Click on generate credentials
The generated credentials will allow us make https calls to codecommit.( download the credentials as we wil use them later)
Step 4 : Clone the CodeCommit repository using cloudshell
-
Go to the codecommit repository we created
-
Copy the url of the repo(go with the https version)
when you click on ‘clone https’ it copies it and then we need to open a cloud shell( a command line interface that runs in the browser) at the top of the browser
-
Open the cloud shell with is located to the right of the search bar.
-
Type in git clone and paste the url of the repository and hit enter
-
You then type in the username you generated for codecommit as well as the password
However it takes us to an directory in cloud shell that hosts the repository so we will have to change it to our created repository by using ‘cd’
Cloning the repository created an empty folder and this is where our code files will end up
Step 5 : Copy the code from an s3 bucket to cloudshell
use this command to get the files:
aws s3 cp s3://ttt-wildrydes/wildrydes-site ./ --recursive
- So were going to download the files from an s3 bucket.
- We use ls to check the files and see that they are in the folder but not in the cloudcommit repo.
- To push them into the cloud commit repo we type ‘git add.’ And then ‘git commit’.
- After pushing the code to the repository
You go back to the wildrydes repository and you seethe files loaded in there
Step 6 : Create a new app for hosting in AWS Amplify
- You open aws amplify, click on host web app
- Go to code commit and hit continue and select the wildrydes repository from the list of options and hit next
- Click on allow aws amplify to automatically deploy files hosted in the project root directory. This means when theres an update or change in the code file it automatically deploys. After doing that you hit next.
- This will take you to the review page where you just save and deploy
- You can click the link to check out the site in a new tab
- We are going to try and see if the continuous deployment is working. We do that by going to codecommit and navigating to the index.html file, clicking edit. You make whatever change you want and then fill in in the tabs which specify your name and email and then click on commit changes.
- It then triggers amplify which starts the build process. When its done, you go back to the site and hit refresh and see that the changes have been applied
Step 7 : Setting up AWS Cognito for user authentification
-
Now we need to work on a way to login and register as those fuctionalities haven’t been worked on. We will be using AWS Cognito(used to do authentication)
-
We go over to aws cognito and then click on create user pool
-
At the security requirements select cognito defaults for the passwork policy and no mfa to keep things simple and then go to next
-
leave all the defaults on the next page and click on next
-
On the next page which is the message delivery page we will click on send email with cognito,leave all the defaults and then hit next
-
On the next page which is the integrate your app page we will give a name to our user pool and then give an app client name as wildrydeswebapp. We will leave the other defaults. Then hit next
-
Review and create the user pool.
-
Now we will click into the user pool.(Copythe user pool id)
-
We then click on app integration and copy the client ID
Step 8 : Updating the app configuration file to use the Amazon Cognito user pool
- Now we need to hook up cognito with our code by updating the config file in our application code to point to the dedicated user pool
- we go back to codecommit and open our repo and then navigate to the js file and then the config.js file
- Click on edit . you paste the user pool ID,user pool client ID, and the region and then commit the changes which will trigger amplify again
Step 9 : Testing Cognito integration by doing user registration and login
-
Now you go over to the wild rydes site and click on giddyup to register
-
Fill in the details and cognito will send an email with the verification code.
-
Once you put in the details you will be routed to the login page where you wil need to login again
Step 10 : Implementing ride sharing functionality with Lambda and DynamoDB
We will use a lambda function and a dynamodb database. The user will request a ride that will invoke the lambda fuction and the request will be stored In the dynamo table
-
Go to dynamodb and navigate to tables where you create a new table
-
You name the table Rides and give the partition key as RideId and leave everything as default and hit create table
-
Click into the created table, go to general information and additional info and copy the aws arn
Step 11 : Creating an IAM role to be used for a Lambda execution role, allowing PutItem on DynamoDB table
We will need to create a role for our lambda function to be able to write into our table so we would go to IAM
- Click on create new role
- The trusted entity type will be aws service and the service will be lambda
- Now we look for a policy to attach to the role
- We select the aws basic lambda execution role and hit next
- We give the name of the role as wildrydeslambda and leave the defaults of everything else and create role
- Now we will open up the role and add some additional permissions. Go to add permissions and hit create inline policy
- You chose the service as dynamodb and then you select putitem and then add the arn
- You give the policy a name-dynamodbwriteaccess and create policy
Step 11 : Creating a new Lambda function to choose a unicorn and write the ride sharing info to DynamoDB
- go to aws lambda and create a new lambda function by clicking create function
- We will author from scratch. The name of the function will be requestunicorn
- For the runtime we use Node.js 16x
- For the execution role we will select ‘use an existing role’ which is the role we created in IAM and then hit create function
- We then scroll down to the code source and replace the original lambda code with the code provided by aws( this can be found in the lambda.py file)
- deploy the changes
Step 12 : Deploying Lambda code and executing a test event
- Now we have to configure a test event
- Copy our test function and paste it in the json file and hit save
- Now we need to run the test and see that the test succeeded
Step 13 : Testing that items are saved to the DynamoDB table
- We then check the dynamodb table to see if everything was recorded properly
- In the rides table you click on explore table items
- When we scroll down we see the one item for the test
Step 14 : Setting up API Gateway to invoke the ride sharing functionality
-
We go to api gateway and then hit create new api
-
Select rest api
-
Give the api a name ‘wildrydes’
-
Select edge optimized and then create api
-
Now we need to create an authorizer to authenticate calls api gateway uses that are returned by cognito
-
After creating the authorizer, click into it to test if things are working
-
Paste in the authorization token from the wildrydes page and hit test
-
We get a feedback of 200 meaning everything is working fine
Step 15 : Creating a resource and POST method in API Gateway for Lambda integration
Now we go into our api and then create resource which is how we will hook it up to the lambda function
- Now we go into our api and then create resource which is how we will hook it up to the lambda function.
- We make sure to select cors when creating the resource and then hit create resource
- After creating the resource , we need to create a method. We click create method from inside the ride resource
- The method type will be a post type to integrate with the lambda function, select lambda as the integration type and then select the unicorns lambda function and then create method
- After creating the post method, select the method request card and then click on edit
- We will authorize using the cognito user pool authorization
- After its all said and done, we depLoy the API
- A pop up tab will show where you select stage s new stage and name it ‘dev’ and deploy
- Copy the invoke url
- Now we go back to codecommit inside the config.js file and update the invoke url with the one we copied from our api and commit the change
now to check if everything is working properly we go to our rides site and refresh
after requesting your unicorn you can go check the dynamodb table to see if it was recorded.everything is working as it should