Use existing Amazon Location resources
To use existing Amazon Location Services resources with your Amplify backend or frontend application, use the addOutput
method to surface backend resource outputs to the amplify_outputs.json
file:
import { defineBackend } from "@aws-amplify/backend"
const backend = defineBackend({})
backend.addOutput({ geo: { aws_region: "<your-aws-region>", maps: { items: { "<your-friendly-map-name>": { name: "<your-map-name>", style: "<your-map-style>", }, }, default: "<your-friendly-map-name>", }, },})
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.
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 "authenticated role" that grants signed-in-user-level access and an "unauthenticated 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.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetTiles", "Effect": "Allow", "Action": [ "geo:GetMapTile", "geo:GetMapSprites", "geo:GetMapGlyphs", "geo:GetMapStyleDescriptor" ], "Resource": "arn:aws:geo:<your-geo-region>:<your-account-id>:map/<your-map-name>" }, { "Sid": "Search", "Effect": "Allow", "Action": [ "geo:SearchPlaceIndexForPosition", "geo:SearchPlaceIndexForText" ], "Resource": "arn:aws:geo:<your-geo-region>:<your-account-id>:place-index/<your-index-name>" }, { "Sid": "Geofence", "Effect": "Allow", "Action": [ "geo:GetGeofence", "geo:PutGeofence", "geo:BatchPutGeofence", "geo:BatchDeleteGeofence", "geo:ListGeofences", ], "Resource": "arn:aws:geo:<your-geo-region>:<your-account-id>:geofence-collection/<your-collection-name>" } ]}
Configure client library directly
You can first import and configure the generated amplify_outputs.json
. You can then manually configure Amplify Geo like this:
import { Amplify } from 'aws-amplify';import outputs from '../amplify_outputs.json';
Amplify.configure(outputs);Amplify.configure({ ...Amplify.getConfig(), Geo: { LocationService: { maps: { items: { <your-map-name>: { // REQUIRED - Amazon Location Service Map resource name style: 'VectorEsriStreets' // REQUIRED - String representing the style of map resource } }, default: '<your-preferred-default-map>' // REQUIRED - Amazon Location Service Map resource name to set as default }, search_indices: { items: ['<your-geo-index>'], // REQUIRED - Amazon Location Service Place Index name default: '<your-default-index>' // REQUIRED - Amazon Location Service Place Index name to set as default }, geofenceCollections: { items: ['<your-geo-collection>'], // REQUIRED - Amazon Location Service Geofence Collection name default: '<your-default-collection>' // REQUIRED - Amazon Location Service Geofence Collection name to set as default }, region: '<your-geo-region>' // REQUIRED - Amazon Location Service Region } }});
Now you can proceed to displaying a map or adding location search to your app.