Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save acdha/e60216c44d51b693f2ce2194b33cc5ec to your computer and use it in GitHub Desktop.

Select an option

Save acdha/e60216c44d51b693f2ce2194b33cc5ec to your computer and use it in GitHub Desktop.
Report AWS VPC resources which are blocking enforcement of VPC Encryption Controls (https://docs.aws.amazon.com/vpc/latest/userguide/vpc-encryption-controls.html)
#!/usr/bin/env -S uv run
# /// script
# requires-python = ">=3.14"
# dependencies = [
# "boto3",
# ]
# ///
"""
Report non-compliant resources blocking VPC Encryption Control enforcement
https://docs.aws.amazon.com/vpc/latest/userguide/vpc-encryption-controls.html
"""
import argparse
import sys
import boto3
EC2 = boto3.client("ec2")
def get_noncompliant_resources(vpc_id):
pagination = {}
while res := EC2.get_vpc_resources_blocking_encryption_enforcement(
VpcId="vpc-02b85984a755710b1",
**pagination,
):
pagination["NextToken"] = next_token = res.pop("NextToken", None)
yield from res["NonCompliantResources"]
if not next_token:
break
if __name__ == "__main__":
parser = argparse.ArgumentParser(description=__doc__.strip())
parser.add_argument(metavar="vpc_id", dest="vpc_ids", nargs="+")
args = parser.parse_args()
report_keys = ("Id", "Type", "IsExcludable", "Description")
for vpc_id in args.vpc_ids:
print("VPC", *report_keys, sep="\t")
for resource in get_noncompliant_resources(vpc_id):
print(vpc_id, *(resource.get(k, "") for k in report_keys), sep="\t")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment