-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtemplate.yaml
More file actions
133 lines (132 loc) · 5.98 KB
/
Copy pathtemplate.yaml
File metadata and controls
133 lines (132 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Metadata:
'AWS::ServerlessRepo::Application':
Name: kinesis-stream-device-data-to-amazon-location-tracker
Description:
Helps setup the resources to start streaming device location data to Amazon Location Service using BatchUpdateDevicePosition API.
https://docs.aws.amazon.com/location/latest/APIReference/API_BatchUpdateDevicePosition.html
Author: Amazon Location Service
SpdxLicenseId: MIT-0
LicenseUrl: LICENSE
SemanticVersion: 1.1.0
SourceCodeUrl: https://github.com/aws-geospatial/amazon-location-stream-device-data-to-tracker-lambda
Parameters:
TrackerName:
Type: String
Default: 'KinesisDataConsumerTracker'
Description: Name of the Location Service tracker to be created. Default is KinesisDataConsumerTracker.
EventBridgeEnabled:
Type: String
Default: 'false'
AllowedValues:
- 'true'
- 'false'
Description: Whether the tracker should emit EventBridge events.
TrackerPositionFilteringType:
Type: String
Default: 'TimeBased'
AllowedValues:
- TimeBased
- DistanceBased
- AccuracyBased
Description: The tracker's position filtering configuration. See Amazon Location Tracking documentation for details.
KinesisStreamArn:
Type: String
Description: ARN of your Kinesis data stream for tracking data.
KinesisStreamKmsKeyArn:
Type: String
Default: ''
AllowedPattern: '^$|^arn:aws[a-zA-Z-]*:kms:[a-z0-9-]+:[0-9]{12}:key/.+$'
ConstraintDescription: Must be empty, or a KMS key ARN of the form arn:<partition>:kms:<region>:<account>:key/<key-id> (an alias ARN is not accepted).
Description: >-
REQUIRED IF your source Kinesis stream is encrypted with a customer-managed
KMS key (CMK): set this to that key's ARN or the function will stop processing
records. The function is then granted only kms:Decrypt, scoped to this one key
and to requests carrying the stream's encryption context. Leave blank if the
stream is unencrypted or uses the AWS-managed key (aws/kinesis); in that case
no KMS permissions are granted. Provide the key ARN (arn:...:key/<id>), not an
alias ARN.
PathToDeviceId:
Type: String
Default: '$.DeviceId'
Description: JSONPath to DeviceId. Default is $.DeviceId. Required. See BatchUpdateDevicePosition documentation for the definition of DeviceId.
PathToDevicePositionLongitude:
Type: String
Default: '$.Position[0]'
Description: JSONPath to Longitude. Default is $.Position[0], assuming Position is a list. Required. See BatchUpdateDevicePosition documentation for the definition of Position.
PathToDevicePositionLatitude:
Type: String
Default: '$.Position[1]'
Description: JSONPath to Latitude. Default is $.Position[1], assuming Position is a list. Required. See BatchUpdateDevicePosition documentation for the definition of Position.
PathToSampleTime:
Type: String
Default: '$.Time'
Description: JSONPath to SampleTime. Default is $.Time. Required. See BatchUpdateDevicePosition documentation for the definition of SampleTime.
PathToHorizontalAccuracy:
Type: String
Default: '$.HorizontalAccuracy'
Description: JSONPath to Horizontal Accuracy, for example $.HorizontalAccuracy. Optional. See BatchUpdateDevicePosition documentation for the definition of Accuracy. Only horizontal accuracy is currently supported.
PathToPositionProperties:
Type: String
Default: '$.Properties'
Description: JSONPath to PositionProperties, for example $.Properties. Optional. See BatchUpdateDevicePosition documentation for the definition of PositionProperties.
Conditions:
HasKinesisStreamKmsKey: !Not [!Equals [!Ref KinesisStreamKmsKeyArn, '']]
Resources:
LocationTracker:
Type: AWS::Location::Tracker
Properties:
TrackerName: !Ref TrackerName
Description: "Tracker for my location-based application"
PositionFiltering: !Ref TrackerPositionFilteringType
EventBridgeEnabled: !Ref EventBridgeEnabled
TrackingDataConsumerLambdaFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: data_consumer.lambda_handler
Runtime: python3.12
CodeUri: ./src
Description: An AWS Lambda function to get data from Kinesis data stream and call Location Service's tracking feature.
MemorySize: 128
Timeout: 60
Environment:
Variables:
TRACKER_NAME: !Ref TrackerName
DEVICE_ID_PATH: !Ref PathToDeviceId
LONGITUDE_PATH: !Ref PathToDevicePositionLongitude
LATITUDE_PATH: !Ref PathToDevicePositionLatitude
SAMPLE_TIME_PATH: !Ref PathToSampleTime
HORIZONTAL_ACCURACY_PATH: !Ref PathToHorizontalAccuracy
POSITION_PROPERTIES_PATH: !Ref PathToPositionProperties
Policies:
- AWSLambdaKinesisExecutionRole
- Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- geo:BatchUpdateDevicePosition
Resource: !GetAtt LocationTracker.Arn
- !If
- HasKinesisStreamKmsKey
- Effect: Allow
Action:
- kms:Decrypt
Resource: !Ref KinesisStreamKmsKeyArn
Condition:
StringEquals:
'kms:EncryptionContext:aws:kinesis:arn': !Ref KinesisStreamArn
- !Ref 'AWS::NoValue'
Events:
KinesisEvent:
Type: Kinesis
Properties:
Stream: !Ref KinesisStreamArn
BatchSize: 100
StartingPosition: LATEST
MaximumBatchingWindowInSeconds: 5
MaximumRetryAttempts: 2
BisectBatchOnFunctionError: true # This will split a failed batch into two. This can help identify any failed records. See https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html for guidance.
Enabled: True