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
// the order regexes can be used across our domain objects, | |
// events, api validation and more.. | |
export const orderRegexes = { | |
orderId: '^[A-Z]{3}-\\d{1,4}$', | |
addressLine: '^[a-zA-Z0-9 _.-]*$', | |
productId: '^[A-Z]{4}-\\d{1,4}$', | |
}; |
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 { orderRegexes } from '@regexes/orders/order'; | |
export const schema = { | |
openapi: '3.0.0', | |
info: { version: '2.0.0', title: 'OrderCreated' }, | |
paths: {}, | |
components: { | |
schemas: { | |
AWSEvent: { | |
type: 'object', |
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
export const schema = { | |
openapi: '3.0.0', | |
info: { version: '1.0.0', title: 'OrderCreated' }, | |
paths: {}, | |
components: { | |
schemas: { | |
AWSEvent: { | |
type: 'object', | |
required: [ | |
'detail-type', |
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
const eventBus: IEventBus = EventBus.fromEventBusName( | |
this, | |
"OnlineOrders", | |
"OnlineOrdersEventBus" | |
); | |
// event bridge options for the api gateway integration | |
const eventBridgeOptions: apigw.IntegrationOptions = { | |
credentialsRole: apigwRole, | |
requestParameters: { |
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 state machine defintion for cancelling an order | |
const cancelOrderStateMachineDefinition: sfn.TaskStateBase = | |
new tasks.LambdaInvoke(this, "CancelOrder", { | |
lambdaFunction: cancelOrderHandler, | |
resultPath: "$", | |
timeout: Duration.seconds(30), | |
comment: "Cancel order task", | |
retryOnServiceExceptions: true, | |
}).addCatch( | |
new tasks.SqsSendMessage(this, "SendSQSFailure", { |
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 AWS from "aws-sdk"; | |
import { | |
CdkCustomResourceEvent, | |
CdkCustomResourceHandler, | |
CdkCustomResourceResponse, | |
} from "aws-lambda"; | |
import { Client } from "pg"; | |
import { v4 as uuid } from "uuid"; |
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 custom resource will create our postgres table on deploy if it doesn't exist | |
const provider: cr.Provider = new cr.Provider( | |
this, | |
"CreateOnlineOrdersTableCustomResource", | |
{ | |
onEventHandler: createTableHandler, // this lambda will be called on cfn deploy | |
logRetention: logs.RetentionDays.ONE_DAY, | |
providerFunctionName: "create-online-table-custom-resource", | |
} | |
); |
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
const dbConnectionGroup: ec2.SecurityGroup = new ec2.SecurityGroup( | |
this, | |
"RdsProxyDBConnection", | |
{ | |
vpc, | |
securityGroupName: "rds-proxy-sg", | |
} | |
); | |
dbConnectionGroup.addIngressRule( |
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
// https://github.com/aws/aws-cdk/issues/20197 | |
enum ServerlessInstanceType { | |
SERVERLESS = "serverless", | |
} | |
type CustomInstanceType = ServerlessInstanceType | ec2.InstanceType; | |
const CustomInstanceType = { | |
...ServerlessInstanceType, | |
...ec2.InstanceType, |
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 { | |
APIGatewayRequestAuthorizerEvent, | |
AuthResponse, | |
PolicyDocument, | |
} from "aws-lambda"; | |
import { CognitoJwtVerifier } from "aws-jwt-verify"; | |
import { CognitoJwtVerifierSingleUserPool } from "aws-jwt-verify/cognito-verifier"; | |
import axios from "axios"; | |
import jwt from "jsonwebtoken"; |