This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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"; |
This file contains hidden or 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 { | |
| APIGatewayProxyEvent, | |
| APIGatewayProxyEventPathParameters, | |
| APIGatewayProxyHandler, | |
| APIGatewayProxyResult, | |
| } from "aws-lambda"; | |
| import { | |
| hydrateContext, | |
| validateCompanyAccessMiddleware, | |
| validateTokenUserAccessMiddleware, |
This file contains hidden or 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 { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda"; | |
| import { UserContext } from "../../../types"; | |
| import axios from "axios"; | |
| import middy from "@middy/core"; | |
| // middleware to ensure that the user is part of the given company i.e. permissions | |
| export const hydrateContext = (): middy.MiddlewareObj< | |
| APIGatewayProxyEvent, | |
| APIGatewayProxyResult |
This file contains hidden or 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 { APIGatewayProxyEvent, APIGatewayProxyResult } from "aws-lambda"; | |
| import { UserContext } from "../../../types"; | |
| import middy from "@middy/core"; | |
| // middleware to ensure that the user is part of the given company i.e. permissions | |
| // when getting their order for a specific company, as well as checking their role | |
| export const validateCompanyAccessMiddleware = ( | |
| role: string | |
| ): middy.MiddlewareObj<APIGatewayProxyEvent, APIGatewayProxyResult> => { |
This file contains hidden or 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 our lambda layer for our middleware | |
| const validationLayer: lambda.LayerVersion = new lambda.LayerVersion( | |
| this, | |
| "ValidationLayer", | |
| { | |
| compatibleRuntimes: [ | |
| lambda.Runtime.NODEJS_12_X, | |
| lambda.Runtime.NODEJS_14_X, | |
| ], | |
| code: lambda.Code.fromAsset("../layers/validation"), |
This file contains hidden or 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
| // add the cognito authorizer to our api which validates our tokens using cognito | |
| const cognitoAuthorizer: apigw.CfnAuthorizer = new apigw.CfnAuthorizer( | |
| this, | |
| "APIGatewayAuthorizer", | |
| { | |
| name: "sushi-orders-authorizer", | |
| identitySource: "method.request.header.Authorization", | |
| providerArns: [userPool.userPoolArn], | |
| restApiId: ordersAPI.restApiId, | |
| type: apigw.AuthorizationType.COGNITO, |