A Python AWS Lambda function to send AWS Kinesis stream events to Falcon LogScale.
- create a Kinesis data source, or identify an existing source
- create a new Python (
python3.9
) AWS Lambda function to host the code- copy/paste the
lambda_function.py
code to the new Lambda functionlambda_function.py
- copy/paste the
- create new file named
logscale.py
, in the Lambda function- copy/paste the
logscale.py
code
- copy/paste the
- configure required Lambda environmental variables
- HOST - target LogScale server
- REPOSITORY - target LogScale repository
- TOKEN - LogScale ingest token
- configure the lambda run timeout setting
- increase the function timeout value above the default (3 secs)
- recommend at least thirty (30) seconds. monitor logs for timeouts.
- increase the function timeout value above the default (3 secs)
- Attach a Lambda layer that contains the python requests library
- create a new layer; upload zipfile that contains requests library
- or, attach and existing requests layer to the Lambda
- Enable a lambda trigger from the kinesis source
- create test events; test the function
- source - set to a unique name for the kinesis stream
- sourcetype - set to the destination LogScale ingest parser name
# suggestion: set the source field to uniquely identify the CloudTrail stream
source = "my-kinesis-stream"
# requirment: set the sourcetype to the target ingest parser name
sourcetype = "aws-kinesis"
hec_event = HecEvent(host=LOGSCALEHOST, index=REPOSITORY, source=source, sourcetype=sourcetype)
# optional: additional hec fields
# example
# hev['fields'].update({"trigger": "kinesis"})
# field name: "trigger"; field value: "kinesis"
hev['fields'].update({"trigger": "kinesis"})
- create a new target ingest repository, or select an existing repository
- create an ingest token, or use the default token
- configure ingest parsing
- kinesis outer event format is JSON
parseJson() | @timezone := "Z"
- kinesis event payload (
kinesis.data
) format varies according to stream format -[JSON|CSV|TSV|SYSLOG]
- e.g. JSON
parseJson(field=kinesis.data)
- e.g. JSON
- example JSON parser (see
aws-kinesis-json.yaml
):parseJson() | @timezone := "Z" | parseJson(field=kinesis.data)
- kinesis outer event format is JSON
- Note: event timestamp is set to lambda ingest time; timezone is GMT