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
import { | |
APIGatewayEvent, | |
APIGatewayProxyHandler, | |
APIGatewayProxyResult, | |
} from "aws-lambda"; | |
// we import these values which are locale aware | |
import { errorMessages } from "@shared/error-messages"; | |
import { schema } from "./create-sale.schema"; | |
import { stringFormat } from "@shared/string-format"; |
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
import * as lambda from "aws-cdk-lib/aws-lambda"; | |
import * as nodeLambda from "aws-cdk-lib/aws-lambda-nodejs"; | |
import * as path from "path"; | |
import { dynamicPath, getLocale } from "@shared/dynamic-imports"; | |
export const getSalesLambdaProps: nodeLambda.NodejsFunctionProps = { | |
runtime: lambda.Runtime.NODEJS_14_X, | |
functionName: "getSalesLambda", | |
// the entry point utilises our dynamic path generator |
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
import * as apigw from "aws-cdk-lib/aws-apigateway"; | |
import * as nodeLambda from "aws-cdk-lib/aws-lambda-nodejs"; | |
import { Stack, StackProps } from "aws-cdk-lib"; | |
import { Construct } from "constructs"; | |
interface SalesProps extends StackProps { | |
apiProps: apigw.RestApiProps; | |
getSalesLambdaProps: nodeLambda.NodejsFunctionProps; |
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
import * as fs from "fs"; | |
import * as path from "path"; | |
function rootDir(): string { | |
return __dirname; | |
} | |
// function to return the locale lowercase | |
export function getLocale(): string { | |
if (!process.env.LOCALE) { |
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
#!/usr/bin/env node | |
import "source-map-support/register"; | |
import * as apigw from "aws-cdk-lib/aws-apigateway"; | |
import * as cdk from "aws-cdk-lib"; | |
import * as nodeLambda from "aws-cdk-lib/aws-lambda-nodejs"; | |
import { SalesStack } from "@lib/sales-stack"; | |
import { dynamicImport } from "@shared/dynamic-imports"; |
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
// create the tires orders event bus | |
const ordersEventBus: events.EventBus = new events.EventBus( | |
this, | |
"orders-event-bus", | |
{ | |
eventBusName: "orders-event-bus", | |
} | |
); | |
ordersEventBus.applyRemovalPolicy(RemovalPolicy.DESTROY); |
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
// create the waf ip set for the api | |
const webAclIPSet = new waf.CfnIPSet(this, "TiresWhitelistIpSet", { | |
name: "tires-whitelist-ip-set", | |
addresses: [`${props.ordersApiIp}/32`], // the source orders api ip address which we allow | |
ipAddressVersion: "IPV4", | |
scope: "REGIONAL", | |
description: "tires api ip set", | |
}); | |
const webacl = new waf.CfnWebACL(this, "TiresWhitelistWebAcl", { |
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
// create the stock table for storing the tire orders | |
const stockTable: dynamodb.Table = new dynamodb.Table( | |
this, | |
"StockOrdersTable", | |
{ | |
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST, | |
encryption: dynamodb.TableEncryption.AWS_MANAGED, | |
pointInTimeRecovery: true, // we add point in time recovery for our table | |
tableName: "StockOrders", | |
contributorInsightsEnabled: true, |
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
// ensure our flow logs go to cloudwatch | |
vpc.addFlowLog("FlowLogS3", { | |
destination: ec2.FlowLogDestination.toCloudWatchLogs(), | |
trafficType: ec2.FlowLogTrafficType.ALL, | |
}); |
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
// create the vpc for the car company solution | |
const vpc: ec2.Vpc = new ec2.Vpc(this, "CarOrdersVPC", { | |
cidr: "10.0.0.0/16", | |
maxAzs: 2, // for the demo only lets add 2 az's note: in production this should be at least 3 | |
natGateways: 1, // The nat gateway has to be provisioned in a public subnet, with a public ip address to access the internet through internet gateway | |
subnetConfiguration: [ | |
{ | |
cidrMask: 24, | |
name: "private-subnet", | |
subnetType: ec2.SubnetType.PRIVATE_WITH_NAT, |