Overview
The FjallVpc construct extends the AWS CDK ec2.Vpc with defaults for network isolation. It creates public and private subnets across multiple availability zones, resolves NAT gateway count, configures flow logs, allocates IP ranges from IPAM, and provisions VPC endpoints, all through one set of Fjall props.
Vpc extends ec2.Vpc, so most standard CDK VPC properties remain available. Five of them are owned by the construct and are overridden if you set them. See Props the construct owns.
Import
Basic Usage
Configuration Options
Core Properties
natGatewayConfig resolves to a NAT gateway count: an object uses count (default 1), and false resolves to 0. Omitting it leaves the count unset, so CDK’s default of one NAT gateway per availability zone applies.
Props the construct owns
These props are set by the constructor after your props are spread, so a value you pass is silently discarded. Configure the Fjall equivalent instead.
Every other
ec2.VpcProps passes through, including subnetConfiguration, natGatewayProvider, enableDnsHostnames, and enableDnsSupport.
Flow Log Properties
retentionDays means two different things:
- CloudWatch destination: log group retention. The value is rounded up to the nearest valid CloudWatch retention (1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, and longer).
- S3 destination: an S3 lifecycle expiration rule. Objects are deleted permanently after that many days, and noncurrent versions after 30 days. Omit it and no expiry rule is written.
Addressing and Account Properties
IPAM does not depend on
accountId. A non-empty ipv4IpamPoolId is the sole
signal of IPAM intent, so an IPAM-backed VPC still allocates correctly when
the ambient account id fails to resolve.VPC Endpoint Properties
Default Configuration
With no props, the construct creates:- 3 availability zones, the first three in the stack’s region
- Public and private-with-egress subnets, one of each per AZ
- An internet gateway plus CDK’s default of one NAT gateway per AZ
- Gateway endpoints for S3 and DynamoDB
flowLogConfig or set accountId. IPAM allocation activates when you pass a non-empty ipv4IpamPoolId.
The construct also emits a VpcCidrBlock output exported as <stack-name><id>-vpc-cidr. The Fjall webapp reads that export to record a linked application’s CIDR, so leave the suffix intact.
NAT Gateway Configuration
PRIVATE_ISOLATED subnets so private workloads can still reach AWS services. With NAT gateways present, they go in PRIVATE_WITH_EGRESS subnets.
Flow Logs
Flow logs turn on in two ways: pass aflowLogConfig object, or set accountId and let the default path run. Both write to a CloudWatch log group at /vpc/flowlogs/vpc-${id}/ with a DESTROY removal policy, so the group is deleted with the stack.
vpc-flowlogs-<lowercased-id>-<account-id>. Set flowLogConfig: false to disable flow logs even when accountId is present.
IPAM Integration
Supply a non-emptyipv4IpamPoolId and 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. Every interface endpoint is created with private DNS enabled.
Custom Subnets
Pass standard CDKsubnetConfiguration for a multi-tier layout. It is a pass-through prop, so your value is used as written.
Factory and StackBuilder Patterns
Network Factory
The canonical way to add a VPC inside a Fjall application isNetworkFactory.build passed to app.addNetwork. The factory reads account, region, and IPAM pool id from CDK context and passes them to the construct.
NetworkFactory props use natGateways, flowLogs, vpcEndpoints, cidrMask, and subnets, which it maps onto the construct’s natGatewayConfig, flowLogConfig, endpointsConfig, vpcCidrMask, and subnetCidrMask. The factory does not accept subnetConfiguration, so build the construct directly for a custom subnet layout. See the Network Factory pattern for the full prop reference.
StackBuilder
Import an Existing VPC
Vpc.import resolves an existing VPC through ec2.Vpc.fromLookup, matching the Name tag <stack-name>/<id>.
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.