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>" } ]}