
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@codedrifters/constructs
Advanced tools
A collection of reusable AWS CDK constructs frequently used in CodeDrifters projects. This package provides pre-configured, secure, and production-ready constructs for common AWS infrastructure patterns.
AWS CDK (Cloud Development Kit) constructs are reusable cloud components that encapsulate AWS resources and their configuration. Think of them as building blocks that combine multiple AWS services into higher-level abstractions.
For example, instead of manually configuring an S3 bucket, CloudFront distribution, Route53 records, and SSL certificates separately, a construct can combine all of these into a single "StaticHosting" construct that you can use with just a few lines of code.
Key Benefits:
For more information about AWS CDK constructs, see the AWS CDK Developer Guide.
Add the package to your CDK project using Configulator/Projen configuration. This ensures consistent dependency management across your project.
Note: Always configure dependencies through Projen configuration files, never by manually running
npm install,pnpm add, oryarn add. Manual installation will create conflicts with Projen-managed files.
If you're using @codedrifters/configulator in a monorepo, add the package as a dependency in your sub-project configuration:
import { TypeScriptProject } from '@codedrifters/configulator';
import { MonorepoProject } from '@codedrifters/configulator';
const myCdkProject = new TypeScriptProject({
name: 'my-cdk-project',
packageName: '@myorg/my-cdk-project',
outdir: 'packages/my-cdk-project',
parent: root, // Your MonorepoProject instance
deps: [
'@codedrifters/constructs',
],
devDeps: [
'aws-cdk-lib@catalog:', // Catalog versions are pre-configured
'constructs@catalog:',
],
});
If you're using AWS CDK directly (not via Configulator), add the package to your deps array:
import { awscdk } from 'projen';
const project = new awscdk.AwsCdkTypeScriptApp({
name: 'my-cdk-app',
deps: [
'@codedrifters/constructs',
],
devDeps: [
'aws-cdk-lib',
'constructs',
],
});
After updating your projenrc configuration file, run:
npx projen
This will update your package.json and install the dependencies.
This package requires the following peer dependencies:
aws-cdk-lib - AWS CDK construct libraryconstructs - Core constructs libraryThese should be added as dev dependencies in your project configuration. If you're using @codedrifters/configulator, the catalog versions (@catalog:) are automatically configured in the root MonorepoProject.
A secure S3 bucket with sensible security defaults. This construct extends AWS CDK's Bucket construct with security best practices applied by default.
Security Defaults:
BlockPublicAccess.BLOCK_ALL)RETAIN)Basic Usage:
import { PrivateBucket } from '@codedrifters/constructs';
import { Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
const stack = new Stack(app, 'MyStack');
// Create a private bucket with default security settings
const bucket = new PrivateBucket(stack, 'MyPrivateBucket');
With Custom Properties:
import { RemovalPolicy } from 'aws-cdk-lib';
import { PrivateBucket } from '@codedrifters/constructs';
const bucket = new PrivateBucket(stack, 'MyPrivateBucket', {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
versioned: true,
});
Note: The security settings (public access blocked, SSL enforced, etc.) cannot be overridden - they are always applied to ensure bucket security.
A complete static website hosting solution that creates and configures:
PrivateBucket)Features:
StaticContentBasic Usage (CloudFront Domain Only):
import { StaticHosting } from '@codedrifters/constructs';
import { Stack } from 'aws-cdk-lib';
const hostingStack = new Stack(app, 'HostingStack', { env });
const hosting = new StaticHosting(hostingStack, 'static-hosting', {
description: 'My static website',
});
With Custom Domain:
import { StaticHosting } from '@codedrifters/constructs';
import { Stack, RemovalPolicy } from 'aws-cdk-lib';
const hostingStack = new Stack(app, 'HostingStack', { env });
const hosting = new StaticHosting(hostingStack, 'static-hosting', {
description: 'My static website',
staticDomainProps: {
baseDomain: 'example.com',
hostedZoneAttributes: {
hostedZoneId: 'Z1234567890ABC',
zoneName: 'example.com',
},
},
privateBucketProps: {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
},
});
Properties:
| Property | Type | Default | Description |
|---|---|---|---|
description | string | undefined | Short description for traceability |
staticDomainProps | StaticDomainProps | undefined | Domain configuration (optional) |
bucketArnParamName | string | "/STATIC_WEBSITE/BUCKET_ARN" | SSM parameter name for bucket ARN |
distributionDomainParamName | string | "/STATIC_WEBSITE/DISTRIBUTION_DOMAIN" | SSM parameter name for distribution domain |
distributionIDParamName | string | "/STATIC_WEBSITE/DISTRIBUTION_ID" | SSM parameter name for distribution ID |
privateBucketProps | PrivateBucketProps | undefined | Props to pass to the S3 bucket |
StaticDomainProps:
| Property | Type | Description |
|---|---|---|
baseDomain | string | The base domain (e.g., example.com) |
hostedZoneAttributes | HostedZoneAttributes | Hosted zone ID and zone name |
Outputs:
The construct exposes:
fullDomain: string - The full domain name (custom domain if provided, otherwise CloudFront domain)SSM Parameters Created:
The construct automatically creates SSM parameters that can be referenced by StaticContent:
/STATIC_WEBSITE/BUCKET_ARN)/STATIC_WEBSITE/DISTRIBUTION_DOMAIN)/STATIC_WEBSITE/DISTRIBUTION_ID)Deploys static content from a local directory to an S3 bucket. This construct is designed to work with StaticHosting and supports branch-based deployment paths for PR and feature branch previews.
Features:
feature-123.example.com/)How Branch-Based Deployment Works:
The construct uses the current git branch name to create unique deployment paths. This allows multiple branches to deploy to the same bucket without conflicts:
S3 Bucket Structure:
├── example.com/ → Production/main branch
├── feature-123.example.com/ → Feature branch
├── pr-456.example.com/ → Pull request
└── stage.example.com/ → Staging branch
Basic Usage:
import { StaticContent, StaticHosting } from '@codedrifters/constructs';
import { Stack } from 'aws-cdk-lib';
// First, create the hosting infrastructure
const hostingStack = new Stack(app, 'HostingStack', { env });
const hosting = new StaticHosting(hostingStack, 'static-hosting', {
staticDomainProps: {
baseDomain: 'example.com',
hostedZoneAttributes: {
hostedZoneId: 'Z1234567890ABC',
zoneName: 'example.com',
},
},
});
// Then, deploy content in a separate stack
const contentStack = new Stack(app, 'ContentStack', { env });
contentStack.node.addDependency(hostingStack);
new StaticContent(contentStack, 'static-content', {
contentSourceDirectory: 'dist', // Local directory with built files
contentDestinationDirectory: '/', // Deploy to root of bucket path
fullDomain: hosting.fullDomain, // Use domain from StaticHosting
});
With Custom Subdomain:
new StaticContent(contentStack, 'static-content', {
contentSourceDirectory: 'dist',
contentDestinationDirectory: '/',
fullDomain: hosting.fullDomain,
subDomain: 'staging', // Override git branch detection
bucketArnParamName: '/STATIC_WEBSITE/BUCKET_ARN', // Custom param name
});
Properties:
| Property | Type | Default | Description |
|---|---|---|---|
contentSourceDirectory | string | Required | Absolute path to directory containing files to deploy |
contentDestinationDirectory | string | Required | Directory within bucket to place content (should start with /) |
fullDomain | string | Required | Full domain name (from StaticHosting.fullDomain) |
subDomain | string | Git branch name | Subdomain prefix (defaults to current git branch) |
bucketArnParamName | string | "/STATIC_WEBSITE/BUCKET_ARN" | SSM parameter name for bucket ARN |
Path Construction:
The construct creates a unique path prefix using: {subDomain}.{fullDomain}
For example:
feature-123, Domain: example.com → Path: feature-123.example.com/main, Domain: example.com → Path: main.example.com/ (or just example.com/ if subdomain is empty)Here's a complete example showing how to use StaticHosting and StaticContent together:
import { StaticContent, StaticHosting } from '@codedrifters/constructs';
import { App, RemovalPolicy, Stack } from 'aws-cdk-lib';
const app = new App();
const env = {
account: '123456789012',
region: 'us-east-1',
};
const baseDomain = 'example.com';
/*******************************************************************************
*
* Step 1: Create the hosting infrastructure
*
* This creates the S3 bucket, CloudFront distribution, SSL certificate,
* and DNS records.
*
******************************************************************************/
const hostingStack = new Stack(
app,
`static-hosting-dev-${env.account}-${env.region}`,
{ env }
);
const hosting = new StaticHosting(hostingStack, 'static-hosting', {
description: 'My static website',
privateBucketProps: {
removalPolicy: RemovalPolicy.DESTROY,
autoDeleteObjects: true,
},
staticDomainProps: {
baseDomain,
hostedZoneAttributes: {
hostedZoneId: 'Z1234567890ABC',
zoneName: baseDomain,
},
},
});
/*******************************************************************************
*
* Step 2: Deploy static content
*
* This deploys files from a local directory to the S3 bucket created above.
* The content stack must depend on the hosting stack to ensure the bucket
* exists before deployment.
*
******************************************************************************/
const contentStack = new Stack(
app,
`static-content-dev-${env.account}-${env.region}`,
{ env }
);
// Ensure hosting stack is created first
contentStack.node.addDependency(hostingStack);
new StaticContent(contentStack, 'static-content', {
contentSourceDirectory: 'src/website', // Path to your built website files
contentDestinationDirectory: '/', // Deploy to root
fullDomain: hosting.fullDomain, // Use the domain from StaticHosting
});
app.synth();
Deployment Flow:
cdk deploy static-hosting-dev-*cdk deploy static-content-dev-*Branch-Based Deployments:
When deploying from different git branches, the StaticContent construct automatically uses the branch name as a subdomain prefix. This allows you to have:
main branch → example.comfeature-123 branch → feature-123.example.compr-456 branch → pr-456.example.comAll using the same S3 bucket and CloudFront distribution!
The package exports the following:
Constructs:
PrivateBucket - Secure S3 bucketStaticHosting - Complete static hosting solutionStaticContent - Static content deploymentPrivateBucketProps
BucketProps from aws-cdk-lib/aws-s3StaticHostingProps
StackProps from aws-cdk-libStaticContentProps
StaticDomainProps
baseDomain: string - Base domain namehostedZoneAttributes: HostedZoneAttributes - Route53 hosted zone attributesNote: This package is designed for use with AWS CDK v2. Make sure you're using compatible versions of aws-cdk-lib and constructs.
FAQs
Constructs frequently used in CodeDrifter projects.
We found that @codedrifters/constructs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.