Overview
The FjallVpc construct extends the AWS CDK ec2.Vpc with sensible defaults for network isolation. It creates public and private subnets across multiple availability zones, configures NAT gateways, enables flow logs, allocates IP ranges from IPAM, and provisions VPC endpoints, all through one set of Fjall props.
Because Vpc extends ec2.Vpc, every standard CDK VPC property remains available alongside the Fjall additions.
Import
Basic Usage
Configuration Options
Core Properties
natGatewayConfig resolves to a NAT gateway count: an object uses count (default 1), and false disables NAT gateways. The raw CDK natGateways number remains available as an ec2.VpcProps pass-through, but prefer natGatewayConfig so the construct can apply its own resolution.
Flow Log Properties
IPAM Properties
VPC Endpoint Properties
Additional Properties
All standard CDKec2.VpcProps are supported through the extending class, including subnetConfiguration, ipAddresses, and natGatewayProvider.
Default Configuration
With no props, the construct creates:- 3 availability zones for high availability
- Public and private-with-egress subnets, one of each per AZ
- An internet gateway plus NAT gateways per the CDK default
- Gateway endpoints for S3 and DynamoDB
accountId (and ipv4IpamPoolId for IPAM).
NAT Gateway Configuration
PRIVATE_ISOLATED subnets so private workloads can still reach AWS services.
Flow Logs
Flow logs turn on automatically onceaccountId is set. They write to a CloudWatch log group at /vpc/flowlogs/vpc-${id}/.
flowLogConfig: false to disable flow logs even when accountId is present.
IPAM Integration
When you supply bothaccountId and ipv4IpamPoolId, the construct allocates the VPC CIDR from your IPAM pool.
/20 VPC CIDR and /23 subnet masks. Override them with vpcCidrMask and subnetCidrMask.
VPC Endpoints
Gateway endpoints (S3, DynamoDB) are on by default. Request interface endpoints individually.ecr, secretsManager, kms, cloudwatchLogs, ssm, sts. Enabling ecr provisions both the ECR API and ECR Docker endpoints. Enabling ssm provisions SSM, SSM Messages, and EC2 Messages.
Custom Subnets
Pass standard CDKsubnetConfiguration for a multi-tier layout.
Factory and StackBuilder Patterns
Network Factory
The canonical way to add a VPC inside a Fjall app isNetworkFactory.build passed to app.addNetwork. The factory wires account, region, and IPAM context automatically.
NetworkFactory props use natGateways, flowLogs, vpcEndpoints, and subnets, which it maps onto the construct’s natGatewayConfig, flowLogConfig, and endpointsConfig. See the Network Factory pattern for the full prop reference.
StackBuilder
Import an Existing VPC
Static Helpers
The construct exposes the helpers it uses internally, so you can compute the same values in custom code.Complete Example
Cost Considerations
Troubleshooting
Next Steps
Network Factory
Compose VPCs declaratively with NetworkFactory props.
Security Group
Control inbound and outbound traffic for VPC resources.
ECS Cluster
Run containers inside your VPC’s private subnets.
RDS Aurora
Deploy a managed database into VPC subnets.