mypy-boto3-codeguru-security

1.42.3 · active · verified Sat Apr 11

mypy-boto3-codeguru-security provides type annotations for the `boto3` AWS SDK for Python, specifically for the CodeGuruSecurity service. These stubs enable static type checkers like Mypy to validate `boto3` calls, improving code quality and catching errors early. It is part of the `mypy-boto3-builder` ecosystem, which maintains a regular release cadence to stay in sync with `boto3` updates. The current version is 1.42.3.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a `boto3` client for CodeGuruSecurity with explicit type hints and then use it to list findings, leveraging paginators. To run this, ensure `boto3` and `mypy-boto3-codeguru-security` are installed, and your AWS credentials are configured (e.g., via environment variables or AWS CLI configuration).

import boto3
from mypy_boto3_codeguru_security.client import CodeGuruSecurityClient
from mypy_boto3_codeguru_security.type_defs import ListFindingsResponseTypeDef

def get_codeguru_security_client() -> CodeGuruSecurityClient:
    """Initializes and returns a CodeGuruSecurity client with type hints."""
    # boto3 automatically picks up credentials from environment variables or IAM roles
    # For local testing, ensure AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN (optional) are set.
    return boto3.client("codeguru-security")

def list_all_findings(client: CodeGuruSecurityClient) -> None:
    """Lists CodeGuruSecurity findings and prints their IDs."""
    print("Listing CodeGuruSecurity findings...")
    paginator = client.get_paginator("list_findings")
    page_iterator = paginator.paginate()

    found_findings = 0
    for page in page_iterator:
        page_data: ListFindingsResponseTypeDef = page
        for finding in page_data.get("findings", []):
            print(f"  Finding ID: {finding.get('id')}")
            found_findings += 1
    if found_findings == 0:
        print("  No findings found.")
    else:
        print(f"Found {found_findings} findings.")

if __name__ == "__main__":
    # Example usage
    codeguru_client = get_codeguru_security_client()
    list_all_findings(codeguru_client)

view raw JSON →