Used Pulumi to create a blog api using AWS Lambda, API Gateway, and DynamoDB. The API is written in Javascript and uses the Serverless Framework to deploy the code to AWS.
stateDiagram-v2
[*] --> BlogAPI
BlogAPI --> APIGateway
BlogAPI --> database
BlogAPI --> scripts
BlogAPI --> test
BlogAPI --> utils
APIGateway --> lambdas
APIGateway --> routes
APIGateway --> auth.ts
APIGateway --> index.ts
lambdas --> comments
lambdas --> posts
lambdas --> users
routes --> comments
routes --> posts
routes --> users
database --> tables
database --> validation
The Entry point of the API
-
APIGateway - Contains the code for the API Gateway. Routes - Contains the routes for the API
The API can be divided into three parts:
- AWS Account
- Pulumi Account
- Clone the repository
- Install the dependencies
yarn install
- Add environment variables | Replace the values with your own
cp .env.example .env
- Create a new stack
pulumi stack init
- Set AWS configurations
pulumi config set aws:accessKey <access-key>
pulumi config set aws:secretKey <secret-key>
pulumi config set aws:region <region>
Note: It is advised not to use root user for the access. Instead create the access from IAM and use the access key and secret key.
- Create a new Pulumi access token
pulumi login
- Deploy the stack
yarn push
Note: If you are prompted with passphrases, you can use the following command to avoid the prompt This will remember the passphrase for the entire cli session
set PULUMI_CONFIG_PASSPHRASE="<passphrase>"
or
$env:PULUMI_CONFIG_PASSPHRASE="<passphrase>"
curl -X POST \
https://<api-gateway-url>/signup \
-H 'Content-Type: application/json' \
-d '{
email: "[email protected]",
password: "Password1@"
}'
Pulumi does not support ignoring files, I added the json to this project which will also be pushed to aws which shouldn't be pushed. You should delete the json file after you have deployed the stack.
The total resources created by the stack are 220. The resources are divided into the following categories:
- APIs - 4
- Functions - 33
- Tables - 5
- Identity - 176
📈 Performance
- Write tests using vitest
- Use jmeter to test the performance
- Add a CI/CD pipeline
- Add a monitoring system
- Add a logging system