Thanks to visit codestin.com
Credit goes to github.com

Skip to content

aws-cdk-dsl/aws-cdk-kotlin-dsl

Repository files navigation

AWS CDK Kotlin DSL

Kotlin Build Status License: MIT

The DSL wrapper on top of AWS CDK. The DSL is fully compatible with SDK Java implementation, meanwhile improves readability of infrastructure related code.

Why AWS CDK Kotlin DSL?

It is a great concept of infrastructure as code, however the problem is what kind of code should it be?

  • yaml (or json): concise however no type-safety and runtime checks, thus why CDK is developed
  • java (or other langs provided by CDK): type safe, but less descriptive than yaml

The idea of Kotlin DSL is to utilize Kotlin's type-safe builder which has been proved as successful in latest Gradle build.gradle practice. The benefit of this way is:

  • Concise as yaml, write less code and easier to diff/review
  • Type safety on top of Java
  • IDE autocomplete support
  • Interoperability with Java, no risk of lacking DSL coverage

A quick example of constructing stack using Kotlin DSL, we could see the benefit easily.

fun main() {

    app {
        stack("myStackId") {
            function("myFunctionId", functionProps {
                functionName = "myFunction"
                runtime = NODE_J_S810
                memorySize = 128
                handler = "index.handler"
                code = Code.inline("""
                    exports.handler = function(event, context, callback) {
                        callback(null, "Hello, World!");
                    }
                """.trimIndent())
            })
        }
    }.run()
}

Quick Start

(It is not released to mavenCentral or jCenter yet)

Checkout lambda-example under examples for a quick view!

Known issues

  • List, Map types on builder is not supported (due to lacking generic type information), use raw withXxx method on builder instead.

License

The AWS CDK Kotlin DSL is distributed under the MIT License.

Releases

No releases published

Packages

No packages published

Languages