Page updated Jan 16, 2024

Use existing Amazon Location resources

You can also use Amplify Geo with your existing Amazon Location Service resources if you'd like, there are some manual setup that you need to do.

Authorization permissions

To use your existing Amazon Location Service resources, i.e. maps and place indices, with Amplify Geo, you need to ensure your role has the right authorization permissions through Cognito. If you set up your Cognito resources in any way other than the Amplify CLI or Amplify Studio, the roles will need to be given permission to access the map and place indices.

Note: Here is a guide on Creating an Amazon Cognito identity pool for use with Amazon Location Service

There are two roles created by Cognito: an Auth_Role that grants signed-in-user-level access and an Unauth_Role that allows unauthenticated access to resources. Attach the following policies for the appropriate resources and roles (Auth and/or Unauth). Replace {region}, {account-id}, and {enter Map/PlaceIndex name} with the correct items. Note that certain actions cannot be performed with unauthenticated access. The list of actions allowed for the Unauth role is in the Granting access to Amazon Location Service guide.

1{
2 "Version": "2012-10-17",
3 "Statement": [
4 {
5 "Sid": "GetTiles",
6 "Effect": "Allow",
7 "Action": [
8 "geo:GetMapTile",
9 "geo:GetMapSprites",
10 "geo:GetMapGlyphs",
11 "geo:GetMapStyleDescriptor"
12 ],
13 "Resource": "arn:aws:geo:{region}:{account-id}:map/{enter Map name}"
14 },
15 {
16 "Sid": "Search",
17 "Effect": "Allow",
18 "Action": [
19 "geo:SearchPlaceIndexForPosition",
20 "geo:SearchPlaceIndexForText"
21 ],
22 "Resource": "arn:aws:geo:{region}:{account-id}:place-index/{enter PlaceIndex name}"
23 }
24 ]
25}

In your application

You can first import and configure the CLI generated amplifyconfiguration.json. You can then manually configure Amplify Geo like this:

1import { Amplify } from 'aws-amplify';
2import amplifyconfig from './amplifyconfiguration.json';
3
4Amplify.configure(amplifyconfig);
5Amplify.configure({
6 ...Amplify.getConfig(),
7 Geo: {
8 LocationService: {
9 maps: {
10 items: {
11 XXXXXXXXXXX: {
12 // REQUIRED - Amazon Location Service Map resource name
13 style: 'VectorEsriStreets' // REQUIRED - String representing the style of map resource
14 }
15 },
16 default: 'XXXXXXXXXXX' // REQUIRED - Amazon Location Service Map resource name to set as default
17 },
18 search_indices: {
19 items: ['XXXXXXXXX', 'XXXXXXXXX'], // REQUIRED - Amazon Location Service Place Index name
20 default: 'XXXXXXXXX' // REQUIRED - Amazon Location Service Place Index name to set as default
21 },
22 geofenceCollections: {
23 items: ['XXXXXXXXX', 'XXXXXXXXX'], // REQUIRED - Amazon Location Service Geofence Collection name
24 default: 'XXXXXXXXX' // REQUIRED - Amazon Location Service Geofence Collection name to set as default
25 },
26 region: 'XX-XXXX-X' // REQUIRED - Amazon Location Service Region
27 }
28 }
29});

Now you can proceed to displaying a map or adding location search to your app.