Examples

Code examples of python-asff and how to use it. These snippets are usable “as is”.

Create a new finding

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#!/usr/bin/env python

from asff import AmazonSecurityFinding

f = AmazonSecurityFinding.from_kwargs(
    aws_account_id="0123456789012",
    title="Example finding",
    description="Example finding to demonstrate python-asff usage",
    types=["Software and Configuration Checks/AWS Security Best Practices"],
    product_name="python-asff-test",
)

print(f.to_json())

Send a finding to Security Hub

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python

import json

import boto3

from asff import AmazonSecurityFinding

sts = boto3.client("sts")
aws_account_id = sts.get_caller_identity()["Account"]

f = AmazonSecurityFinding.from_kwargs(
    aws_account_id=aws_account_id,
    title="Example finding",
    description="Example finding to demonstrate python-asff usage",
    types=["Software and Configuration Checks/AWS Security Best Practices"],
    product_name="python-asff-test",
)

sh = boto3.client("securityhub", region_name="eu-west-1")
response = sh.batch_import_findings(Findings=[f.to_dict()])

print(json.dumps(response, indent=4, sort_keys=True))