Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin language support #557

Closed
eladb opened this issue Aug 14, 2018 · 21 comments
Closed

Kotlin language support #557

eladb opened this issue Aug 14, 2018 · 21 comments
Assignees
Labels
effort/large Large work item – several weeks of effort feature/new-language Request for a new language binding feature-request A feature should be added or improved. language/support Related to non-typescript language bindings that aren't currently supported

Comments

@eladb
Copy link
Contributor

eladb commented Aug 14, 2018

+1 if you would like to see Kotlin support for the CDK

@eladb
Copy link
Contributor Author

eladb commented Aug 14, 2018

👍 from @skinny85 in aws/jsii#3925

@thesurlydev
Copy link
Contributor

I'd like to take a stab at contributing Kotlin support along with Gradle build with Kotlin DSL assuming this work hasn't already started.

Any pointers other than looking at what was done for Java?

@thesurlydev
Copy link
Contributor

I’ve written a POC which uses Kotlin language and Gradle Kotlin DSL: https://github.com/digitalsanctum/cdk-kotlin-example. I don’t think it would take much to add support for Kotlin and Gradle but the wiring up of cdk.json and app.sh leaves something to be desired.

@eladb
Copy link
Contributor Author

eladb commented Dec 6, 2018

Thanks @digitalsanctum! This is awesome. Asked some questions on your commit.

Happy to include this as a template for cdk init if you are interested.

@thesurlydev
Copy link
Contributor

Thanks. I've replied to your questions there.

The POC was a first step to prove that supporting Kotlin and Gradle wouldn't be a lot of extra effort. I'd like to address #1294 and further simplify the semantics around app.sh and cdk.json before including as a template for cdk init.

@srchase srchase added feature-request A feature should be added or improved. and removed enhancement labels Jan 3, 2019
@eladb eladb added the language/support Related to non-typescript language bindings that aren't currently supported label Mar 12, 2019
@willings
Copy link

willings commented Apr 3, 2019

I've started one, roughly tested :P
https://github.com/aws-cdk-dsl/aws-cdk-kotlin-dsl

@eladb
Copy link
Contributor Author

eladb commented Apr 3, 2019

@willings this is great! Would love to explore the option of adding this to our official release

@rmagatti
Copy link

Any news on this? @willings repo looks promising.

@toliner
Copy link

toliner commented Sep 4, 2019

Hi, I'm working on wrapper library of cdk.

Now, no documents are available but all source codes are available:
https://github.com/justincase-jp/AWS-CDK-Kotlin-DSL
And generated & built packages are available too:
https://bintray.com/justincase/aws-cdk-kotlin-dsl

This is WIP project, so any issue comment, or contribution is welcome.

@nbraid
Copy link

nbraid commented Apr 28, 2020

Another approach could be leveraging Kotlin's JS compatibility. JetBrains provides dukat to generate Kotlin JS files from TS definitions.

@codeslubber
Copy link

Jesus what happened here?? seemed like it was going to happen, but no... !

@ethanjdiamond
Copy link

Any updates on this?

@SomayaB SomayaB assigned ccfife and unassigned fulghum Jul 10, 2020
@ccfife ccfife added the effort/large Large work item – several weeks of effort label Jul 15, 2020
@pkrishnath
Copy link

Any updates?

@michaelbrewer
Copy link
Contributor

I have created a cookiecutter template, that I can open source if people are interested (and maybe add it to the CDK templates):

Screen Shot 2021-04-05 at 6 46 57 PM

This is what the directory structure looks like, it assumed your cdk code is within a larger project:

.
├── README.md
├── build.gradle
├── cdk
│   ├── README.md
│   ├── build.gradle
│   ├── cdk.context.json
│   ├── cdk.json
│   └── src
│       ├── main
│       │   └── kotlin
│       │       └── com
│       │           └── fiserv
│       │               └── services
│       │                   └── footie
│       │                       └── cdk
│       │                           ├── app
│       │                           │   └── App.kt
│       │                           └── stack
│       │                               └── ApplicationStack.kt
│       └── test
│           └── kotlin
│               └── com
│                   └── fiserv
│                       └── services
│                           └── footie
│                               └── cdk
│                                   └── stack
│                                       └── ApplicationStackTests.kt
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle

21 directories, 14 files
  • settings.gradle - Adds the cdk subproject
  • build.gradle - Is the base project with just the junit5 deps
  • cdk/build.gradle - Has the CDK deps
  • cdk/cdk.json - Has some demo properties and the app command to build and run the cdk code.

cdk/build.gradle:

plugins {
    id "application"
}

def cdkVersion = "1.96.0"
dependencies {
    implementation("org.slf4j:slf4j-simple:1.7.30")

    // AWS Cloud Development Kit
    implementation("software.amazon.awscdk:core:$cdkVersion")

    // Respective AWS Construct Libraries
    implementation("software.amazon.awscdk:iam:$cdkVersion")
    implementation("software.amazon.awscdk:lambda:$cdkVersion")
    implementation("software.amazon.awscdk:dynamodb:$cdkVersion")
    implementation("software.amazon.awscdk:apigateway:$cdkVersion")
}

application {
    mainClassName = 'com.fiserv.services.footie.cdk.app.AppKt'
}

cdk/cdk.json:

{
  "app": "cd ../; ./gradlew -q cdk:run",
  "context": {
    "branch": "develop",
    "env_dev": {
      "example": "DEMO ENVIRONMENT VARIABLE"
    }
  }
}

Example stack.kt

package com.fiserv.services.footie.cdk.stack

import software.amazon.awscdk.core.*
import software.amazon.awscdk.core.Stack

class ApplicationStack(scope: Construct, id: String, props: StackProps? = null) : Stack(scope, id, props) {
    init {
        val environment = this.node.tryGetContext("env") as String? ?: "dev"
        val branch = this.node.tryGetContext("branch") as String? ?: "develop"
        val namespace = "$environment${if (branch == "master") "" else "-$branch"}"
        @Suppress("UNCHECKED_CAST")
        val settings = this.node.tryGetContext("env_$environment") as Map<String, String>? 
            ?: throw RuntimeException("settings needs to be configured for $environment")

        // NOTE: Example of getting a environment config value from the cdk.json
        val example = settings.requireNotNull("example")
        CfnOutput(
                this,
                "ExampleOutput",
                CfnOutputProps
                        .builder()
                        .exportName("example-variable-$namespace")
                        .value(example)
                        .description("Example variable you can show or share for this stack: $namespace")
                        .build()
        )
    }

    private fun Map<String, String>.requireNotNull(name: String) = requireNotNull(this[name]) {
        "'$name' needs to be configured in cdk.json"
    }
}

@michaelbrewer
Copy link
Contributor

Btw. what @willings is the best I have seen for CDK, I hold AWS takes this on,.

@ericzbeard ericzbeard added the feature/new-language Request for a new language binding label Apr 6, 2021
@luistrigueiros
Copy link

Yes this is great idea, a fluent Kotlin DSL for CDK would be great

@ecejmsr
Copy link

ecejmsr commented Jan 9, 2022

+1 I just got “done” working on a stack that I’ve been at it for like… 6 months? TS isn’t bad once I got used to it. Kotlin would be nice. Would compile/run times times be relatively slower or faster than TS? Would auto scaling be impacted?

@luistrigueiros
Copy link

I agree that TS is not bad alternative, my preference for Kotlin comes from the fact that:

  1. Kotlin has excellent, support of internal DSL's, but I have doubt whether this is possible with the current infrastructure for code generation from JSII as the code generation would have to be done in a way that makes possible to leverage Kotlin's idioms like type safe builders [https://kotlinlang.org/docs/type-safe-builders.html] an interesting example is of what is possible with Kotlin is this one [https://kotlinlang.org/docs/type-safe-builders.html]
  2. Another issue with TS and JS ecosystem in general for me is security with NPN/Node.JS I think and the fact that it can easily pull so many packages with full access to filesystem in build infrastructure.

On the last one I think that it would be very interesting if the CDK/TS could run via [https://deno.land/] where there is much better security and sandboxing of JS code.

@waltervargas
Copy link

Is there any update on this?

@MrArnoldPalmer
Copy link
Contributor

Closing this as a duplicate of aws/jsii#1541

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/large Large work item – several weeks of effort feature/new-language Request for a new language binding feature-request A feature should be added or improved. language/support Related to non-typescript language bindings that aren't currently supported
Projects
None yet
Development

No branches or pull requests