Cloud + Python
Cloud SDK patterns — storage, serverless handlers, secrets, and deployment helpers.
How to Mock Pulumi Stack Outputs in Python
Create a dict-like mock of Pulumi stack outputs for local testing and scripts without running pulumi.
from collections import defaultdict
class StackOutputMock:
def __init__(self, outputs: dict):
self.outputs = dict(outputs)
def export(self):
return self.outputs
def get(self, key: str, default=None):
return self.outputs.get(key, default)
def keys(self):
r…
How to Parse Terraform Output JSON in Python
Parse Terraform's JSON output into a flat dictionary of values using the standard library json module.
import json
def parse_terraform_output(raw_output):
"""Parse Terraform JSON output into a flat dict of values."""
try:
data = json.loads(raw_output)
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON: {e}")
return {key: value["value"] for key, value in data.items()}
i…
Mock CloudWatch put_metric_data in Python
Simulate AWS CloudWatch put_metric_data with validation and formatted output for local testing without AWS.
import json
from datetime import datetime, timezone
def put_metric_data(namespace, metric_data_list):
"""
Mock AWS CloudWatch put_metric_data.
Validates and prints the metrics that would be sent.
"""
timestamp = datetime.now(timezone.utc).isoformat()
print(f"[MockCloudWatch] Received request …
Browse by section
Each section groups closely related Python snippets.
Cloud + Python — Python code examples
What you will find here
This page collects cloud + python snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.
Samples vs tutorials and challenges
Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.