This project was done as a pre-assignment for the OP Kiitorata Trainee Program 🤞.
coffee-beans-iac/
├── backend/ # Lambda function code
├── cdk/ # Infrastructure code
│ ├── bin/
│ └── lib/
│ ├── backend-stack.ts
│ └── frontend-stack.ts
└── frontend/ # React + TypeScript application
The infrastructure code is built with AWS CDK and it consists of two main stacks.
-
AWS Lambda (Docker-based) - Runs the backend logic inside a container image and serves coffee beans data via a REST API.
-
API Gateway (HTTP API) - Exposes a secure, public HTTP endpoint for the Lambda function and manages CORS configuration.
-
S3 Bucket - Hosts the static assets of the React frontend application
-
CloudFront Distribution - Provides a global CDN layer for fast, cached content delivery.
-
Automatic Configuration - During deployment, a config.json file is generated and uploaded to S3 containing runtime settings such as the API Gateway endpoint and CloudFront distribution URL.
- Node.js Lambda Handler - Serverless REST API serving coffee beans data
- React + TypeScript + styled-components – Modern frontend built with React and TypeScript, styled using styled-components.
-
Create an AWS Account if you don't have one.
-
Install AWS CLI:
https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
-
Configure AWS credentials:
aws configure
To create a new configuration:
- $ aws configure
- AWS Access Key ID :
your-access-key - AWS Secret Access Key :
your-secret-key - Default region name :
eu-north-1(or your preferred region) - Default output format :
json
Verify Authentication
aws sts get-caller-identity
Should return your AWS account details.
-
Install AWS CDK globally:
npm install -g aws-cdk
-
Install Node.js (version 20.x or later)
Download Node.js from: https://nodejs.org/
verify installation
node --version npm --version
The backend Lambda function uses container images, so Docker is required:
- Download Docker Desktop from: https://www.docker.com/products/docker-desktop/
- Verify installation:
docker --version
- Start Docker Desktop (must be running during deployment)
-
Clone the repository:
git clone https://github.com/finye/coffee-beans-iac.git cd coffee-beans-iac -
Install dependencies for all the components:
npm run install:all
This installs dependencies for the root, frontend, and CDK packages.
-
Bootstrap AWS CDK (first-time only):
cd cdk cdk bootstrap cd ..
This sets up the necessary AWS resources for CDK deployments in your account.
# From project root level
npm run deployThis will:
- Build the frontend React application
- Deploy the backend stack (Lambda + API Gateway)
- Deploy the frontend stack (S3 + CloudFront + config.json)
-
Build frontend
npm run build:frontend
-
Deploy the backend stack
npm run deploy:backend
This will:
- Build and deploy the Lambda container image
- Create the API Gateway
-
Deploy the frontend stack
npm run deploy:frontend
This will:
- Create an S3 bucket for hosting
- Set up CloudFront distribution
- Generate and upload config.json with runtime configuration
After deployment, you'll see the following outputs:
- CoffeeCo-Frontend.ApiEndpoint
- CoffeeCo-Frontend.SiteUrl
Visit the SiteUrl to see the deployed website :)
This will permanently delete all deployed resources.
npm run destroy:all