Quickstart For CDK And CDKTF Users
Use App, Stack, and reusable Python constructs to model a VPC and bucket. Netherframe
uses generated Terraform provider bindings for resource classes, and nf calls the provider
directly in hybrid execution. A saved plan covers the whole app, and the app's backend stores state.
1. Install The AWS Binding Package
Set up Python 3.15 or later and the CLI in your project. See installation. For a source checkout, see AWS binding installation.
uv add netherframe.providers.hashicorp.aws
pip install netherframe.providers.hashicorp.aws
2. Configure A Tiny App
Add these settings to pyproject.toml.
[tool.nf]
apps = ["app:app"]
3. Write A Small Construct-Flavored Stack
Create app.py:
# coding: nf_autoid
from nf.core import App, Bind, BindContext, Construct, Output, Stack, autoscope
from nf.providers.hashicorp.aws import AwsProvider, S3Bucket, Vpc
class Network(Construct):
def __init__(self, *, nf_scope: Construct | None = None, nf_id: str | None = None, cidr: str) -> None:
super().__init__(nf_scope=nf_scope, nf_id=nf_id)
self.vpc: Bind[Vpc] = Vpc(
cidr_block=cidr,
enable_dns_support=True,
enable_dns_hostnames=True,
tags={"Name": "cdk-style-vpc"},
)
@autoscope
class PlatformStack(Stack):
def __init__(self, *, nf_scope: App | None = None, nf_id: str | None = None) -> None:
super().__init__(nf_scope=nf_scope, nf_id=nf_id)
aws: Bind = AwsProvider(region="us-east-1")
self.network: Bind[Network] = Network(cidr="10.55.0.0/16")
self.bucket = S3Bucket(
nf_id="assets",
bucket="replace-with-a-globally-unique-name",
force_destroy=True,
tags={"Name": "cdk-style-assets"},
)
bucket_id: Bind = Output(value=self.bucket.output.id)
vpc_id: Bind = Output(value=self.network.vpc.output.id)
def app() -> App:
with App() as app, BindContext:
platform: Bind = PlatformStack()
app.enable_hybrid_execution_local(path=".nf.out/hybrid.tfstate")
return app
@autoscope makes PlatformStack the current scope while its constructor runs.
Network groups the Python code for the VPC, and the VPC belongs to that active stack.
4. Review a plan
Configure AWS credentials and choose a globally unique bucket name. Keep the project's Python environment active.
nf plan --app app --out reviewed-plan.json
The plan should show the VPC and bucket in the platform stack.
5. Apply and clean up
nf apply --app app --plan-file reviewed-plan.json
nf plan --app app
nf destroy --app app
The second plan should report no changes. Run destroy when you’re done with the example.
What To Watch For As You Translate CDK Habits
Construct Tree Expectations
If you are used to deep construct trees, keep the surface simpler at first:
- start with one
App - add one or two explicit
Stackclasses - use a small
Constructonly where it clarifies composition - keep ids intentional
The example above does exactly that: one small reusable Network construct inside one deployable stack.
Resource Authoring Style
The generated provider package exposes typed AWS constructs such as:
AwsProviderVpcS3BucketInstanceSecurityGroup
Deployment Boundary
Use stacks to group related resources. The --app app commands plan and apply the
whole app, including every stack it contains.
Recommended First Moves
- Get a plan for an app with one stack.
- Review it and apply it in the intended account.
- Extract shared resource definitions into reusable classes as the app grows.
If you later need unattended deploys, nf deploy --auto-approve is available, but it is better kept for CI or other advanced workflows.
Next Steps
- Quickstart For Developers
- Building Your First Application
- Custom Codec And Autoscope explains these bindings and scopes.
- Hybrid Execution