Reference library

Cloud + Python

Cloud SDK patterns — storage, serverless handlers, secrets, and deployment helpers.

4 matches
Cloud + Python easy

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.

pulumi mock cloud
Python
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…
12 0 Open
Cloud + Python easy

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.

terraform json cloud
Python
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…
11 0 Open
Cloud + Python medium

Mock CDK Synth Output in Python for Template Testing

Simulate AWS CDK synth output with MagicMock to test or preview CloudFormation templates without running a real CDK app.

aws cdk cloudformation
Python
import json
from unittest.mock import MagicMock

def mock_cdk_synth() -> dict:
    """Simulate AWS CDK synth output for a simple S3 bucket."""
    cdk_app = MagicMock()
    cdk_app.synth.return_value.template = {
        "Resources": {
            "MyBucket": {
                "Type": "AWS::S3::Bucket",
              …
12 0 Open
Cloud + Python easy

Mock CloudWatch put_metric_data in Python

Simulate AWS CloudWatch put_metric_data with validation and formatted output for local testing without AWS.

cloudwatch aws mock
Python
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 …
15 0 Open

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.