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(orjson): concise however no type-safety and runtime checks, thus why CDK is developedjava(or other langs provided by CDK): type safe, but less descriptive thanyaml
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()
}(It is not released to mavenCentral or jCenter yet)
Checkout lambda-example under examples for a quick view!
List,Maptypes on builder is not supported (due to lacking generic type information), use rawwithXxxmethod on builder instead.
The AWS CDK Kotlin DSL is distributed under the MIT License.