Skip to content

alihemmatnia/PulumiNote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serverless Notes API with Pulumi and TypeScript

This project demonstrates how to build a simple, serverless note-taking application using Pulumi to define and deploy infrastructure on AWS. The application consists of a RESTful API built with API Gateway and a Lambda function that saves and retrieves notes from a DynamoDB table. The entire project, including infrastructure and application code, is written in TypeScript.

Features

  • Infrastructure as Code: All AWS resources are defined declaratively using Pulumi and TypeScript.
  • Serverless: No servers to manage. The application scales automatically with demand.
  • REST API:
    • POST /notes: Create a new note.
    • GET /notes/{id}: Retrieve a specific note by its ID.
  • Type-Safe: End-to-end TypeScript for both infrastructure and application logic.
  • Fast Deployments: Pulumi's engine quickly and reliably deploys changes to the cloud.

Tech Stack


Prerequisites

Before you begin, ensure you have the following installed and configured:

  1. Node.js and npm: Download Node.js (v18 or later recommended).
  2. Pulumi CLI: Install Pulumi.
  3. AWS Account: An active AWS account.
  4. AWS CLI: Install and configure the AWS CLI with your credentials.
aws configure
# AWS Access Key ID [None]: YOUR_ACCESS_KEY
# AWS Secret Access Key [None]: YOUR_SECRET_KEY
# Default region name [None]: us-east-1
# Default output format [None]: json

Setup and Deployment

Follow these steps to get the project running in your own AWS account.

1. Clone the Repository

git clone https://github.com/alihemmatnia/PulumiNote
cd pulumi-notes-app

2. Install Dependencies

This will install dependencies for both the Pulumi program and the Lambda function.

npm install

3. Log in to Pulumi

You can use the free Pulumi Service backend to store your state.

pulumi login

4. Configure the AWS Region

Set the AWS region where you want to deploy your resources.

pulumi config set aws:region us-east-2 # Or your preferred region

5. Deploy the Stack

Run the pulumi up command to deploy your infrastructure. This will first compile the TypeScript Lambda code (due to the preup script in package.json) and then preview and deploy the AWS resources.

pulumi up

Pulumi will display a preview of the resources to be created. Review the plan and select yes to proceed with the deployment.

Upon completion, Pulumi will output the public URL of your API.

Outputs:
  + apiUrl: "https://abcdef123.execute-api.us-east-1.amazonaws.com"

Testing Your API

Use a tool like curl or Postman to interact with your newly deployed API. Replace YOUR_API_URL with the URL from the pulumi up output.

Create a Note (POST /notes)

Send a POST request with a JSON body containing the note's content.

curl -X POST \
  YOUR_API_URL/notes \
  -H "Content-Type: application/json" \
  -d '{"content": "My first serverless note!"}'

The API will respond with the full note object, including its unique ID and creation timestamp.

{
  "id": "e7b1c3e1-8a9d-4f2c-b5f6-3d4a5e6b7c8d",
  "content": "My first serverless note!",
  "createdAt": "2024-02-23T10:00:00.123Z"
}

Get a Note (GET /notes/{id})

Use the id from the previous response to fetch the specific note.

curl YOUR_API_URL/notes/e7b1c3e1-8a9d-4f2c-b5f6-3d4a5e6b7c8d

You will receive the note's data in the response.

{
  "id": "e7b1c3e1-8a9d-4f2c-b5f6-3d4a5e6b7c8d",
  "content": "My first serverless note!",
  "createdAt": "2024-02-23T10:00:00.123Z"
}

Cleaning Up

To avoid ongoing AWS charges, you can destroy all the resources created by this project when you are finished.

Run the following command and confirm the action when prompted:

pulumi destroy

This will permanently delete the API Gateway, Lambda function, IAM role, and DynamoDB table.

About

Serverless Notes API with Pulumi and TypeScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published