This project show how I use AWS services.
Building an authentication app
- Cognito (User Pool)
- DynamoDB (DataBase)
- Lambda (Serverless)
- AWS SAM (IaC)
- NodeJS (Runtime)
No need to redeploy the stack.
But if you do, you can use the following commands:
sam build
sam deploy
And replace the tests with the new API Gateway URLs.
There are two gateways:
- Unauthenticated requests
- output key:
WebEndpoint
- functions: Create user, Login user
- output key:
- Authenticated requests
- output key:
WebAuthEndpoint
- functions: Get user, Update user
- output key:
1. Create user
POST https://mc1qjoxaod.execute-api.eu-central-1.amazonaws.com/Prod/user
{
"first_name": "John",
"last_name": "Doe",
"phone_number": "+972123456789",
"national_id": "1234567891",
"password": "12345678"
}
Navigate to the AWS Cognito to confirm the user.
2. Login
POST https://mc1qjoxaod.execute-api.eu-central-1.amazonaws.com/Prod/user/login
{
"national_id": "1234567891",
"password": "12345678"
}
Copy the access token from the response body or cookie.
And use it in the next request in the Authorization header.
4. Update user
PUT https://l59g4gnum0.execute-api.eu-central-1.amazonaws.com/Prod/user
{
"first_name": "Jane!!!!!",
"last_name": "Doe",
"phone_number": "+972123123123",
"national_id": "1234567891"
}
5. Confirm changes
GET https://l59g4gnum0.execute-api.eu-central-1.amazonaws.com/Prod/user/1234567891
see the name changed to Jane!!!!! and the phone number changed to +972123123123
This test is designed to evaluate your proficiency in API gateway and AWS Lambda. Feel free to use any npm packages as needed.
Follow the steps below:
- Set up a Cognito user pool for managing user registration and authentication.
- Develop a Lambda function for user registration, which should add the newly registered user to a
DynamoDB table.
Ensure all fields are saved in both DynamoDB and Cognito. Allowed fields:
- Fields
- First name: up to 20 letters
- Last name: up to 20 letters
- ID: a valid Israeli ID
- Phone number: a valid phone number
- Password: minimum 6 characters
- Note that all fields are mandatory.
- If incorrect data is provided, return a 400 HTTP response.
- If successful, return a 201 HTTP response along with the ID from DynamoDB.
- Endpoint: POST /user
- Fields
- Implement another Lambda function to handle user. This function should verify the
user's credentials against the user pool and return a JSON web token (JWT) if the credentials are
valid.
- Endpoint: POST /user/login
- Create a Lambda function for processing authorized requests. This function should verify a valid
JWT in the request
headers before permitting the request to proceed and update user data.
- Endpoint: PUT /user
- Develop a Lambda function for handling authorized requests. This function should check for a
valid JWT in the request
headers before allowing the request to proceed and read user data.
- Endpoint: GET user/{id}
- Implement a Lambda function to retrieve a user by their ID.
- Provide a Postman collection along with your code.