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
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 mapconst 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 resourceconst 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 rolesbackend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeoPolicy);
// create a location services place indexconst 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 indexconst 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 rolesbackend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myIndexPolicy);
// patch the place index resource to the expected output configurationbackend.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.
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.