in frauddetector/frauddetector.py [0:0]
def create_variables(self, variables):
"""Create Amazon FraudDetector variables. Wraps the boto3 SDK API to allow bulk operations.
https://docs.aws.amazon.com/frauddetector/latest/ug/create-a-variable.html
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/frauddetector.html#FraudDetector.Client.create_variable
Args:
:variables: (list) List object containing variables to instantiate with associated Amazon Fraud Detector types
[
{
"name": "email_address",
"variableType": "EMAIL_ADDRESS",
"dataType": "STRING",
"defaultValue": "unknown",
"description": "email address",
"tags": [{"VariableName": "email_address"}, }]
},
...
]
Returns:
:response_all: {variable_name: API-response-status, variable_name: API-response-status} dict
"""
existing_names = [v['name'] for v in self.fd.get_variables()['variables']]
response_all = []
for v in variables:
if v['name'] not in existing_names:
# handle missing keys for incomplete JSON spec
data_type = v.get('dataType')
default_value = v.get('defaultValue')
if default_value is None:
if v['variableType'] != "NUMERIC":
default_value = '<unknown>'
else:
default_value = "0.0"
# create variables via Boto3 SDK fd instance
lh.debug("create_variables: {} {} defaultValue {}".format(v['name'], v['variableType'], default_value))
response = self.fd.create_variable(
name=v['name'],
variableType=v['variableType'],
dataSource='EVENT',
dataType=data_type,
defaultValue=default_value
)
lh.info("create_variables: variable {} created".format(v['name']))
status = {v['name']: response['ResponseMetadata']['HTTPStatusCode']}
response_all.append(status)
else:
lh.warning("create_variables: variable {} already exists, skipping".format(v['name']))
status = {v['name']: "skipped"}
response_all.append(status)
# update myself
self.variables = self.fd.get_variables()
# 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