This is a easy-to-setup stack to help the user connect streaming device position data from Kinesis Data Stream to Amazon Location service.
This app can be deployed to any existing service or app that uses Kinesis Data Stream to stream device position data to Amazon Location.
It will create a Tracker and a Lambda function to stream data to the tracker, along with the necessary permissions.
- Search for AWS Serverless Application Repository.
- Select "Available applications" on the left side panel.
- Search for "kinesis-stream-device-data-to-location-tracker". You may need to check "Show apps that create custom IAM roles or resource policies" to see the application.
- Enter the required parameters, then click "Deploy". A new web browser window/tab will pop up.
- Monitor the "Deployment Status" on the new window.
TrackerName
: Name of the Amazon Location Tracker to be created.
EventBridgeEnabled
: Whether EventBridge integration is turned on. It may incur additional costs by leaving it on unused.
Note that this app requires a Kinesis Data Stream as an input.
The app supports custom event structure via JSONPath-ng.
See Kinesis documentation for Lambda consumers for more information about fine-tuning the system.
By default, this supports data defined in the following structure:
{
"DeviceId": "<your device id>",
"Position": [<some longitude, some latitude>],
"Time": "<the update's timestamp in ISO 8601 format (https://www.iso.org/iso-8601-date-and-time-format.html)>",
"Properties": {
"key1": val1,
"key2": val2,
"key3": val3
},
"HorizontalAccuracy": <some number>
}
These are one-to-one mapped to parameters of BatchUpdateDevicePosition API.
For example, the SampleTime API parameter is populated by the source event's Time property by default. $.Time is a JSONPath expression targeting Time in the source event JSON above.
List of paths that are configurable:
PathToDeviceId
maps to theDeviceId
parameter of the API. Default is$.DeviceId
.PathToDevicePositionLongitude
maps to the first element of thePosition
parameter of the API. Default is$.Position[0]
.PathToDevicePositionLatitude
maps to the second element of thePosition
parameter of the API. Default is$.Position[1]
.PathToSampleTime
maps to theSampleTime
parameter of the API. Default is$.Time
.PathToHorizontalAccuracy
maps to theAccuracy
parameter, specifically theHorizontal
key. Default is$.HorizontalAccuracy
.Horizontal
is the only type of accuracy supported by the API.PathToPositionProperties
maps to thePositionProperties
parameter of the API.
To publish your own adaptions to the Serverless Application Repository as a private application, run the following:
# create a bucket if necessary and ensure that it has an appropriate bucket policy, similar to the one below
aws s3 mb s3://<bucket> --region <region>
AWS_REGION=<region> S3_BUCKET=<bucket> make publish
<bucket>
must be readable by the Serverless Application Repository. This can be achieved by applying the following policy to the bucket:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "serverlessrepo.amazonaws.com"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::<bucket>/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<account-id>"
}
}
}
]
}
Note that the Condition
is added as a best practice to prevent the potential confused deputy problem.
Since this app is being deployed as a private application, the aws:SourceAccount
should point to the account in which this app is deployed to.
Once this runs successfully, you'll be able to view the application on Serverless Application Repository console under "private applications" and deploy it.
It is advisable to monitor the performance of this Lambda in production environment.
See Lambda documentation for what Kinesis-Lambda metrics are available.
See Lambda Metrics documentation about how to work with Lambda metrics.
For this particular app, Lambda's IteratorAge
metric would be an important metric to monitor. IteratorAge
describes the age of the latest Kinesis record consumed by the Lambda function.
It can be used to monitor if the consumer is working. An increased IteratorAge
indicates either increased latency or error in the system.
The Lambda function created by this app has CloudWatch logging enabled by default. Steps to see the logs:
- Go to
CloudWatch
on AWS console. - Select
Log groups
on the left side panel. - Look for a log group that starts with
/aws/lambda/serverlessrepo-kinesis-st-TrackingDataConsumer
. This contains log output from the Lambda function, including details on the conditions described below.
This app logs failed executions or invalid position updates into its log group, and retries twice on errors.
Note that this app calls BatchUpdateDevicePosition API. Retries on that API may result in the same position update being processed multiple times. Amazon Location handles this case by only storing the most recent position update.
See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License.