serverless-next.js
serverless-next.js copied to clipboard
CDK Construct for users of python CDK
Is your feature request related to a problem? Please describe. The CDK constructs in this lib are only usable in a Typescript CDK project. Would like to be able to use them in a Python based CDK project.
Describe the solution you'd like AWS has a jsii project that is used as part of CDK to create bindings for other languages. This involved generating the bindings and publishing the projects to corresponding repositories. For Python, Pypi would be the appropriate location.
Describe alternatives you've considered Would have to recreate our existing CDK set of utilities in Typescript or deploy the Next.js application separately.
Additional context Are there any plans to do such thing? Any recommendations?
This does not seem to be in the radar for the contributors, but I wanted to update some of my findings here.
As it stands, the current construct cannot be processed by JSII. The class is just not compatible with JSSI conventions and I suspect too much work to make it so. Having said that, it is still possible to expose this construct to other languages by doing the following. NOTE that my goal was to not have to fork and create my own version of this repo.
- Create a separate project modeled after a new CDK Construct.
- Add
@sls-next/cdk-construct
as a dependency. - To have JSII ignore the dependency in its processing, mark it as a bundled dependency. See JSII dependency requirements.
- Create a new module, import
NextJSLambdaEdge
- Create a new class that extends core:Construct and then instantiate NextJSLambdaEdge in the constructor. Something like this:
import { NextJSLambdaEdge } from '@sls-next/cdk-construct';
import * as cdk from "@aws-cdk/core";
export class NextJs extends cdk.Construct {
private nestJs: NextJSLambdaEdge;
constructor(scope: cdk.Construct, id: string, build_dir: string) {
super(scope, `${id}_proxy`);
this.nestJs = new NextJSLambdaEdge(this, id, {
serverlessBuildOutDir: build_dir
});
}
public bucketName() {
return this.nestJs.bucket.bucketArn;
}
}
-
npm run build; npm run package
to build and package the library. You will end up with distributions in different language based on JSII configurations. Similar to this.