Skip to content

Instantly share code, notes, and snippets.

@eladb eladb/
Last active Mar 19, 2019

What would you like to do?
Reflecting on the AWS CDK Type System using jsii-reflect
set -euo pipefail
# given an aws-cdk bundle archive (the one published to github releases), extract
# all .jsii manifests and places them under "jsii/*.jsii"
# now they can be used with jsii-reflect
if [ -z "${zip}" ]; then
echo "Usage: $(basename $0) <cdk-bundle-zip>"
exit 1
# make absolute path
zip="$(cd $(dirname ${zip}) && pwd)/$(basename ${zip})"
rm -fr ${outdir}
mkdir -p ${outdir}
workdir=$(mktemp -d)
(cd ${workdir} && unzip -q ${zip} js/*)
for tarball in $(find ${workdir} -name *.jsii.tgz); do
basename=$(basename ${tarball} .jsii.tgz)
staging=$(mktemp -d)
cd ${staging}
if tar -xzv --strip-components=1 -f ${tarball} package/.jsii 2> /dev/null; then
echo ${basename}
mv .jsii ${outdir}/${basename}.jsii
rm -fr ${staging}

The AWS CDK uses jsii to package it's modules to multiple programming languages. The following document describes how to use a tool called jsii-reflect to explore the CDK's type system.

Create a working directory:

mkdir cdk-explore
cd cdk-explore

Download the .zip release of the CDK from GitHub Releases:

curl -LO

Now, we need to extract all .jsii files from the release. Download the script:

curl -LO ""
chmod +x ./

This will create a jsii subdirectory with all CDKK .jsii files.

Next, we'll use the jsii-reflect module to reflect load the entire type system into memory and explore it.

Install the jsii-reflect npm module:

npm i --no-save jsii-reflect

Now, create a file explore.js (if you use VSCode, you'll get nice code completion and stuffs):

const { TypeSystem } = require('jsii-reflect');
const fs = require('fs');
const path = require('path');

const ts = new TypeSystem();

async function main() {
  // load all .jsii files into the type system
  for (const file of fs.readdirSync('./jsii')) {
    await ts.load(path.join('./jsii', file));

  // ready to explore!

  for (const cls of ts.classes) {
    console.log('class name:',;
    console.log('base class:', cls.base && cls.base.fqn);
    console.log('properties:', =>;
    console.log('method:', =>;

main().catch(e => {

Explore Away!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.