Skip to content

Commit

Permalink
Improve method for adding geofence collections
Browse files Browse the repository at this point in the history
  • Loading branch information
mazyu36 committed Sep 3, 2024
1 parent 5fb3cdd commit a815c83
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 140 deletions.
11 changes: 7 additions & 4 deletions packages/@aws-cdk/aws-location-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,17 @@ const tracker = new location.Tracker(this, 'Tracker', {
tracker.grantRead(role);
```

If you want to associate a tracker with a geofence collection, define a `TrackerConsumer`.
If you want to associate a tracker with geofence collections, define a `geofenceCollections` property or use `addGeofenceCollections` method.

```ts
declare const geofenceCollection: location.GeofenceCollection;
declare const geofenceCollectionForAdd: location.GeofenceCollection;
declare const tracker: location.Tracker;

new location.TrackerConsumer(this, 'TrackerConsumer', {
consumer: geofenceCollection,
tracker: tracker,
const tracker = new location.Tracker(this, 'Tracker', {
trackerName: 'MyTracker',
geofenceCollections: [geofenceCollection],
});

tracker.addGeofenceCollections(geofenceCollectionForAdd);
```
1 change: 0 additions & 1 deletion packages/@aws-cdk/aws-location-alpha/awslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"exclude": [
"props-physical-name:@aws-cdk/aws-location-alpha.TrackerConsumerProps"
]
}
37 changes: 0 additions & 37 deletions packages/@aws-cdk/aws-location-alpha/lib/tracker-consumer.ts

This file was deleted.

29 changes: 28 additions & 1 deletion packages/@aws-cdk/aws-location-alpha/lib/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as iam from 'aws-cdk-lib/aws-iam';
import * as kms from 'aws-cdk-lib/aws-kms';
import { ArnFormat, IResource, Lazy, Resource, Stack, Token } from 'aws-cdk-lib/core';
import { Construct } from 'constructs';
import { CfnTracker } from 'aws-cdk-lib/aws-location';
import { CfnTracker, CfnTrackerConsumer } from 'aws-cdk-lib/aws-location';
import { generateUniqueId } from './util';
import { IGeofenceCollection } from './geofence-collection';

/**
* A Tracker
Expand Down Expand Up @@ -74,6 +75,13 @@ export interface TrackerProps {
* @default PositionFiltering.TIME_BASED
*/
readonly positionFiltering?: PositionFiltering;

/**
* An optional list of geofence collections to associate with the tracker resource
*
* @default - no geofence collections are associated
*/
readonly geofenceCollections?: IGeofenceCollection[];
}

/**
Expand Down Expand Up @@ -193,12 +201,31 @@ export class Tracker extends Resource implements ITracker {
positionFiltering: props.positionFiltering,
});

props.geofenceCollections?.forEach((collection) => {
new CfnTrackerConsumer(this, `TrackerConsumer${collection.node.id}`, {
consumerArn: collection.geofenceCollectionArn,
trackerName: Lazy.string({ produce: () => this.trackerName }),
});
});

this.trackerName = tracker.ref;
this.trackerArn = tracker.attrArn;
this.trackerCreateTime = tracker.attrCreateTime;
this.trackerUpdateTime = tracker.attrUpdateTime;
}

/**
* Add Geofence Collections which are associated to the tracker resource.
*/
public addGeofenceCollections(...geofenceCollections: IGeofenceCollection[]) {
geofenceCollections.forEach((collection) => {
new CfnTrackerConsumer(this, `TrackerConsumer${collection.node.id}`, {
consumerArn: collection.geofenceCollectionArn,
trackerName: Lazy.string({ produce: () => this.trackerName }),
});
});
}

/**
* Grant the given principal identity permissions to perform the actions on this tracker.
*/
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
{
"Resources": {
"GeofenceCollection6FAC681F": {
"GeofenceCollection1D36FEE6D": {
"Type": "AWS::Location::GeofenceCollection",
"Properties": {
"CollectionName": "MyGeofenceCollection",
"Description": "test"
"CollectionName": "cdkinteglocationtrackerGeofenceCollection10D13873F"
}
},
"GeofenceCollection2348D6DB5": {
"Type": "AWS::Location::GeofenceCollection",
"Properties": {
"CollectionName": "cdkinteglocationtrackerGeofenceCollection262FB26D9"
}
},
"GeofenceCollectionForAdd131D6B4EA": {
"Type": "AWS::Location::GeofenceCollection",
"Properties": {
"CollectionName": "cdkinteglocationtrackerGeofenceCollectionForAdd1449865F9"
}
},
"GeofenceCollectionForAdd21A9CA549": {
"Type": "AWS::Location::GeofenceCollection",
"Properties": {
"CollectionName": "cdkinteglocationtrackerGeofenceCollectionForAdd22B418373"
}
},
"Key961B73FD": {
Expand Down Expand Up @@ -58,12 +75,54 @@
"TrackerName": "MyTracker"
}
},
"TrackerConsumer3AEB9150": {
"TrackerTrackerConsumerGeofenceCollection106C790AE": {
"Type": "AWS::Location::TrackerConsumer",
"Properties": {
"ConsumerArn": {
"Fn::GetAtt": [
"GeofenceCollection1D36FEE6D",
"Arn"
]
},
"TrackerName": {
"Ref": "TrackerAF5FC55F"
}
}
},
"TrackerTrackerConsumerGeofenceCollection2BA7E93DE": {
"Type": "AWS::Location::TrackerConsumer",
"Properties": {
"ConsumerArn": {
"Fn::GetAtt": [
"GeofenceCollection2348D6DB5",
"Arn"
]
},
"TrackerName": {
"Ref": "TrackerAF5FC55F"
}
}
},
"TrackerTrackerConsumerGeofenceCollectionForAdd1BAA19E05": {
"Type": "AWS::Location::TrackerConsumer",
"Properties": {
"ConsumerArn": {
"Fn::GetAtt": [
"GeofenceCollectionForAdd131D6B4EA",
"Arn"
]
},
"TrackerName": {
"Ref": "TrackerAF5FC55F"
}
}
},
"TrackerTrackerConsumerGeofenceCollectionForAdd268D815CE": {
"Type": "AWS::Location::TrackerConsumer",
"Properties": {
"ConsumerArn": {
"Fn::GetAtt": [
"GeofenceCollection6FAC681F",
"GeofenceCollectionForAdd21A9CA549",
"Arn"
]
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a815c83

Please sign in to comment.