Every Stelvio project has a stlv_app.py file at its root - this is the
cornerstone of your infrastructure definition. The CLI automatically looks for
this file in your current directory.
Basic Structure
fromstelvio.appimportStelvioAppfromstelvio.configimportStelvioAppConfig,AwsConfigfromstelvio.aws.dynamo_dbimportDynamoTablefromstelvio.aws.functionimportFunction# Create your app instanceapp=StelvioApp("my-project-name")# Configuration function - runs first@app.configdefconfiguration(env:str)->StelvioAppConfig:returnStelvioAppConfig()# Uses default values/setting# Infrastructure definition - runs after configuration@app.rundefrun()->None:# Create your AWS resources heretable=DynamoTable(name="users",...)fn=Function(handler="functions/users.process",links=[table])
The Two Required Decorators
For Stelvio to load and work properly you need to create StelvioApp object
with app = StelvioApp("some-name") and then create two functions.
One which
will have @app.config decorator and one with @app.run decorator.
@app.config
Purpose: Configures Stelvio for your project and environment
Parameters: env: str - the environment name (e.g., "dev", "staging", "
prod")
Returns: StelvioAppConfig object with AWS settings and other
configuration
Timing: Runs first, before any infrastructure is created
@app.run
Purpose: Defines your infrastructure components
Timing: Runs after configuration is loaded
Requirement: All Stelvio components must be created inside this function (
or in modules when using auto-discovery). See Project Structure for details on component creation order.
Environment-Specific Configuration
You can customize settings based on the environment:
fromstelvio.configimportAwsConfig,StelvioAppConfig@app.configdefconfiguration(env:str)->StelvioAppConfig:ifenv=="prod":# Production uses separate AWS accountreturnStelvioAppConfig(aws=AwsConfig(profile="production-account"),environments=["staging","prod"])# Staging/personal use default accountreturnStelvioAppConfig(environments=["staging","prod"])
StelvioApp Class
The StelvioApp class is the main entry point for your infrastructure
definition and also defines name of your application.
app=StelvioApp("my-project-name")
Note
The app name is used to identify your infrastructure state. Changing it creates new resources rather than renaming existing ones. See State Management - Renaming for details.
Configuration Options
Function marked with @app.config decorator must return StelvioAppConfig object.
It supports several configuration options:
AWS Configuration
Both profile and region are optional overrides. When not specified, Stelvio follows the standard AWS credential and region resolution chain.
Basic Usage
@app.configdefconfiguration(env:str)->StelvioAppConfig:# Same as # StelvioAppConfig(aws=AwsConfig())# Uses standard AWS credential chain described belowreturnStelvioAppConfig()
No AWS configuration needed unless you want to override. This uses the standard AWS resolution order for both credentials and region.
Credential Resolution Order
Stelvio uses boto3 and Pulumi, both following the AWS SDK credential chain:
Explicit profile parameter (override in AwsConfig) - determines which profile's credentials to use
Assume role providers: AWS_ROLE_ARN + AWS_WEB_IDENTITY_TOKEN_FILE (OIDC/web identity), or role assumption configured in ~/.aws/config
AWS IAM Identity Center (SSO): Configured via aws sso login and ~/.aws/config
Shared credentials file: ~/.aws/credentials
Shared config file: ~/.aws/config
IAM role credentials (when running in AWS): ECS task role, EC2 instance profile, Lambda execution role
Region Resolution Order
Explicit region parameter (override in AwsConfig)
AWS_REGION or AWS_DEFAULT_REGION environment variable
Region from selected profile in ~/.aws/config
If none specified, AWS operations will fail
Examples
Use environment variables (CI/CD):
# Set in environment: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION@app.configdefconfiguration(env:str)->StelvioAppConfig:returnStelvioAppConfig()# Uses env vars automatically
Separate profile for production:
fromstelvio.configimportAwsConfig@app.configdefconfiguration(env:str)->StelvioAppConfig:ifenv=="prod":# Production uses separate AWS accountreturnStelvioAppConfig(aws=AwsConfig(profile="production-account"))# Staging/personal use default accountreturnStelvioAppConfig()
@app.configdefconfiguration(env:str)->StelvioAppConfig:returnStelvioAppConfig(environments=["staging","prod"]# Only these shared environments allowed)
With this configuration:
Anyone can deploy to their personal environment (username)
Only "staging" and "prod" are accepted as shared environments
Stelvio will validate environment names and show an error for invalid ones
Common Patterns
Environment-Specific Resources
fromstelvio.appimportcontext...@app.rundefrun()->None:env=context().environmentifenv=="prod":# Production-specific resourcesprod_only_lambda=Function(name="backup")# Common resources for all environmentsmain_table=DynamoTable(name="users",...)
Next Steps
Now that you understand the StelvioApp structure, you might want to explore: