Skip to content

Commit eda67a1

Browse files
adding new page for access customization, configuring geofence collections, and new set up page
1 parent 6c46bc7 commit eda67a1

File tree

6 files changed

+232
-234
lines changed

6 files changed

+232
-234
lines changed

src/components/GeoLegacyResourcesBanner/GeoLegacyResourcesBanner.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ import classNames from 'classnames';
55
export const GeoLegacyResourcesBanner = () => {
66
return (
77
<Callout backgroundColor="background.error">
8-
Amazon Location Service has introduced new APIs for Maps and Places which
9-
no longer require account-bound resources. Amplify Geo no longer supports
10-
the provisioning of legacy (account-bound) maps and place indices. Please{' '}
8+
Amazon Location Service has introduced{' '}
9+
<Link
10+
href="https://us-west-2.console.aws.amazon.com/location/home?region=us-west-2#/feature-spotlight"
11+
passHref
12+
className={classNames('amplify-link')}
13+
>
14+
new APIs for Maps and Places
15+
</Link>{' '}
16+
which no longer require account-bound resources. Amplify Geo no longer
17+
supports the provisioning of legacy (account-bound) maps and place
18+
indices. Please{' '}
1119
<Link
1220
href="https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_location-readme.html"
1321
passHref

src/directory/directory.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ export const directory = {
530530
{
531531
path: 'src/pages/[platform]/build-a-backend/add-aws-services/geo/set-up-geo/index.mdx'
532532
},
533+
{
534+
path: 'src/pages/[platform]/build-a-backend/add-aws-services/geo/custom-authorization/index.mdx'
535+
},
533536
{
534537
path: 'src/pages/[platform]/build-a-backend/add-aws-services/geo/maps/index.mdx'
535538
},

src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-geofencing/index.mdx

Lines changed: 58 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -29,70 +29,62 @@ A Geofence is a virtual perimeter for a real-world geographic area. A Geofence c
2929

3030
## Setup a new Geofence Collection
3131

32+
```ts title="amplify/geo/resource.ts"
33+
import { defineCollection } from "@aws-amplify/backend-geo";
34+
35+
export const collection = defineCollection({
36+
name: 'amplifyCollection',
37+
description: 'This is an Amplify collection.',
38+
access: (allow) => [
39+
allow.authenticated.to(['create', 'read', 'update', 'delete', 'list']),
40+
allow.guest.to(['read', 'list'])
41+
]
42+
});
43+
```
44+
45+
Now update your `backend.ts` file with the collection created in your `resource.ts` file.
46+
3247
```ts title="amplify/backend.ts"
3348
import { defineBackend } from "@aws-amplify/backend";
3449
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
3550
import { CfnGeofenceCollection } from "aws-cdk-lib/aws-location";
3651
import { auth } from "./auth/resource";
3752
import { data } from "./data/resource";
53+
import { collection } from "./geo/resource";
3854

3955
const backend = defineBackend({
4056
auth,
4157
data,
42-
// additional resources
58+
collection
4359
});
60+
```
4461

45-
const geoStack = backend.createStack("geo-stack");
46-
47-
// create a location services geofence collection
48-
const myGeofenceCollection = new CfnGeofenceCollection(
49-
geoStack,
50-
"GeofenceCollection",
51-
{
52-
collectionName: "myGeofenceCollection",
53-
pricingPlan: "RequestBasedUsage",
54-
tags: [
55-
{
56-
key: "name",
57-
value: "myGeofenceCollection",
58-
},
59-
],
60-
}
61-
);
62-
63-
// create an IAM policy to allow interacting with geofence collection resource
64-
const myGeofenceCollectionPolicy = new Policy(
65-
geoStack,
66-
"GeofenceCollectionPolicy",
67-
{
68-
policyName: "myGeofenceCollectionPolicy",
69-
statements: [
70-
new PolicyStatement({
71-
actions: [
72-
"geo:GetGeofence",
73-
"geo:PutGeofence",
74-
"geo:BatchPutGeofence",
75-
"geo:BatchDeleteGeofence",
76-
"geo:ListGeofences",
77-
],
78-
resources: [myGeofenceCollection.attrArn],
79-
}),
80-
],
81-
}
82-
);
83-
84-
// apply the policy to the authenticated and unauthenticated roles
85-
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeofenceCollectionPolicy);
86-
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeofenceCollectionPolicy);
87-
88-
// patch the geofence collection resource to the expected output configuration
89-
backend.addOutput({
90-
geo: {
91-
geofence_collections: {
92-
default: myGeofenceCollection.collectionName,
93-
items: [myGeofenceCollection.collectionName],
94-
},
95-
},
62+
<Callout warning="true">
63+
64+
AWS Location API keys currently do not support geofence collections or their associated APIs. Adding acesss definitions for any API keys using the `allow.apiKey.to()` definition will NOT result in the creation of an API key.
65+
66+
</Callout>
67+
68+
## Configure additional geofence collections
69+
70+
Amplify Geo gives you the ability to configure your backend to automatically request and manage multiple geofence collections.
71+
72+
You can define these additional geofence collections by reusing the `defineCollection` function while providing a unique `name` to identify the collection. You can configure specific access permissions to these collections by adding them to the API with the unique `name`.
73+
74+
<Callout info>
75+
76+
**Note**: If numerous geofence collections are defined, then one of them must be marked as default using the `isDefault` flag.
77+
78+
</Callout>
79+
80+
```ts title="amplify/geo/resource.ts"
81+
export const firstCollection = defineCollection({
82+
name: 'firstCollection',
83+
isDefault: true
84+
});
85+
86+
export const secondCollection = defineCollection({
87+
name: 'secondCollection'
9688
});
9789
```
9890

@@ -117,30 +109,21 @@ export const auth = defineAuth({
117109
});
118110
```
119111

120-
2. Add permissions to the Cognito User Pool Group role
112+
2. Update the collection access definition in your `resource.ts`
121113

122-
```ts title="amplify/backend.ts"
123-
const myGeofenceCollectionPolicy = new Policy(
124-
geoStack,
125-
"GeofenceCollectionPolicy",
126-
{
127-
policyName: "myGeofenceCollectionPolicy",
128-
statements: [
129-
new PolicyStatement({
130-
actions: [
131-
"geo:GetGeofence",
132-
"geo:PutGeofence",
133-
"geo:BatchPutGeofence",
134-
"geo:BatchDeleteGeofence",
135-
"geo:ListGeofences",
136-
],
137-
resources: [myGeofenceCollection.attrArn],
138-
}),
139-
],
140-
}
141-
);
142-
143-
backend.auth.resources.groups["User"].role.attachInlinePolicy(myGeofenceCollectionPolicy);
114+
```ts title="amplify/geo/resource.ts"
115+
import { defineCollection } from "@aws-amplify/backend-geo";
116+
117+
export const collection = defineCollection({
118+
name: 'amplifyCollection',
119+
description: 'This is an Amplify collection.',
120+
access: (allow) => [
121+
allow.authenticated.to(['create', 'read', 'update', 'delete', 'list']),
122+
allow.guest.to(['read', 'list']),
123+
// highlight-next-line
124+
allow.groups("User").to(['read', 'update'])
125+
]
126+
});
144127
```
145128

146129
> Note: If you combine `Auth/Guest user access` and `Individual Group access`, users who are members of a group will only be granted the permissions of the group, and not the authenticated user permissions. The permissions apply to ALL Geofences in a collection. For example, If you add `Read` permission such as `ListGeofences` and `GetGeofence` to `User` Cognito group, ALL users added to that group will be able to read the properties of ALL Geofences in that Geofence collection.

src/pages/[platform]/build-a-backend/add-aws-services/geo/configure-location-search/index.mdx

Lines changed: 27 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -27,131 +27,51 @@ export function getStaticProps(context) {
2727
};
2828
}
2929

30-
31-
Amplify's `geo` category enables you to search by places, addresses, and coordinates in your app with "place index" resources.
30+
Amplify's `geo` category enables you to search by places, addresses, and coordinates in your app with "place index" resources. These resources also include an API key with access restrictions specified from the `access` callback. This API key will be used to render the location search components if your application requires access control on the components. To set up or learn more about Amazon Location API keys, visit the [developer guide](https://docs.aws.amazon.com/location/latest/developerguide/using-apikeys.html).
3231

3332
## Setup a new Location Search Index
3433

34+
```ts title="amplify/geo/resource.ts"
35+
import { definePlace } from "@aws-amplify/backend-geo";
36+
37+
export const searchIndex = definePlace({
38+
name: 'amplfyPlace',
39+
description: 'This is an Amplify search index.',
40+
access: (allow) => [
41+
allow.authenticated.to(['autocomplete', 'geocode']),
42+
allow.guest.to(['autocomplete', 'geocode']),
43+
allow.apiKey.to(['search'])
44+
],
45+
apiKeyProps: {
46+
apiKeyName: 'amplifyPlaceIndexKey'
47+
}
48+
});
49+
```
50+
51+
Now update your `backend.ts` file with the place index created in your `resource.ts` file.
52+
3553
```ts title="amplify/backend.ts"
3654
import { defineBackend } from "@aws-amplify/backend";
37-
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
38-
// highlight-next-line
39-
import { CfnMap, CfnPlaceIndex } from "aws-cdk-lib/aws-location";
4055
import { auth } from "./auth/resource";
4156
import { data } from "./data/resource";
57+
// highlight-next-line
58+
import { searchIndex } from "./geo/resource";
4259

4360
const backend = defineBackend({
4461
auth,
4562
data,
46-
// additional resources
47-
});
48-
49-
const geoStack = backend.createStack("geo-stack");
50-
51-
// create a location services map
52-
const map = new CfnMap(geoStack, "Map", {
53-
mapName: "myMap",
54-
description: "Map",
55-
configuration: {
56-
style: "VectorEsriNavigation",
57-
},
58-
pricingPlan: "RequestBasedUsage",
59-
tags: [
60-
{
61-
key: "name",
62-
value: "myMap",
63-
},
64-
],
65-
});
66-
67-
68-
// create an IAM policy to allow interacting with geo resource
69-
const myGeoPolicy = new Policy(geoStack, "GeoPolicy", {
70-
policyName: "myGeoPolicy",
71-
statements: [
72-
new PolicyStatement({
73-
actions: [
74-
"geo:GetMapTile",
75-
"geo:GetMapSprites",
76-
"geo:GetMapGlyphs",
77-
"geo:GetMapStyleDescriptor",
78-
],
79-
resources: [map.attrArn],
80-
}),
81-
],
82-
});
83-
84-
// apply the policy to the authenticated and unauthenticated roles
85-
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
86-
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
87-
88-
// highlight-start
89-
// create a location services place index
90-
const myIndex = new CfnPlaceIndex(geoStack, "PlaceIndex", {
91-
dataSource: "Here",
92-
dataSourceConfiguration: {
93-
intendedUse: "SingleUse",
94-
},
95-
indexName: "myPlaceIndex",
96-
pricingPlan: "RequestBasedUsage",
97-
tags: [
98-
{
99-
key: "name",
100-
value: "myPlaceIndex",
101-
},
102-
],
103-
});
104-
105-
// create a policy to allow access to the place index
106-
const myIndexPolicy = new Policy(geoStack, "IndexPolicy", {
107-
policyName: "myIndexPolicy",
108-
statements: [
109-
new PolicyStatement({
110-
actions: [
111-
"geo:SearchPlaceIndexForPosition",
112-
"geo:SearchPlaceIndexForText",
113-
"geo:SearchPlaceIndexForSuggestions",
114-
"geo:GetPlace",
115-
],
116-
resources: [myIndex.attrArn],
117-
}),
118-
],
119-
});
120-
121-
// attach the policy to the authenticated and unauthenticated IAM roles
122-
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
123-
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
124-
// highlight-end
125-
126-
// patch the place index resource to the expected output configuration
127-
backend.addOutput({
128-
geo: {
129-
aws_region: geoStack.region,
130-
maps: {
131-
items: {
132-
[map.mapName]: {
133-
style: "VectorEsriNavigation",
134-
},
135-
},
136-
default: map.mapName,
137-
},
138-
// highlight-start
139-
search_indices: {
140-
default: myIndex.indexName,
141-
items: [myIndex.indexName],
142-
},
143-
// highlight-end
144-
},
63+
// highlight-next-line
64+
searchIndex
14565
});
14666
```
14767

148-
14968
## Location Search Index Pricing Plan
15069
The pricing plan for Search Index will be set to `RequestBasedUsage`.
15170
We advice you to go through the [location service pricing](https://aws.amazon.com/location/pricing/) along with the [location service terms](https://aws.amazon.com/service-terms/) (_82.5 section_) to learn more about the pricing plan.
15271

15372

154-
## Advanced Settings
73+
{/* MOVE THIS TO LEGACY RESOURCES PAGE */}
74+
{/* ## Advanced Settings
15575
You can optionally configure the data provider and result storage location for your location search index.
15676
15777
### Location Search data provider
@@ -175,4 +95,4 @@ You can specify how the results of a search operation will be stored by the call
17595
- SingleUse - specifies that the results won't be stored.
17696
- Storage - specifies that the result can be cached or stored in a database.
17797
178-
Refer [this location service doc](https://docs.aws.amazon.com/location-places/latest/APIReference/API_DataSourceConfiguration.html#locationplaces-Type-DataSourceConfiguration-IntendedUse) for more information.
98+
Refer [this location service doc](https://docs.aws.amazon.com/location-places/latest/APIReference/API_DataSourceConfiguration.html#locationplaces-Type-DataSourceConfiguration-IntendedUse) for more information. */}

0 commit comments

Comments
 (0)