1. Home
  2. /
  3. Pulumi-automation
  4. /
  5. Simple Pulumi Automation API Script (Python)

Simple Pulumi Automation API Script (Python) - Pulumi-automation Typing CST Test

Loading…

Simple Pulumi Automation API Script (Python) — Pulumi-automation Code

A simple Pulumi Automation API script in Python to create an S3 bucket.

# pulumi/demo/automation_api.py
import pulumi
from pulumi_automation import LocalWorkspace

stack = LocalWorkspace.create_stack(stack_name='dev', project_name='demo_project')

bucket = pulumi.aws.s3.Bucket('my-bucket')

stack.up()

Pulumi-automation Language Guide

Pulumi Automation API enables programmatic Infrastructure as Code (IaC) by allowing developers to define, deploy, and manage cloud infrastructure directly from code in languages like TypeScript, Python, Go, and C#. It provides full automation capabilities for CI/CD and custom tooling.

Primary Use Cases

  • ▸Programmatic provisioning of cloud infrastructure
  • ▸Automating CI/CD pipelines for infrastructure changes
  • ▸Embedding infrastructure logic into custom applications
  • ▸Testing and validating infrastructure programmatically
  • ▸Multi-cloud infrastructure orchestration from code

Notable Features

  • ▸Use familiar programming languages (TypeScript, Python, Go, C#) for IaC
  • ▸Full automation API for programmatic infrastructure management
  • ▸Supports multiple cloud providers and Kubernetes
  • ▸Preview, update, and destroy infrastructure via code
  • ▸Integration with CI/CD pipelines and testing frameworks

Origin & Creator

Created by Pulumi, Inc. to extend Pulumi’s cloud infrastructure platform for programmable automation of deployments within custom applications and CI/CD pipelines.

Industrial Note

Pulumi Automation is often used by platform teams and DevOps engineers who need to integrate IaC tightly with CI/CD pipelines, testing frameworks, and custom automation tools, allowing infrastructure to be treated as a software library.

Quick Explain

  • ▸Pulumi Automation API allows embedding Pulumi programs into applications or pipelines.
  • ▸Infrastructure is defined imperatively using familiar programming languages rather than YAML or JSON.
  • ▸Supports multiple cloud providers such as AWS, GCP, Azure, Kubernetes, and more.
  • ▸Enables full lifecycle automation: preview, update, refresh, and destroy resources.
  • ▸Ideal for programmatically managing infrastructure in CI/CD, GitOps, or custom dev workflows.

Core Features

  • ▸Pulumi stacks can be managed programmatically
  • ▸Supports stack outputs, configuration, secrets, and state management
  • ▸Automation API allows embedding Pulumi programs into apps or scripts
  • ▸Programmatic control over lifecycle: preview, up, destroy, refresh
  • ▸Works with local, cloud, or backend state management

Learning Path

  • ▸Learn Pulumi basics and CLI usage
  • ▸Understand resource concepts and stacks
  • ▸Practice Automation API with sample scripts
  • ▸Integrate Automation API into CI/CD pipelines
  • ▸Experiment with multi-cloud deployments

Practical Examples

  • ▸Provision AWS S3 bucket using TypeScript Automation API
  • ▸Programmatically deploy Kubernetes cluster with Python
  • ▸CI/CD pipeline that dynamically creates environments per branch
  • ▸Automated testing of infrastructure updates in a staging environment
  • ▸Multi-cloud deployments orchestrated via Go Automation API scripts

Comparisons

  • ▸Pulumi vs Terraform - code-first imperative vs declarative IaC
  • ▸Pulumi vs Crossplane - programmatic API vs Kubernetes-native CRDs
  • ▸Pulumi vs Ansible - full automation vs configuration management
  • ▸Pulumi vs CloudFormation - multi-cloud code vs provider-specific templates
  • ▸Pulumi vs CDK - similar programmatic IaC, Automation API enables custom embedding

Strengths

  • ▸Full flexibility of a programming language for infrastructure
  • ▸Tight integration with CI/CD pipelines
  • ▸Supports multi-cloud deployments
  • ▸Automates infrastructure operations without manual CLI steps
  • ▸Enables testing and validation of infrastructure code

Limitations

  • ▸Requires programming knowledge in supported languages
  • ▸Less declarative than YAML/JSON-based IaC tools
  • ▸Automation API adds complexity for simple use cases
  • ▸State management setup needed (local or Pulumi Service)
  • ▸Limited pre-built abstractions compared to declarative frameworks

When NOT to Use

  • ▸For teams preferring fully declarative YAML or JSON
  • ▸When no programming expertise is available
  • ▸For simple single-cloud deployments without automation needs
  • ▸If CLI-only manual deployment is sufficient
  • ▸Where Kubernetes-native CRDs are preferred (use Crossplane instead)

Cheat Sheet

  • ▸AutomationAPI.createStack - create or select stack programmatically
  • ▸stack.preview() - preview infrastructure changes
  • ▸stack.up() - apply updates
  • ▸stack.destroy() - remove resources
  • ▸stack.outputs() - read outputs programmatically

FAQ

  • ▸Can Automation API provision AWS resources? -> Yes, via Pulumi SDK
  • ▸Is it free? -> Yes, open-source with optional Pulumi Service features
  • ▸Does it support multi-cloud? -> Yes, fully supported
  • ▸Can it integrate with CI/CD? -> Yes, Automation API is designed for pipelines
  • ▸Can it handle secrets securely? -> Yes, via Pulumi secrets and backend

30-Day Skill Plan

  • ▸Week 1: Create single resource via Automation API
  • ▸Week 2: Manage stack lifecycle programmatically
  • ▸Week 3: Use outputs, configuration, and secrets
  • ▸Week 4: CI/CD integration with Automation API
  • ▸Week 5: Multi-cloud orchestration and testing

Final Summary

  • ▸Pulumi Automation API allows programmatic control of infrastructure via code.
  • ▸Supports multiple cloud providers and Kubernetes.
  • ▸Enables embedding infrastructure automation in applications and CI/CD pipelines.
  • ▸Provides full lifecycle management: preview, update, destroy.
  • ▸Ideal for DevOps teams and platform engineers seeking code-first automation.

Project Structure

  • ▸Pulumi.yaml - stack metadata
  • ▸index.ts / main.py / main.go - infrastructure program
  • ▸package.json / requirements.txt / go.mod - dependencies
  • ▸automation/ - scripts using Automation API
  • ▸README.md - documentation and instructions

Monetization

  • ▸Enterprise automation of infrastructure deployments
  • ▸Platform engineering SaaS tooling
  • ▸Managed Pulumi Service subscriptions
  • ▸Consulting and DevOps integration services
  • ▸Programmatic multi-cloud orchestration for clients

Productivity Tips

  • ▸Reuse Automation API functions across stacks
  • ▸Use secrets and configuration effectively
  • ▸Integrate with CI/CD pipelines for repeatability
  • ▸Programmatically validate changes before deployment
  • ▸Monitor scripts and backend for consistency

Basic Concepts

  • ▸Stack - isolated instance of infrastructure (like environment)
  • ▸Program - code defining resources for a stack
  • ▸Resource - cloud or Kubernetes entity managed by Pulumi
  • ▸Config - stack configuration values, including secrets
  • ▸Automation API - programmatic API to manage stacks

Official Docs

  • ▸https://www.pulumi.com/docs/automation-api/
  • ▸Pulumi GitHub repository
  • ▸Pulumi Service documentation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher