Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DB_HOST=localhost
DB_PORT=5432
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_NAME=database-1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ lerna-debug.log*
!.elasticbeanstalk/*.global.yml

.env

.temp.*
cdk.out/
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
# nodejs-aws-cart-api
# Cart API Service

## API Endpoints

### Base URL

https://clv4uq63tjqjx52sqzia33d63e0uluqz.lambda-url.eu-west-1.on.aws


### Health Check
- **Endpoint**: `/`
- **Method**: GET
- **Description**: Checks the health status of the service
- **Example Request**:
```bash
curl https://clv4uq63tjqjx52sqzia33d63e0uluqz.lambda-url.eu-west-1.on.aws/


{"statusCode":200,"message":"OK"}
```
```
Cart model:

carts:
id - uuid (Primary key)
user_id - uuid, not null (It's not Foreign key, because there is no user entity in DB)
created_at - date, not null
updated_at - date, not null
status - enum ("OPEN", "ORDERED")

Cart Item model:

cart_items:
cart_id - uuid (Foreign key from carts.id)
product_id - uuid
count - integer (Number of items in a cart)
```
## Installation

```bash
Expand Down
3 changes: 3 additions & 0 deletions cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "npx ts-node deploy/App.ts"
}
10 changes: 10 additions & 0 deletions deploy/App.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as cdk from 'aws-cdk-lib';
import { Stack } from './Stack';

const app = new cdk.App();

new Stack(app, 'NodejsAwsCartApiStack', {
env: {
region: process.env.CDK_DEFAULT_REGION,
},
});
53 changes: 53 additions & 0 deletions deploy/Stack.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { Construct } from 'constructs';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import * as dotenv from 'dotenv';

dotenv.config();

export class Stack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const server = new NodejsFunction(this, 'server', {
functionName: 'nodejs-aws-cart-api',
runtime: lambda.Runtime.NODEJS_20_X,
entry: 'dist/main.lambda.js',
memorySize: 1024,
timeout: cdk.Duration.seconds(30),
bundling: {
minify: true,
target: 'node20',
externalModules: [
'@nestjs/microservices',
'@nestjs/websockets',
'class-transformer',
'class-validator',
],
},
environment: {
DB_HOST: process.env.DB_HOST,
DB_PORT: process.env.DB_PORT,
DB_USERNAME: process.env.DB_USERNAME,
DB_PASSWORD: process.env.DB_PASSWORD,
DB_NAME: process.env.DB_NAME,
},
});

// lambda via HTTP URL
const { url } = server.addFunctionUrl({
authType: lambda.FunctionUrlAuthType.NONE,
cors: {
allowedOrigins: ['*'],
allowedHeaders: ['*'],
allowedMethods: [lambda.HttpMethod.ALL],
maxAge: cdk.Duration.days(1),
},
});

new cdk.CfnOutput(this, 'Url', {
value: url,
});
}
}
6 changes: 5 additions & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"collection": "@nestjs/schematics",
"sourceRoot": "src"
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"webpack": false
}
}
Loading