CDK UtilsA comprehensive toolkit for provisioning cloud infrastructure using AWS CDK and Pulumi. This monorepo provides high-level constructs, service managers, and common utilities that simplify infrastructure-as-code across AWS, Azure, and Cloudflare.
For more details, see the full API documentation.
Install the umbrella package:
pnpm add @gradientedge/cdk-utils
Or install individual packages as needed:
pnpm add @gradientedge/cdk-utils-aws
pnpm add @gradientedge/cdk-utils-azure
pnpm add @gradientedge/cdk-utils-cloudflare
pnpm add @gradientedge/cdk-utils-common
import { CommonConstruct, CommonStackProps } from '@gradientedge/cdk-utils-aws'
import { Construct } from 'constructs'
class MyStack extends CommonConstruct {
constructor(parent: Construct, id: string, props: CommonStackProps) {
super(parent, id, props)
this.initResources()
}
protected initResources() {
this.lambdaManager.createLambdaFunction('MyFunction', this, functionProps)
this.s3Manager.createBucket('MyBucket', this, bucketProps)
}
}
import { CommonAzureConstruct } from '@gradientedge/cdk-utils-azure'
import * as pulumi from '@pulumi/pulumi'
class MyAzureStack extends CommonAzureConstruct {
constructor(name: string, args: any, opts?: pulumi.ComponentResourceOptions) {
super(name, args, opts)
this.initResources()
}
}
import { CommonCloudflareConstruct } from '@gradientedge/cdk-utils-cloudflare'
import * as pulumi from '@pulumi/pulumi'
class MyCloudflareStack extends CommonCloudflareConstruct {
constructor(name: string, args: any, opts?: pulumi.ComponentResourceOptions) {
super(name, args, opts)
this.initResources()
}
}
CloudflareWorkerSite reads the base wrangler.jsonc from siteWranglerConfig (or siteSource).
Its assets.directory is resolved relative to that configuration file. When present, _headers
and _redirects in that directory are read as UTF-8 and passed to Pulumi as
assets.config.headers and assets.config.redirects. Missing rule files are optional; errors
reading existing files fail provisioning. Ensure the asset build/copy step finishes before
running Pulumi so these files are available.
By default, _headers, _redirects and .assetsignore at the root of the asset directory are
not uploaded as assets, so they can't be requested as static files. The Pulumi provider uploads
every file in assets.directory, so matching assets are copied to a staging directory under the
system temporary directory and excluded from the copy. Its path depends on the asset directory, the
worker script name and the staged contents, so it stays the same between deployments while the assets
don't change. A staged copy is never changed or removed once it's in place, so runs that stage the
same worker at the same time (e.g. parallel tests or deployments on one machine) don't interfere, and
a worker's copies are removed a day after they were last used. Set workerAssetsExcludes on
CloudflareWorkerSiteProps to customize the excluded paths; it defaults to
['_headers', '_redirects', '.assetsignore']. Files and directories matching the gitignore-style
patterns listed in .assetsignore are also left out, matched the same way as Wrangler; an
.assetsignore file that isn't UTF-8 or contains a null character fails provisioning.
cache.enabled and cache.cross_version_cache become the script's cacheOptions. Entries of
type worker in the exports map (default is the default export) are passed as the script's
exports, so each entrypoint keeps its own cache.enabled override, for example an uncached
gateway in front of a cached named entrypoint. Other exports entries, such as Durable Object
classes, are skipped: the script resource can't declare their storage, so declare Durable Objects
with migrations, which Cloudflare accepts alongside worker entries. When the configuration has
no worker entries, siteWorkerScript.exports is used.
pnpm install
pnpm build
Run the full test suite:
pnpm test
Watch mode for a specific test:
pnpm test:watch static-asset-deployment-distribution-ref.test.ts
Run prettier, linting, and tests:
pnpm validate
pnpm run docs
There are common utilities that help with testing constructs in the test tools directory. A debug utility is also available for printing template contents during development.
See CONTRIBUTING.md for guidelines on how to contribute to this project.
This project is licensed under the MIT License — see the LICENSE file for details.