Provisioning ML Infrastructure with Infrastructure as Code
This lesson explains how infrastructure as code creates the many resources of an ML system repeatably across accounts and passes their identifiers to the services that use them.
Learning outcomes
After completing this lesson, you will be able to:
- Define resources with CloudFormation and the CDK.
- Share values between stacks and services.
- Provision standardised environments with SageMaker Projects.
CloudFormation and CDK
AWS CloudFormation declares resources in YAML or JSON templates and deploys them as stacks, with change sets to preview updates and automatic rollback on failure. It has resource types for SageMaker AI models, endpoint configurations, endpoints, pipelines, feature groups, model package groups and Bedrock knowledge bases, agents and guardrails. The AWS CDK defines the same resources in Python or TypeScript and synthesizes CloudFormation, which lets teams build reusable constructs such as "a monitored endpoint with alarms".
Communication between stacks and services
Large systems are split into stacks, such as network, data, training and serving. Stacks share values through outputs and exports consumed with Fn::ImportValue, which creates a hard dependency; through nested stacks; or through SSM Parameter Store parameters, which decouple stacks so one can be replaced without blocking the other. Orchestration services consume these values: a Step Functions state machine or SageMaker pipeline receives an execution role ARN, subnet IDs or a model package group name as parameters; EventBridge rules connect stacks through events, such as a model approval starting a deployment.
Connect the stacks
Standardized ML environments
SageMaker Projects use AWS Service Catalog products to provision a complete MLOps setup from a template: code repositories, a model-building pipeline, a Model Registry group and CI/CD pipelines that deploy to staging and production. A data science team starting a new project receives the whole structure in minutes instead of building it by hand.
Platform teams publish approved templates, which encode the organisation's standards for security, networking and deployment, so every team's infrastructure is compliant from the start. The following table summarises the integration methods.
| Method | Coupling | Use when |
|---|---|---|
| Outputs and Fn::ImportValue | Tight (export cannot change while imported) | Stable shared values such as VPC IDs |
| Nested stacks | Parent manages children | Components deployed together |
| SSM Parameter Store | Loose | Values read by stacks, pipelines and code |
| Pipeline or state machine parameters | Runtime | Passing ARNs and names into orchestration |
| SageMaker Projects + Service Catalog | Template | Standard MLOps environments for many teams |
The following diagram shows how values pass between three separate infrastructure stacks, network, serving and training, without tight coupling.

Standard environments
Three stacks
A team splits its ML platform into a network stack, a training stack and a serving stack, deployed per environment.
# network stack (CDK, Python)
ssm.StringParameter(self, "PrivateSubnets", parameter_name="/ml/prod/private-subnets",
string_value=",".join(s.subnet_id for s in vpc.private_subnets))
# serving stack reads the value at deploy time
subnets = ssm.StringParameter.value_for_string_parameter(self, "/ml/prod/private-subnets")
# training pipeline receives values as parameters at run time
pipeline.start(parameters={"SubnetIds": subnets, "ModelPackageGroup": "churn-models"})Parameter Store keeps the stacks loosely coupled, so the network team can update its stack without first removing imports from the ML stacks. Hard-coding subnet IDs in each template would break the moment the network changed.
How can stacks share values loosely, without a hard dependency?
Show answer
Through SSM Parameter Store parameters.
Exam Tips
Remember for the exam
- Repeatable ML infrastructure: CloudFormation or CDK.
- Share values loosely between stacks: SSM Parameter Store.
- Tight sharing of stable values: outputs with Fn::ImportValue.
- Pass ARNs and IDs into Step Functions or SageMaker Pipelines as parameters.
- Standard MLOps templates for many teams: SageMaker Projects with Service Catalog.