The DSL wrapper on top of AWS CDK. The DSL is fully compatible with SDK Java implementation, meanwhile improves readability of infrastructure related code.
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 developedjava
(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:
yaml
, write less code and easier to diff/reviewA 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()
}
(It is not released to mavenCentral
or jCenter
yet)
Checkout lambda-example under examples
for a quick view!
List
, Map
types on builder is not supported (due to lacking generic type information), use raw withXxx
method on builder instead.The AWS CDK Kotlin DSL is distributed under the MIT License.