Skip to main content

A tool for describing AWS infrastructure as code

Project description

PyPI release Python versions Build Status Documentation Status Downloads Code style: black

flying-circus

Flying Circus is a tool for describing AWS infrastructure as code (using Python). It uses the same data structures as the AWS Cloud Formation service, except described as Python objects instead of the usual YAML. The Python program generates a YAML template, which is passed across to Cloud Formation in the usual manner.

It is a bit unusual to use a full programming language to describe infrastructure, instead of a static configuration file like many of us are used to (whether or not we also utilise a templating tool). We hope that the Flying Circus library can empower DevOps folk by unlocking some of the techniques that are available for software code, like named variables and techniques to structure code independently of the output format, libraries to allow code re-use with versioning, automated refactoring tools and so on.

You can learn how to use Flying Circus yourself by reading the documentation

Installation

Install Flying Circus through the Python packaging system:

pip install flying-circus

Many people also use the Amazon Web Services command line tools to deploy their CloudFormation stacks. If you want this, a good way to install an up-to-date version is also with pip:

# Optional
pip install awscli

Example

Here is a simple example of how you can use Flying Circus to describe some EC2 instances and deploy them using the AWS CloudFormation service.

First, create a python script (called my_ec2_stack.py in this case) to describe your infrastructure. Any valid Python can be used to create the Flying Circus objects, along with any valid CloudFormation properties and attributes.

This example is intentionally simplistic - it just creates two EC2 instances with varying configuration, and outputs the internal IP for one. However, it does hint at some of the more complex and powerful usage patterns.

import os

from flyingcircus.core import Stack, Output
from flyingcircus.intrinsic_function import GetAtt
from flyingcircus.service.ec2 import *


def create_ec2_instance(name, instance_type="t2.micro"):
    instance = Instance(Properties=InstanceProperties(
        ImageId="ami-942dd1f6",
        InstanceType=instance_type,
        Monitoring=False,
    ))
    instance.name = name
    return instance


if __name__ == "__main__":
    stack = Stack()

    stack.Resources["WebServer"] = create_ec2_instance("webserver")
    stack.Resources["DatabaseServer"] = dbserver = create_ec2_instance("dbserver", "t2.medium")
    dbserver.DeletionPolicy = "Retain"

    stack.Outputs["DatabaseServerIp"] = Output(
        Description=f"Internal IP address for the database server",
        Value=GetAtt(dbserver, "PrivateIp"),
    )

    stack.tag(application="api-service", environment="test", owner=os.environ.get("USER"))

    print(stack.export("yaml"))

Now generate CloudFormation YAML from your Python script. Note that the result will always be valid well-formatted YAML, and internal checks mean that it is also difficult to generate invalid CloudFormation.

Finally, use the AWS command line tools to create/update a stack and it's associated resources.

python my_ec2_stack.py > my_ec2_stack.yaml
aws cloudformation deploy --stack-name demo-flying-circus-ec2 --template-file my_ec2_stack.yaml

You could do these steps in your Continuous Integration server ;-)

Is/Is Not

There's a lot of tools for managing Infrastructure as Code, often with subtle differences and passionate advocates. A quick discussion of our scope may help you understand where Flying Circus fits into this ecosystem, and whether it can help you. This is presented in the simple "Is/Is Not" format.

Flying Circus Is...

  • ...a Pythonic DSL for writing fully featured Python code
  • ...for Amazon Web Services infrastructure
  • ...built on top of AWS Cloud Formation templates
  • ...a generator that always produces valid, consistent, human-readable, good-practice YAML

Flying Circus Is Not...

  • ...YAML or JSON. It's Python.
  • ...a tool to make it easier to write YAML or JSON. You write Python, and YAML is an output format.
  • ...a DSL with a completely new syntax. You use normal Python syntax with all of it's features and nothing changed.
  • ...a templating language, like Jinja2.
  • ...a template management tool, like Ansible.
  • ...an independent implementation of infrastructure management, like AWS Cloud Formation stacks, or Terraform.
  • ...a cloud-agnostic abstraction layer.
  • ...multi-cloud - although it could become this in the future. The current implementation is focused on representing AWS infrastructure using the CloudFormation data model. Other cloud providers have similar native data models, so it is feasible that we could re-use the concepts and tooling to support Google Cloud Platform, etc.
  • ...a tool for interacting with the Cloud Formation service. There are other tools that can do this for you (such as boto3 or the AWS CLI, for starters)
  • ...a validation tool - although it could become this in the future, and already has elements of validation as a by-product of presenting a helpful interface to users.

Sounds Great, Can I Use It?

Sure, of course you can. The documentation will get you started.

Flying Circus is currently in Beta. This means it is expected to work for the supported AWS services, and is in use by real customers. However, the details of the interface and implementation are still being validated and may change drastically.

How Do I Help?

Just use it!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flying-circus-0.7.0.tar.gz (77.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flying_circus-0.7.0-py3-none-any.whl (168.9 kB view details)

Uploaded Python 3

File details

Details for the file flying-circus-0.7.0.tar.gz.

File metadata

  • Download URL: flying-circus-0.7.0.tar.gz
  • Upload date:
  • Size: 77.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.9

File hashes

Hashes for flying-circus-0.7.0.tar.gz
Algorithm Hash digest
SHA256 a638bf2c9b2c90090d8309d63100268376e0632fabee1eed87895fc3411506c5
MD5 2833fdbdf8ad5ed4ddb74c7ac3238815
BLAKE2b-256 1f43f9e901c3a4b1f78a569eeeebc8a7cdb67c304848b64958b7a43561395071

See more details on using hashes here.

File details

Details for the file flying_circus-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: flying_circus-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 168.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.9

File hashes

Hashes for flying_circus-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31610bcb0f3474cf74abca3de237fc5a03f49004e03c1cdec11998eef6259d26
MD5 d6c49bdaa37c0572d2115a492bc3269a
BLAKE2b-256 e475014726894ed85f027c7fd7cf1c3c1432c82747cb3cacbf7ea36a6d653271

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page