Created
December 2, 2025 19:38
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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