Project

ruby-cdk

0.0
The project is in a healthy, maintained state
Define AWS infrastructure as Ruby code, synthesize byte-identical CloudFormation templates, validate them at synth against the schemas AWS publishes, and deploy them through change sets with the AWS SDK for Ruby. A pure Ruby toolchain: no JavaScript runtime anywhere.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

ruby-cdk

Infrastructure as code in pure Ruby, in the style of the AWS CDK: define stacks as Ruby objects, synthesize deterministic CloudFormation templates validated against the schemas AWS publishes, and deploy them through change sets with the AWS SDK for Ruby. No Node.js, no jsii, no npm anywhere in the toolchain.

Status: 0.1.0, pre-release. The gem is on rubygems.org and attached to each release. The API is still settling; see Status.

What it is

The AWS CDK's programming model, reimplemented in Ruby. Your app file creates one RubyCdk::App; stacks are classes with a build method that declares resources, parameters and outputs; synthesis turns the object tree into CloudFormation templates whose every byte is specified, and the ruby-cdk CLI deploys them through change sets. Properties are written with CloudFormation's names, or in snake_case — the keys are normalized against AWS's own resource schemas before anything is written.

"Measured against the CDK" is a number, not a claim. The CDK's own test suites are ported and run in the default gate (rake parity): 2,445 cases, 803 of them ported, every ported case passing, and each of the others listed in a ported file's header with the reason it is not ported — every header's origin count held to the counted fact in test/cdk/origins.json, so the numbers are recountable, not remembered. The whole suite — 2,598 runs, 26,918 assertions — passes with no AWS credential reachable; the same gate keeps line coverage above 98% over a floor of 85%, and proves that every example synthesizes byte-identical output across two runs with different Ruby hash seeds.

Install

From rubygems.org, or from source:

gem install ruby-cdk
git clone https://github.com/a-safe-digital/ruby-cdk.git
cd ruby-cdk
bundle install
bundle exec rake install:local   # builds the gem and installs it into your gems
$ ruby-cdk version
0.1.0

The gem ships no native code, so no compiler is needed.

Quickstart

With the gem installed (above), ruby-cdk new scaffolds the smallest useful app — one stack, one S3 bucket that stays private, a parameter, and the three commands in its README:

ruby-cdk new my-app
cd my-app
bundle install            # ruby-cdk is on rubygems.org; this resolves the Gemfile

The directory holds the app file, cdk.rb — one RubyCdk::App, one stack:

require "ruby-cdk"
require_relative "my_app/my_app_stack"

RubyCdk::App.new do |app|
  MyApp::Stack.new(app, "my-app")
end

and the stack, my_app/my_app_stack.rb, declares what the template holds — a parameter for versioning, and a bucket with public access blocked on all four settings and AES256 encryption:

module MyApp
  class Stack < RubyCdk::Stack
    def build
      versioning = parameter("Versioning", type: "String", default: "Suspended", allowed_values: [ "Suspended", "Enabled" ],
        description: "Whether the bucket keeps every version of an object")

      resource("Bucket", "AWS::S3::Bucket", properties: {
        "BucketEncryption" => {
          "ServerSideEncryptionConfiguration" => [
            { "ServerSideEncryptionByDefault" => { "SSEAlgorithm" => "AES256" } }
          ]
        },
        "PublicAccessBlockConfiguration" => {
          "BlockPublicAcls" => true,
          "BlockPublicPolicy" => true,
          "IgnorePublicAcls" => true,
          "RestrictPublicBuckets" => true
        },
        "VersioningConfiguration" => { "Status" => Fn.ref(versioning) }
      })
    end
  end
end

Synthesize it:

bundle exec ruby-cdk synth

This validates the tree, writes cdk.out/my-app.template.json and cdk.out/manifest.json, and prints the template, with a Synthesis time: … line on standard error first:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "Versioning": {
      "Type": "String",
      "Default": "Suspended",
      "Description": "Whether the bucket keeps every version of an object",
      "AllowedValues": [
        "Suspended",
        "Enabled"
      ]
    }
  },
  "Resources": {
    "Bucket": {
      "Type": "AWS::S3::Bucket",
      "DeletionPolicy": "RetainExceptOnCreate",
      "UpdateReplacePolicy": "Retain",
      "Properties": {
        "BucketEncryption": {
          "ServerSideEncryptionConfiguration": [
            {
              "ServerSideEncryptionByDefault": {
                "SSEAlgorithm": "AES256"
              }
            }
          ]
        },
        "PublicAccessBlockConfiguration": {
          "BlockPublicAcls": true,
          "BlockPublicPolicy": true,
          "IgnorePublicAcls": true,
          "RestrictPublicBuckets": true
        },
        "VersioningConfiguration": {
          "Status": {
            "Ref": "Versioning"
          }
        }
      }
    }
  }
}

ruby-cdk validate runs the same rules without writing anything (its section is below), so a template CloudFormation would reject is caught here, before any deploy.

Deploy it:

bundle exec ruby-cdk deploy

The command prints the target — account, region, profile — before the first request, creates the change set, prints every change in it and the IAM capabilities it would add, and then asks, in a terminal:

Deploy these changes to stack my-app in account 123456789012 (eu-central-1)?

Yes executes the change set and follows the operation, printing each event as it arrives and the outputs at the end. Anything else stops: the change set is deleted, and a not-yet-created stack is deleted with it, so a refused deploy leaves nothing behind. A stack without an env deploys wherever your credentials point, after the command prints the target. Useful options:

  • --yes — deploy without asking. Without a terminal the command stops at the question anyway (exit 4, nothing deployed), so unattended runs must say --yes.
  • --parameters K=V,K=V and --tags K=V,K=V — template parameters and stack tags. A parameter you don't name again keeps the value the stack was last deployed with (the CDK's --previous-parameters, on by default); with --no-previous-parameters every parameter without a template default must be named on every deploy.
  • --outputs-file PATH — the outputs of each stack as JSON.
  • --no-execute — create the change set and leave it for the console.
  • --on-failure DELETE|ROLLBACK|DO_NOTHING — what CloudFormation does when a first deploy fails (default DELETE, so a failed creation cleans up after itself).
  • --notification-arns ARN[,ARN] — SNS topics CloudFormation notifies with the stack's events (the CDK's flag). Not given, whatever the stack carries is left alone; an ARN that is not an SNS topic's is refused before anything is asked of AWS.
  • --rollback-trigger-alarm-arns ARN[,ARN] and --monitoring-time-minutes N — the CloudWatch alarms CloudFormation monitors during the deployment, rolling it back when one goes ALARM (the CDK's rollback triggers: at most five alarms, zero to 180 whole monitoring minutes, and the minutes need the alarms). --rollback-trigger-alarm-arns none clears what the stack has; not given, nothing is managed and whatever the stack carries stays.
  • --import-existing-resources — the change set imports resources that already exist instead of failing on them.
  • --force — deploy even when the deployed template, parameters and tags are unchanged (unchanged means the deploy is skipped).
  • --all, -e/--exclusively — every stack of the app in dependency order, or only the ones named.
  • --hotswap / --hotswap-fallback — the development-loop fast path; see below.

The hotswap fast path. Change sets are the default, and the CDK's --hotswap flags are the deliberate way around them for the inner development loop. With --hotswap or --hotswap-fallback, the deploy diffs the synthesized template against the deployed one and, when every change is a Lambda function's code (an asset's S3 location, S3ObjectVersion, or inline ZipFile) or in-place configuration (Handler, Runtime, MemorySize, Timeout, Environment, Description), applies them with one direct UpdateStack — no change set, no waiting for one — reporting each function it swapped and asking the same approval question a change-set deploy asks. Anything else (a new or removed resource, a replacement, any other type or section) is refused by the fast path: --hotswap-fallback hands the whole deploy to the normal change set, the CDK's FALL_BACK mode, while --hotswap reports what it refused and applies nothing, the CDK's HOTSWAP_ONLY mode — giving both is an error. With --json, the per-stack record gains a hotswap object: the mode, whether the change set took over, the swapped functions, and the refused changes with their reasons. The command prints the CDK's own warning above every hotswap deploy:

⚠️ The --hotswap and --hotswap-fallback flags deliberately introduce CloudFormation drift to speed up deployments
⚠️ They should only be used for development - never use them for your production Stacks!

A hotswap puts the stack outside what CloudFormation last deployed (drift); the next ordinary deploy brings it back in line. Do not use either flag on a production stack.

The development loop. bundle exec ruby-cdk watch is the CDK's cdk watch: it synthesizes and deploys once up front, then polls the app's files and, on a change, synthesizes and deploys again — hotswapping by default — until you interrupt it. It takes the stack selection deploy takes (--all, -e/--exclusively), the deploy flags the inner deploy uses (--parameters, --tags, --force, and the global --profile, --region, --account), and --hotswap / --no-hotswap / --hotswap-fallback (--hotswap is on by default; --no-hotswap deploys every change through a change set). What is watched is the app file and every asset source directory the manifest records — the synthesis output directory and hidden files are left out, as the CDK's watch leaves its own out — and a deploy that fails, like an app file broken mid-edit, is printed and watched through: the next change tries again. The inner deploy never asks (--yes is the watch's): the CDK's watch deploy is built with RequireApproval.NEVER, and a loop that stops to ask is not a watch. A change the fast path refuses is reported and ignored, and the watch goes on. The poll runs every --interval SECONDS (one second by default) — this flag is this tool's own: the CDK's watcher is a native file watcher, and ours polls in process, starting no watcher of its own. The loop prints the CDK's own lines:

'watch' is observing the file '/path/to/cdk.rb' for changes
Triggering initial 'ruby-cdk deploy'
Detected change to '/path/to/cdk.rb' (type: change). Triggering 'ruby-cdk deploy'

Preview a deploy. bundle exec ruby-cdk diff compares each stack's synthesized template with the one CloudFormation holds: per resource and per changed property path, the properties whose change replaces the resource marked as such, and the security view — the IAM statements a deployment adds or takes away. It reads the deployed template and writes nothing. The command exits 0 whether or not there are differences; these options decide otherwise, as the CDK's do:

  • --fail — exit 1 when a stack differs.
  • --fail-on=any-change | broadening | destructive | never — exit 1 when the diff holds that kind of change: any difference; a change that broadens permissions; a resource that would be replaced, destroyed or orphaned, listed after the closing line; or never. Not together with --fail.
  • --security-only — the security view alone.
  • --json — one object per stack on standard output: the changes with their replacement facts, the security view, and the destructive changes.

Detect live drift. bundle exec ruby-cdk drift [STACK...] runs CloudFormation drift detection on each selected stack (DetectStackDrift, polling DescribeStackDriftDetectionStatus until complete, then reading every page of DescribeStackResourceDrifts). It prints modified resources with their property differences, deleted resources, and the per-stack and overall drift counts on standard error; --verbose also shows in-sync resources, unchecked resources (template resources with no drift record or UNKNOWN status), and detection progress; --quiet omits clean stacks; --json writes one structured object per stack to standard output. As in the CDK, the command exits 0 even when drift is found unless --fail is passed, in which case any MODIFIED or DELETED resource exits 1 (UNKNOWN and unchecked resources do not fail it). Stack selection matches deploy and diff (--all, -e/--exclusively).

bundle exec ruby-cdk destroy prints what the stack retains, then asks you to type the stack's name — a yes/no is not enough for an irreversible act — and deletes it. --yes skips the question; a termination-protected stack is refused.

Bring existing resources in. bundle exec ruby-cdk import STACK adopts resources that already exist in AWS into the stack, the CDK's cdk import. The command synthesizes the app, compares the template against the one CloudFormation holds, and the resources the stack does not have yet are the candidates. Each one is asked for the properties that identify it — a queue's QueueName, a table's TableName, a Route53 key-signing key's HostedZoneId and Name together — as a yes/no when the template already spells the value out, otherwise one line to type. When the template also holds updates or deletes, the command shows them and asks before importing; --force imports anyway. For scripts, the questions have a file form:

bundle exec ruby-cdk import my-app --resource-mapping mapping.json
# mapping.json: { "MyQueue": { "QueueName": "my-existing-queue" } }

--resource-mapping-inline '{"MyQueue":{"QueueName":"my-existing-queue"}}' is the same on the command line, and --record-resource-mapping PATH writes what was collected instead of importing. The import itself is one CloudFormation change set of type IMPORT: its template is the deployed one with the additions in it, every imported resource kept (DeletionPolicy: Retain) so a failed operation loses nothing, executed after the same approval question a deploy asks (--yes answers it) and followed to the end like a deploy. Without a terminal, a mapping is required. After an import that left pending updates behind, the command offers to finish with a ruby-cdk deploy — the import puts the resources under the stack as they are today, and the deploy brings the rest of the template in line.

examples/hello is this same app kept by hand, with more commentary on what each line does, and the generated project's README carries the three commands with the notes a first deploy needs: where a stack without an env deploys, what deploy asks, and that an asset (asset.zip) needs a pinned env, because the bucket its zip lands in is named after the account and the region and synthesis never calls AWS to discover them.

Validation before deploy

Mistakes are caught while synthesizing, not by CloudFormation after. The normalizer resolves every key against the model AWS publishes, so both spellings work:

resource("Queue", "AWS::SQS::Queue", properties: {
  queue_name: "todo",          # -> "QueueName"
  visibility_timeout: 300      # -> "VisibilityTimeout"
})

A key that matches nothing is an error with the closest names as suggestions — visibilty_timeout answers "did you mean VisibilityTimeout?" — and an ambiguous one lists every candidate. On top of the normalizer run rules V1–V23: unknown types and logical IDs (V1–V2), property names, required properties and literal kinds (V3–V7), intrinsics — Ref, GetAtt, Sub — checked against the stack (V8–V11), quotas and stack names (V12–V13), circular dependencies (V14), a warning on a stateful type deleted outright (V15), deletion and replacement policies (V16), strings standing where numbers or booleans belong (V17), allowed values and patterns (V18–V19), and the malformed templates CloudFormation itself refuses (V20–V23). The rules pass over a committed sample of 400 templates the CDK has synthesized — real templates CloudFormation accepted — with no exception on file.

ruby-cdk validate runs the same rules without writing anything:

$ ruby-cdk validate
typo
  V3 Resources.Queue.Properties.visibilty_timeout: "visibilty_timeout" is not a property of AWS::SQS::Queue; did you mean VisibilityTimeout?
    write the CloudFormation name, or in snake_case: visibility_timeout
typo: 1 error(s), 0 warning(s)

Exit 0 when every selected stack is clean of errors, 2 otherwise; warnings are reported but not fatal. An unknown resource type (V1) is a warning that leaves the resource's keys as written, so Custom::* and registry types work.

--strict-types re-registers the rules so that V1 reports an error instead of a warning. The run keeps validate's contract: exit 0 when nothing is found, exit 2 with the first error printed.

Assets

examples/lambda shows a file asset: a directory walked, hashed and zipped at deploy, in the shape of the CDK's file-asset scenario. The function's Code is the asset's S3 location:

function = resource("Function", "AWS::Lambda::Function", depends_on: [ log_group ], properties: {
  "Code" => asset.zip(__dir__.to_s, exclude: [ "stack.rb" ]).s3_location,
  ...
})

Synthesizing that example puts, in the template:

"Code": {
  "S3Bucket": "ruby-cdk-assets-111122223333-eu-central-1",
  "S3Key": "3479630be1c6bd65929a6623ef407d0b1af8364fd29e2e93801094d0f6db1207.zip"
}

The key is the asset's hash, and the hash is the SHA-256 of a manifest — one <mode> <relative path> <content hash> line per file, sorted by path, with only 0644 and 0755 as modes and no timestamps. The same files give the same hash on every machine, and one byte of one file gives a new one: editing the example's app.rb by a single character moves the key from 3479630b…07.zip to a735bc12…64.zip, and the next deploy uploads the new object and points Code at it. exclude: takes plain globs; .git, .DS_Store and *.log are excluded by default. An asset needs a concrete env — the bucket's name is made of the account and the region, and synthesis never calls AWS to discover them — and belongs to the stack that declared it.

The bucket comes from ruby-cdk bootstrap, which deploys a stack named ruby-cdk-bootstrap holding ruby-cdk-assets-<account>-<region>: versioning, encryption at rest, public access blocked, a deny-without-TLS bucket policy, read granted to the principal named with --deployer ARN (the caller's own by default), and the bucket retained when the stack is deleted. A stack without assets deploys into an account that was never bootstrapped. Templates above 51,200 bytes go into the same bucket and deploy by URL.

Testing your infrastructure

RubyCdk::Test is the CDK's assertions module, ported: the same method names, snake_cased. A stack's template in a plain Minitest:

# test/my_app_stack_test.rb — beside the scaffold's files
require "minitest/autorun"
require "ruby-cdk"
require "ruby_cdk/test"

require_relative "my_app/my_app_stack"

class MyAppStackTest < Minitest::Test
  def test_the_bucket_stays_private_and_is_encrypted
    stack = MyApp::Stack.new(RubyCdk::App.new, "my-app")
    template = RubyCdk::Test.template(stack)

    template.resource_count_is("AWS::S3::Bucket", 1)
    template.has_resource_properties("AWS::S3::Bucket", {
      "BucketEncryption" => {
        "ServerSideEncryptionConfiguration" => [
          { "ServerSideEncryptionByDefault" => RubyCdk::Test.object_like("SSEAlgorithm" => "AES256") }
        ]
      },
      "PublicAccessBlockConfiguration" => RubyCdk::Test.object_equals(
        "BlockPublicAcls" => true,
        "BlockPublicPolicy" => true,
        "IgnorePublicAcls" => true,
        "RestrictPublicBuckets" => true
      )
    })
    template.has_resource("AWS::S3::Bucket",
      "DeletionPolicy" => "RetainExceptOnCreate",
      "UpdateReplacePolicy" => "Retain")
    template.has_parameter("Versioning", "Type" => "String", "Default" => "Suspended")
    template.template_matches("Parameters" => RubyCdk::Test.any_value)
    assert_equal "RetainExceptOnCreate",
      template.get("Resources.Bucket.DeletionPolicy").as_string
  end
end

That test runs:

1 runs, 1 assertions, 0 failures, 0 errors, 0 skips

template(source) takes a stack (anything with to_template), a Hash, or a JSON string; from_string and from_json are there too. The assert methods — resource_count_is, has_resource_properties, has_resource, all_resources, template_matches, has_parameter, has_output, has_condition, has_mapping, and the find_* pair for each — raise RubyCdk::Test::AssertionError when they fail, which is a Minitest::Assertion in a Minitest run (require minitest/autorun before ruby_cdk/test). The matchers are the CDK's: object_like, object_equals, array_with, array_equals, exact, not_, any_value, absent, string_like_regexp, serialized_json. template.get(path) reads one value at a dotted path through the typed captures (as_string, as_number, as_array, and the rest), which the CDK's module does not have and a Ruby test with no jest snapshots wants.

Security defaults

  • Change sets by default. A deploy is a change set you are shown before it executes (lib/ruby_cdk/deploy/deployer.rb). The one way around it is the explicit --hotswap pair ("The hotswap fast path" above), which applies a Lambda function's code and in-place configuration with one direct UpdateStack after the same approval question, under the CDK's drift warning. A failed first deploy passes OnStackFailure: DELETE, and a refused creation deletes the stack it created, so nothing half-made is left behind.
  • Stateful types are retained, not deleted. The types the CDK retains — S3 buckets, DynamoDB tables, log groups, KMS keys, and the rest of its list — get DeletionPolicy: RetainExceptOnCreate and UpdateReplacePolicy: Retain from the first synth; RDS instances and clusters get Snapshot. RetainExceptOnCreate rather than Retain, so a creation that rolls back leaves no orphan behind; every change set also executes with RetainExceptOnCreate: true, which protects plain-Retain templates too (lib/ruby_cdk/core/stateful.rb).
  • The account rule. A stack with an env deploys and is destroyed only into that account — the command resolves who it is with STS and refuses on a mismatch. A stack without one goes wherever the credentials point, with the target printed first; an unattended deploy (--yes) of such a stack refuses without --account ID naming it (lib/ruby_cdk/deploy/deployer.rb).
  • The asset bucket's owner is checked on every call. HeadBucket, HeadObject and PutObject all carry expected_bucket_owner; a bucket that exists and is not yours stops the deploy before anything is uploaded (lib/ruby_cdk/assets/uploader.rb).
  • Nothing executes without approval. The change view is printed, then the question; --yes must be exactly true; without a terminal the command refuses at the question and leaves nothing deployed. destroy asks for the stack's name to be typed, not for a yes (lib/ruby_cdk/deploy/ports.rb).

Requirements

  • Ruby 4.0 or newer. The gemspec refuses older (required_ruby_version ">= 4.0.0").
  • AWS credentials reachable through the SDK's standard chain — environment, shared files, SSO — narrowed by --profile. Nothing is stored, nothing is logged, and synthesis never calls AWS.
  • The six runtime gems (aws-sdk-cloudformation, aws-sdk-s3, aws-sdk-ec2, aws-sdk-ssm, thor, rubyzip) install with the gem; the EC2 and SSM ones are loaded only by ruby-cdk lookup. No Node, no build tools, no native extensions.

Status

Works today:

  • ruby-cdk synth, validate, ls, diff, drift, deploy, destroy, import, watch, new, bootstrap, lookup (ruby-cdk help COMMAND for each). new PROJECT scaffolds an app: cdk.rb, one stack with one private bucket, a Gemfile, .gitattributes and .gitignore.
  • Schema-backed synthesis with the normalizer and rules V1–V23.
  • File assets with content hashing, zipping at deploy, and the bootstrap bucket; templates above 51,200 bytes deploy by URL.
  • The nag rule pack — seventeen security rules over every example's synthesized template, run with rake nag, suppressed per resource or in .ruby-cdk/nag.yml.
  • The test kit, RubyCdk::Test, with the CDK's assertions ported.
  • Two scenarios run end to end in CI against the AWS Emulator, which answers as CloudFormation does (rake integration), and the same two against the real sandbox before a release: a stack created, updated through a change set, deployed again with nothing changed and destroyed; and a Lambda function whose code is a zipped asset, bootstrapped, created, updated through --hotswap, left untouched by --hotswap when a change is refused, updated through --hotswap-fallback, and destroyed.
  • Curated constructs — S3::Bucket, IAM::Role, Lambda::Function, DynamoDB::Table, SQS::Queue, SNS::Topic, Logs::LogGroup, SSM::Parameter, a SecretsManager::Secret reference, Events::Rule, ApiGateway::RestApi, KMS::Key, EC2::Vpc — with explicit grants, and ruby-cdk diff against the deployed template. KMS::Key brings customer-managed encryption to the bucket (encryption: :kms, encryption_key:), the queue (encryption:, encryption_master_key:), the topic (master_key:) and the table (encryption:, encryption_key:), with the grants on the key the CDK's own grants add. EC2::Vpc is the CDK's defaults: the VPC, the Internet Gateway and its attachment, the public and private subnets per availability zone with their route tables and routes, and a NAT Gateway and EIP per zone — max_azs:, availability_zones:, subnet_configuration: (name, subnet_type, cidr_mask, reserved), nat_gateways:, nat_gateway_subnets:, cidr:, dns_support:, dns_hostnames: — with the subnet ids and the zone names on the construct. Route53::HostedZone is the CDK's hosted zone: the zone name validated and given the trailing dot (add_trailing_dot: keeps it off), comment:, query_logs_log_group_arn:, and vpcs: for a private zone — each entry a Vpc, a { vpc_id:, region: } Hash or a bare id — with the zone id, ARN and name on the construct, and the CDK's record sets beside it: RecordSet and the A, AAAA, CNAME, TXT, SRV, CAA, Amazon CAA, MX and NS records, built with the zone as their scope, the record name qualified against the zone name and the CDK's 1800-second default ttl. Route53::HostedZone.from_hosted_zone_attributes(zone_id:, zone_name:) imports a zone by attributes — no resources, the shape the hosted-zone lookup will one day fill.
  • Lookups of existing resources on one machinery, the CDK's context providers as decision D-022 shapes them: EC2::Vpc.from_lookup(stack, "Net", vpc_id: "vpc-…") (optionally tags:) reads its answer from cdk.context.json beside the app file — the VPC's id and CIDR, the zone names, and the subnet ids grouped by reachability type, as literals: a looked-up VPC synthesizes no resources, and what consumes it writes the ids directly. The second provider reads an SSM parameter: SSM::Parameter.from_lookup(stack, "Pwd", name: "/app/db-…") answers the value, the type as AWS reads it (String, StringList), and the parameter's name, as literals — a looked-up parameter synthesizes no resource, and what consumes it writes the value directly; a SecureString is refused (read without decryption, as the CDK's provider reads it, the answer is a per-call KMS ciphertext), and the dynamic reference {{resolve:ssm-secure:…}} reads one at deploy time. On a cache miss, synthesis refuses with the command to run; ruby-cdk lookup performs the queries through the EC2 API (one VPC, or a tags-only query that must match exactly one VPC) and the SSM API (get_parameter) for the stack's account and region, writes the answers into cdk.context.json, and synthesizes again. The file is part of the app: commit it, so two machines read the same answers and synthesize the same template. An entry is keyed by its environment, and a lookup never reads one written for another account or region.
  • Two examples that put the constructs in one stack: examples/app — a function, a table, a bucket and one least-privilege role for them all — and examples/api — a function behind a REST API and a scheduled rule, with the queue, topic and parameter grants and the two Lambda permissions a service principal needs to call a function itself. Both are under the determinism and nag gates.

Next: the hosted-zone lookup on the same lookup machinery, and the context commands of the CDK's cdk context. deploy --hotswap is there (see "The hotswap fast path" above).

And the honest part: this is 0.1.0. The APIs — Stack, App, Test, the constructs, the CLI options — may still change between versions. Pin the version you build against.

Development

git clone https://github.com/a-safe-digital/ruby-cdk.git
cd ruby-cdk
bundle install
bundle exec rake        # everything that must pass before a commit

The default gate is an explicit list: test, rubocop, typecheck (Sorbet), coverage:check (floor 85%), determinism, parity, nag, purity. It never touches the network and never calls AWS. rake -T lists the rest — rake mutation, and the network tasks spec:update and corpus:update, which CI runs weekly and everyone else runs by hand, on purpose.

The tests: test/unit/ for each component alone, test/cdk/ for the CDK's suites ported (every file's header names the origin path, commit and licence), test/architecture/ for the component map — the set of components and their dependencies, enforced by a test so no shortcut crosses a boundary — and test/integration/, of which only the in-process part runs in the gate. The design documents under docs/ are not part of a fresh clone: the owner keeps them local (decision D-025), so the code comments and this README are the public record.

Rules for contributors and for coding agents are in CLAUDE.md.

License

MIT