-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced nest in favour of aws api gateway + lambdas
- Loading branch information
Facundo De Lorenzo
committed
May 16, 2024
1 parent
e748c6b
commit 7af5fc3
Showing
15 changed files
with
177 additions
and
2,947 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version = 0.1 | ||
[default] | ||
[default.deploy] | ||
[default.deploy.parameters] | ||
s3_bucket = "faq-lambda-artifacts" | ||
region = "us-east-1" | ||
confirm_changeset = true | ||
capabilities = "CAPABILITY_IAM" | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { APIGatewayEvent, Callback, Context } from 'aws-lambda'; | ||
import { CreateOrderRequest, Order, Product } from './types'; | ||
|
||
const responseHeaders = { | ||
'Access-Control-Allow-Origin': '*', | ||
'Access-Control-Allow-Credentials': true, | ||
'Access-Control-Allow-Methods': 'OPTIONS,GET, POST', | ||
}; | ||
|
||
exports.get = async ( | ||
event: APIGatewayEvent, | ||
context: Context, | ||
callback: Callback, | ||
) => { | ||
try { | ||
const products: Product[] = [ | ||
{ name: 'Kuva Roast Rib Eye', price: 418 }, | ||
{ name: 'Guadalupe Half Rack', price: 298 }, | ||
{ name: 'Tohono Chicken', price: 308 }, | ||
]; | ||
|
||
return { | ||
isBase64Encoded: false, | ||
statusCode: 200, | ||
headers: responseHeaders, | ||
body: JSON.stringify(products), | ||
}; | ||
} catch (error) { | ||
return { | ||
isBase64Encoded: false, | ||
statusCode: 500, | ||
headers: responseHeaders, | ||
body: error.message, | ||
}; | ||
} | ||
}; | ||
|
||
exports.createOrder = async ( | ||
event: APIGatewayEvent, | ||
context: Context, | ||
callback: Callback, | ||
) => { | ||
try { | ||
const req: CreateOrderRequest = JSON.parse(event.body); | ||
|
||
if (!req?.products) | ||
return { | ||
isBase64Encoded: false, | ||
statusCode: 400, | ||
headers: responseHeaders, | ||
body: "Products must be provided", | ||
} | ||
const order: Order = { | ||
products: req.products, | ||
totalPrice: req.products.reduce((acc, val) => acc + val.price, 0), | ||
}; | ||
|
||
return { | ||
isBase64Encoded: false, | ||
statusCode: 200, | ||
headers: responseHeaders, | ||
body: JSON.stringify(order), | ||
}; | ||
} catch (error) { | ||
return { | ||
isBase64Encoded: false, | ||
statusCode: 500, | ||
headers: responseHeaders, | ||
body: error.message, | ||
}; | ||
} | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export interface CreateOrderRequest { | ||
products: Product[]; | ||
} | ||
|
||
export interface Product { | ||
name: string; | ||
price: number; | ||
} | ||
|
||
export interface Order { | ||
products: Product[]; | ||
totalPrice: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
Transform: AWS::Serverless-2016-10-31 | ||
Description: Api | ||
|
||
Resources: | ||
GetProductsFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: ./dist | ||
Handler: products.get | ||
Runtime: nodejs20.x | ||
MemorySize: 128 | ||
Timeout: 10 | ||
Events: | ||
Event: | ||
Type: Api | ||
Properties: | ||
Method: GET | ||
Path: /products | ||
|
||
createOrderFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: ./dist | ||
Handler: products.createOrder | ||
Runtime: nodejs20.x | ||
MemorySize: 128 | ||
Timeout: 10 | ||
Events: | ||
Event: | ||
Type: Api | ||
Properties: | ||
Method: POST | ||
Path: /createOrder |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.