This is a AWS Serverless Framework Application that allows to save users in a database.
Motivation: This is part of my journey of learning about AWS. I developed this application for the Advanced Serverless Framework course by Platzi.
- Implementation of Lambda functions for HTTP Events
- Implementation of Lambda functions for SQS Events
- Implementation of Lambda functions for S3 Events
- DynamoDB Integration
- Lambda Layers
- API Key authorization
- Custom Authorizer
- Unit test with JEST (100% Coverage)
- CI/CD with Github Actions
- TypeScript
If you want to deploy this application in your AWS environment, don't forget to change the S3 bucket name in the custom section of the serverless.yml
file.
$ npx sls deploy
This endpoint allows you to create a user record in DynamoBD.
curl --location 'http://your-domain.com/users' \
--header 'Authorization: Bearer <SECRET KEY FROM SSM>-<CURRENT UTC HOUR>-<CURRENT UTC MINUTE>' \
--header 'Content-Type: application/json' \
--data '{
"firstName": "john",
"lastName": "doe"
}'
{
"pk": "f2189613-34c5-48a6-bc0e-c44bc968df33",
"firstName": "john",
"lastName": "doe",
"likes": "0",
"createdAt": "2024-05-31T05:59:09.467Z",
"updatedAt": "2024-05-31T05:59:09.467Z"
}
This endpoint returns the list of users. A query parameter named lastKey
containing the last id of the users from a previous request can be used for pagination.
curl --location 'http://your-domain.com/users/' \
--header 'x-api-key: <Your APT Key>'
{
"lastKey": null,
"pageSize": 10,
"count": 1,
"items": [
{
"createdAt": "2024-05-31T05:59:09.467Z",
"likes": "0",
"pk": "f2189613-34c5-48a6-bc0e-c44bc968df33",
"firstName": "john",
"lastName": "doe",
"updatedAt": "2024-05-31T05:59:09.467Z"
},
]
}
This endpoint allows you to get the information of a single user.
curl --location 'http://your-domain.com/users/f2189613-34c5-48a6-bc0e-c44bc968df33' \
--header 'x-api-key: <Your API Key>'
{
"createdAt": "2024-05-31T05:59:09.467Z",
"likes": "0",
"pk": "f2189613-34c5-48a6-bc0e-c44bc968df33",
"lastName": "doe",
"updatedAt": "2024-05-31T05:59:09.467Z",
"firstName": "john"
}
This endpoint allows you to update the first name and last name of a user.
curl --location --request PUT 'http://your-domain.com/users/2b808b73-a671-48af-9a55-85e5baed36af' \
--header 'Authorization: Bearer <SECRET KEY FROM SSM>-<CURRENT UTC HOUR>-<CURRENT UTC MINUTE>' \
--header 'Content-Type: application/json' \
--data '{
"firstName": "Juan",
"lastName": "gomez"
}'
{
"createdAt": "2024-05-27T22:49:36.222Z",
"pk": "2b808b73-a671-48af-9a55-85e5baed36af",
"firstName": "Juan",
"lastName": "gomez",
"updatedAt": "2024-05-31T06:09:26.857Z"
}
This endpoint allows you to delete a user record from the database.
curl --location --request DELETE 'http://your-domain.com/users/f2189613-34c5-48a6-bc0e-c44bc968df33' \
--header 'Authorization: Bearer <SECRET KEY FROM SSM>-<CURRENT UTC HOUR>-<CURRENT UTC MINUTE>'
{
"createdAt": "2024-05-31T05:59:09.467Z",
"likes": "0",
"pk": "f2189613-34c5-48a6-bc0e-c44bc968df33",
"lastName": "doe",
"updatedAt": "2024-05-31T05:59:09.467Z",
"firstName": "john"
}
This endpoint allows you to generate a signed s3 url to upload an image.
curl --location 'http://your-domain.com/signed-url' \
--header 'Authorization: Bearer <SECRET KEY FROM SSM>-<CURRENT UTC HOUR>-<CURRENT UTC MINUTE>' \
--header 'Content-Type: application/json' \
--data '{
"filename": "image.jpeg"
}'
The url in the response will be used to upload an image in your s3 bucket.
{
"url": "http://your-domain.com/upload/image.jpeg?..."
}
This endpoint allows increment the likes counter attribute from a user record.
curl --location 'http://your-domain.com/like-user' \
--header 'Content-Type: application/json' \
--data '{
"id": "2b808b73-a671-48af-9a55-85e5baed36af"
}'
{
"message": "accepted"
}