Name:
interface
Value:
Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated May 14, 2024

Configure location search

Amplify's geo category enables you to search by places, addresses, and coordinates in your app with "place index" resources.

Setup a new Location Search Index

amplify/backend.ts
import { defineBackend } from "@aws-amplify/backend";
import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";
import { CfnMap, CfnPlaceIndex } from "aws-cdk-lib/aws-location";
import { auth } from "./auth/resource";
import { data } from "./data/resource";
const backend = defineBackend({
auth,
data,
// additional resources
});
const geoStack = backend.createStack("geo-stack");
// create a location services map
const map = new CfnMap(geoStack, "Map", {
mapName: "myMap",
description: "Map",
configuration: {
style: "VectorEsriNavigation",
},
pricingPlan: "RequestBasedUsage",
tags: [
{
key: "name",
value: "myMap",
},
],
});
// create an IAM policy to allow interacting with geo resource
const myGeoPolicy = new Policy(geoStack, "GeoPolicy", {
policyName: "myGeoPolicy",
statements: [
new PolicyStatement({
actions: [
"geo:GetMapTile",
"geo:GetMapSprites",
"geo:GetMapGlyphs",
"geo:GetMapStyleDescriptor",
],
resources: [map.attrArn],
}),
],
});
// apply the policy to the authenticated and unauthenticated roles
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
// create a location services place index
const myIndex = new CfnPlaceIndex(geoStack, "PlaceIndex", {
dataSource: "Here",
dataSourceConfiguration: {
intendedUse: "SingleUse",
},
indexName: "myPlaceIndex",
pricingPlan: "RequestBasedUsage",
tags: [
{
key: "name",
value: "myPlaceIndex",
},
],
});
// create a policy to allow access to the place index
const myIndexPolicy = new Policy(geoStack, "IndexPolicy", {
policyName: "myIndexPolicy",
statements: [
new PolicyStatement({
actions: [
"geo:SearchPlaceIndexForPosition",
"geo:SearchPlaceIndexForText",
"geo:SearchPlaceIndexForSuggestions",
"geo:GetPlace",
],
resources: [myIndex.attrArn],
}),
],
});
// attach the policy to the authenticated and unauthenticated IAM roles
backend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
// patch the place index resource to the expected output configuration
backend.addOutput({
geo: {
aws_region: geoStack.region,
maps: {
items: {
[map.mapName]: {
style: "VectorEsriNavigation",
},
},
default: map.mapName,
},
search_indices: {
default: myIndex.indexName,
items: [myIndex.indexName],
},
},
});

Location Search Index Pricing Plan

The pricing plan for Search Index will be set to RequestBasedUsage. We advice you to go through the location service pricing along with the location service terms (82.5 section) to learn more about the pricing plan.

Advanced Settings

You can optionally configure the data provider and result storage location for your location search index.

Location Search data provider

You can select a data provider as the source for geocoding, reverse geocoding and searches. Each provider gathers and curates their data using different means. They may also have varying expertise in different regions of the world. The available data providers of geospatial data are shown. To learn more about data providers, please refer this location service documentation.

  • Here – For additional information about HERE Technologies, see Here guide.
  • Esri – For additional information about Esri, see Esri guide.

Note: If your application is tracking or routing assets you use in your business (such as delivery vehicles or employees), you may only use HERE as your geolocation provider. See section 82 of the AWS service terms for more details.

Location Search result storage location

You can specify how the results of a search operation will be stored by the caller.

  • SingleUse - specifies that the results won't be stored.
  • Storage - specifies that the result can be cached or stored in a database.

Refer this location service doc for more information.