jsii icon indicating copy to clipboard operation
jsii copied to clipboard

(aws-cdk): Information for Requesting Deno Support

Open shellscape opened this issue 4 years ago • 16 comments

General Issue

Information for Requesting Deno Support

The Question

I'd like to know what the proper procedures and steps are required to start the discussion around formal support for Deno (https://deno.land). Deno is an alternative to Node that supports TypeScript and ESM natively. While it's a close cousin, many of the mechanisms have significant differences, namely dependency management. Presently, to make use of AWS CDK for Deno apps, users must run Node along side Deno.

I'd like to propose Deno support for AWS CDK, as it's already authored in TypeScript for Node support, but I'm honestly not sure where to begin.

CDK CLI Version

1.131.0

Framework Version

No response

Node.js Version

No response

OS

No response

Language

Typescript

Language Version

No response

Other information

No response

shellscape avatar Nov 07 '21 15:11 shellscape

I would like to add to this. The biggest benefit is the nature of the cdk in that you want infrastructure as code but why do you need to compile code first. Thats just a a side effect of how typescript works with node. With deno you could basically just generate a single TypeScript file, cdk config and a README.md and then you are god to go. No compile step. Dependencies are declared inside the TypeScript file etc. Its the perfect tool for CDK. Deno is also super simple to install. The deno engine could probably be embedded as well. There could be a cdk-ts that basically didn't even need deno installed it just had a TS as input. That would be awesome.

PerArneng avatar Nov 18 '21 12:11 PerArneng

Thanks for the issue @shellscape

I'll convert this to a feature request since its requesting new support. Feel free to update your description accordingly.

We prioritize by community feedback so +1 👍🏻 the issue if you'd like to see this worked.

ryparker avatar Nov 18 '21 20:11 ryparker

The biggest benefit is the nature of the cdk in that you want infrastructure as code but why do you need to compile code first.

You do not have to, you can choose to use ts-node as well. This will provide the same benefits.

rix0rrr avatar Nov 22 '21 13:11 rix0rrr

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

github-actions[bot] avatar Apr 10 '22 00:04 github-actions[bot]

So I see that this has gotten a few +1s. It's one of those long-living tracking issues though, and some of the other issues labeled feature/new-language have hundreds of +1s. It would be incorrect to keep this as a p1, as we are not considering adding new languages to JSII at this time, and even if we were, I'm not sure that this would be the language we pick up.

kaizencc avatar May 17 '22 14:05 kaizencc

Odd considering it's probably the easiest lateral move with the least amount of effort needed from the current Node support.

shellscape avatar May 17 '22 14:05 shellscape

we are not considering adding new languages to JSII at this time, and even if we were, I'm not sure that this would be the language we pick up.

Can I suggest a bit of a review into it? Deno is literally the successor to Node, written by the same creator (Ryan Dahl), and in a stable form used by an increasingly growing number of developers. And like shellscape pointed out, it's a very, very easy transition. The reason this post got so much attention is because a lot of devs (like myself) are waiting for basically this final piece to start transitioning all of our business apps into Deno.

BrintParisK avatar May 23 '22 18:05 BrintParisK

if you need help get this running: i am happy to invest some time into it.

sebs avatar Jul 01 '22 17:07 sebs

I wish I could run cdk using deno. It seems to me that this could slim down the configuration a lot.

tarcon avatar Jul 11 '22 12:07 tarcon

The newly released Deno 1.28 has npm support out of the box. It's incredibly tempting to be able to run CDK without needing to install anything at all. The npm support would probably make it a lot simpler to integrate with CDK.

we are not considering adding new languages to JSII at this time

I'd be hard pressed to call Deno a language. It's Typescript, and even compatible with the web. It has it's own API on the Deno namespace, which is similar to Node's built in modules. Given that the CDK supports Typescript already, a large part should already work as-is.

csvn avatar Nov 15 '22 16:11 csvn

It seems that a simple CDK project can already be made to work with Deno (including CDK CLI).

// deno.jsonc
{
  "tasks": {
    "cdk": "deno run --allow-all npm:aws-cdk --app 'deno run --allow-all main.ts'",
    "test": "deno test --allow-all",
    "ci": "deno fmt --check && deno lint && deno task test"
  },
  "lint": {
    "files": {
      "exclude": ["cdk.out"]
    }
  },
  "fmt": {
    "files": {
      "exclude": ["cdk.out"]
    }
  }
}
// main.ts
import cdk from "npm:aws-cdk-lib";

const app = new cdk.App();
export const stack = new cdk.Stack(app, "DenoCdkStack");

new cdk.aws_logs.LogGroup(stack, "DenoCdkLogGroup");
// main.test.ts
import { assertSnapshot } from "https://deno.land/[email protected]/testing/snapshot.ts";
import { Template } from "npm:aws-cdk-lib/assertions";
import { stack } from "./main.ts";

Deno.test("Snapshot Test", async (t) => {
  await assertSnapshot(t, Template.fromStack(stack).toJSON());
});
$ deno task cdk synth

$ deno task test

[Edit] deno task cdk deploy does not succeed, but it looks close...

rinfield avatar Dec 05 '22 08:12 rinfield

[Edit] deno task cdk deploy does not succeed, but it looks close...

fwiw I got this to work:

...
✅  DenoCdkStack

✨  Deployment time: 31.42s

Stack ARN:
arn:aws:cloudformation:us-east-42:123456789:stack/DenoCdkStack/p0938dc0-7b50-11ed-8365-0ecc2da87269

✨  Total time: 33.75s

// deno.jsonc
...
    "deploy": "deno run --allow-all npm:aws-cdk deploy"
...

then I called it via:

deno task deploy --app cdk.out --profile foo

what worked for me was --profile foo.

Reading the default profile from ~/.aws/ was not working (even though it was configured correctly for the CLI tools to work). Setting env vars like AWS_ACCESS_KEY_ID in the environment or a .env file (loading via import "https://deno.land/[email protected]/dotenv/load.ts";) was also not working.

Only thing that worked was copying the default profile to something else (foo) in my case, and explicitly passing it to the cdk cli.

🤷🏻

virtuoushub avatar Dec 14 '22 01:12 virtuoushub

This issue should be tracked in jsii. Please note that although we do not have the bandwidth to take this on, we do accept community contributions so if anyone really wants to see this happen, feel free to start an RFC on this.

TheRealAmazonKendra avatar Jan 27 '23 03:01 TheRealAmazonKendra

This issue should be tracked in jsii. Please note that although we do not have the bandwidth to take this on, we do accept community contributions so if anyone really wants to see this happen, feel free to start an RFC on this.

Thanks for your reply and suggestion. Seeing how this thread is going I agree it should be picked up by the Deno community themselves I think. Just a check question: even though Deno supports Typescript natively you think there still should be a separate JSII implementation? What would this add over the existing one for Typescript? I am trying to wrap my head around where this would fit and how we would start on this RFC. :)

meije702 avatar Jan 28 '23 15:01 meije702

There are numerous aspects to this, and this issue could hide multiple things in reality... Most of the comments appear to ask for ability to natively use deno for working with CDK apps written in TypeScript. I don't reckon this requires any material changes from jsii's side, as deno has a compatibility layer that should be all that's needed... That said, there might be something to do with respects to how we are currently targeting CommonJS and not ESM. Dependency management might be another place where things may need to be done, but I'm not sure exactly how much or what.

Now - if there's a broader ask of being able to use deno instead of node as the JS runtime used by foreign interfaces (Java, C#, Go, Python, ...), then yes, this is actually touching into jsii feature land, and might hopefully be relatively easy to do (the runtimes will shell out to node but they could as well shell out to deno instead either in the absence of node, or when a specific environment variable is set).

We are currently busy on other projects, but would welcome community contributions on that front. Note however that it'd be very useful for any work in that space to bring in new integration tests run with deno right off the bat.

RomainMuller avatar Feb 08 '23 09:02 RomainMuller

note the asw-cdk package works on deno

guy-borderless avatar Oct 04 '23 18:10 guy-borderless