AWACS (AWS Access Policy Language creation library)

2.5.0 · active · verified Sat Apr 11

AWACS is a Python library designed for creating AWS Access Policy Language (IAM policies) programmatically. It provides a structured way to define policies using Python objects, making them easier to manage, version, and integrate into infrastructure-as-code tools. The library regularly updates its definitions for AWS services and actions by scraping AWS documentation. It is actively maintained with frequent minor releases to incorporate new AWS actions and address scraper fixes, currently at version 2.5.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple AWS IAM AssumeRole policy and an S3 read-only policy using AWACS. It shows how to import core components like `Policy`, `Statement`, `Principal`, `Action`, `Effect`, and specific service actions (`AssumeRole`, `GetObject`, `ListBucket`) to build policies that can then be converted to a JSON string for use with AWS services.

from awacs.aws import Action, Allow, Policy, Principal, Statement
from awacs.iam import ARN
from awacs.sts import AssumeRole

# Create a basic AssumeRole policy
policy = Policy(
    Statement(
        Effect=Allow,
        Principal=Principal("AWS", ARN("arn:aws:iam::123456789012:root")),
        Action=[AssumeRole],
    )
)

# Convert the policy to JSON string
policy_json = policy.to_json()
print(policy_json)

# Example of an S3 read-only policy for a specific bucket
from awacs.s3 import GetObject, ListBucket

s3_read_policy = Policy(
    Statement(
        Effect=Allow,
        Action=[ListBucket],
        Resource=[ARN("arn:aws:s3:::my-example-bucket")]
    ),
    Statement(
        Effect=Allow,
        Action=[GetObject],
        Resource=[ARN("arn:aws:s3:::my-example-bucket/*")]
    )
)
print(s3_read_policy.to_json())

view raw JSON →