in frauddetector/frauddetector.py [0:0]
def create_labels(self, labels):
"""Create Amazon FraudDetector labels. Wraps the boto3 SDK API to allow bulk operations.
https://docs.aws.amazon.com/frauddetector/latest/ug/create-a-label.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/frauddetector.html#FraudDetector.Client.put_label
Args:
:labels: (list) List object containing labels to instantiate with associated Amazon Fraud Detector
[
{
"name": "legit"
},
{
"name": "fraud"
}
]
Returns:
:response_all: {variable_name: API-response-status, variable_name: API-response-status} dict
"""
existing_names = [l['name'] for l in self.labels['labels']]
response_all = []
for l in labels:
if l['name'] not in existing_names:
# create label via Boto3 SDK fd instance
lh.debug("put_label: {}".format(l['name']))
response = self.fd.put_label(
name=l['name'],
description=l['name']
)
lh.info("create_labels: label {} created".format(l['name']))
status = {l['name']: response['ResponseMetadata']['HTTPStatusCode']}
response_all.append(status)
else:
lh.warning("create_labels: label {} already exists, skipping".format(l['name']))
status = {l['name']: "skipped"}
response_all.append(status)
# update myself
self.variables = self.fd.get_labels()
# convert list of dicts to single dict
response_all = {k: v for d in response_all for k, v in d.items()}
return response_all