Created
August 13, 2023 03:43
-
-
Save ColeMurray/9fdc5ee298ef941db367985eb91b4548 to your computer and use it in GitHub Desktop.
Deployment stack for serverless-express
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 {Stack, StackProps} from "aws-cdk-lib"; | |
import {Construct} from "constructs"; | |
import {ApprovedNodeLambda} from "./constructs/approvedNodeLambdaConstruct"; | |
import {Cors, LambdaIntegration, RestApi} from "aws-cdk-lib/aws-apigateway"; | |
export interface DeploymentStackProps extends StackProps { | |
envVars?: Record<string, string>, | |
} | |
export class DeploymentStack extends Stack { | |
constructor(scope: Construct, id: string, props: DeploymentStackProps) { | |
super(scope, id, props); | |
const serverFunction = new ApprovedNodeLambda(this, 'backend-server', { | |
codeDir: '../source/', | |
description: 'backend server lambda function', | |
handler: 'src/lambdaServer.handler', | |
runtimeEnvironment: props.envVars ?? {} | |
}); | |
const api = new RestApi(this, 'api', { | |
restApiName: 'BackendApi', | |
description: 'Api gateway for backend api', | |
binaryMediaTypes: ['*/*'] | |
}); | |
api.root.addProxy({ | |
defaultCorsPreflightOptions: { | |
allowOrigins: Cors.ALL_ORIGINS, | |
allowMethods: Cors.ALL_METHODS, | |
}, | |
defaultIntegration: new LambdaIntegration(serverFunction.lambda, { | |
proxy: true | |
}), | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment