是否可以对 AWS Location 'Places' API 进行未经身份验证的访问?
Is unauthenticated access to AWS Location 'Places' API possible?
我刚刚开始使用 Amazon Location Services,我知道它最近才发布。我已经创建了我的第一张地图,并且可以作为未经身份验证的用户正常访问它。但是,我现在正在尝试添加地理编码功能,但我不清楚如何授予对 'places' API 的未经身份验证的访问权限(或者是否可能)。该文档明确涵盖了授予对地图的未经身份验证的访问权限,但它对地点的这个主题保持沉默。
我尝试了一个简单的 POST 到 https://places.geo.eu-west-1.amazonaws.com/places/v0/indexes//search/text,但我收到了 HTTP 403 响应。
明确地说,API 我试图以未经身份验证的用户身份访问在此处讨论:https://docs.aws.amazon.com/location/latest/developerguide/search-place-index-geocode.html
是否可以从 AWS 位置服务对 'Places API' 进行未经身份验证的访问?
对于以后阅读本文的任何人,我最终使它正常工作,但是伙计,这很痛苦!我知道 Amazon Location 是新的,但是文档很差。
首先,您需要创建一个可以访问 'places' 资源的未经身份验证的身份池。 https://docs.aws.amazon.com/location/latest/developerguide/tutorial-mapbox.html 上的地图对此进行了记录,但地方 API.
上没有类似的文档
我创建了一个包含地图和地点的单一身份池:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "MapsReadOnly",
"Effect": "Allow",
"Action": [
"geo:GetMapStyleDescriptor",
"geo:GetMapGlyphs",
"geo:GetMapSprites",
"geo:GetMapTile"
],
"Resource": "arn:aws:geo:eu-west-1:XXXXXXXXXX:map/mapdemo"
},
{
"Sid": "PlacesReadOnly",
"Effect": "Allow",
"Action": [
"geo:SearchPlaceIndex*"
],
"Resource": "arn:aws:geo:eu-west-1:XXXXXXXXX:place-index/placedemo"
}
]
}
仅此还不够。您需要使用 Amazon 的 cognito 库对 HTTP 请求进行签名。同样,https://docs.aws.amazon.com/location/latest/developerguide/tutorial-mapbox-gl-js.html 中的 transformRequest 函数给出了如何为他们的地图执行此操作的示例,但地方 API.
没有这样的事情
您可能认为它们是一样的,但您错了。因为'places'请求是POST,所以签名机制不同(需要对URL、方法和请求体进行签名)。所以更新后的 transformRequest 函数如下所示:
function transformRequest(url, resourceType, body) {
if (resourceType === "Style" && !url.includes("://")) {
// resolve to an AWS URL
url = `https://maps.geo.${AWS.config.region}.amazonaws.com/maps/v0/maps/${url}/style-descriptor`;
}
if (url.includes("amazonaws.com")) {
// There's two types of Amazon requests at play here. Tile requests are GET, but place requests
// (geocoding) are POSTs. When doing a POST request, you need to pass up the POST verb, _and_ the
// POST body to the AWS request signer.
return {
url: Signer.signUrl({
url: url,
method: url.includes("places.geo") ? "POST" : "GET",
body: url.includes("places.geo") ? body : undefined
},
{
access_key: credentials.accessKeyId,
secret_key: credentials.secretAccessKey,
session_token: credentials.sessionToken,
}),
};
}
完成所有这些后,您仍然需要在前端运行地理编码客户端库。我最终修改了 Mapbox GL Geocoder。 Mapbox GL Geocoder 已经支持 'externalGeocoder' 选项,可用于插入 AWS 的 Places API.
如果亚马逊包含一个示例,说明如何在客户端使用地点 API,就像他们使用地图一样。
我刚刚开始使用 Amazon Location Services,我知道它最近才发布。我已经创建了我的第一张地图,并且可以作为未经身份验证的用户正常访问它。但是,我现在正在尝试添加地理编码功能,但我不清楚如何授予对 'places' API 的未经身份验证的访问权限(或者是否可能)。该文档明确涵盖了授予对地图的未经身份验证的访问权限,但它对地点的这个主题保持沉默。
我尝试了一个简单的 POST 到 https://places.geo.eu-west-1.amazonaws.com/places/v0/indexes//search/text,但我收到了 HTTP 403 响应。
明确地说,API 我试图以未经身份验证的用户身份访问在此处讨论:https://docs.aws.amazon.com/location/latest/developerguide/search-place-index-geocode.html
是否可以从 AWS 位置服务对 'Places API' 进行未经身份验证的访问?
对于以后阅读本文的任何人,我最终使它正常工作,但是伙计,这很痛苦!我知道 Amazon Location 是新的,但是文档很差。
首先,您需要创建一个可以访问 'places' 资源的未经身份验证的身份池。 https://docs.aws.amazon.com/location/latest/developerguide/tutorial-mapbox.html 上的地图对此进行了记录,但地方 API.
上没有类似的文档我创建了一个包含地图和地点的单一身份池:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "MapsReadOnly",
"Effect": "Allow",
"Action": [
"geo:GetMapStyleDescriptor",
"geo:GetMapGlyphs",
"geo:GetMapSprites",
"geo:GetMapTile"
],
"Resource": "arn:aws:geo:eu-west-1:XXXXXXXXXX:map/mapdemo"
},
{
"Sid": "PlacesReadOnly",
"Effect": "Allow",
"Action": [
"geo:SearchPlaceIndex*"
],
"Resource": "arn:aws:geo:eu-west-1:XXXXXXXXX:place-index/placedemo"
}
]
}
仅此还不够。您需要使用 Amazon 的 cognito 库对 HTTP 请求进行签名。同样,https://docs.aws.amazon.com/location/latest/developerguide/tutorial-mapbox-gl-js.html 中的 transformRequest 函数给出了如何为他们的地图执行此操作的示例,但地方 API.
没有这样的事情您可能认为它们是一样的,但您错了。因为'places'请求是POST,所以签名机制不同(需要对URL、方法和请求体进行签名)。所以更新后的 transformRequest 函数如下所示:
function transformRequest(url, resourceType, body) {
if (resourceType === "Style" && !url.includes("://")) {
// resolve to an AWS URL
url = `https://maps.geo.${AWS.config.region}.amazonaws.com/maps/v0/maps/${url}/style-descriptor`;
}
if (url.includes("amazonaws.com")) {
// There's two types of Amazon requests at play here. Tile requests are GET, but place requests
// (geocoding) are POSTs. When doing a POST request, you need to pass up the POST verb, _and_ the
// POST body to the AWS request signer.
return {
url: Signer.signUrl({
url: url,
method: url.includes("places.geo") ? "POST" : "GET",
body: url.includes("places.geo") ? body : undefined
},
{
access_key: credentials.accessKeyId,
secret_key: credentials.secretAccessKey,
session_token: credentials.sessionToken,
}),
};
}
完成所有这些后,您仍然需要在前端运行地理编码客户端库。我最终修改了 Mapbox GL Geocoder。 Mapbox GL Geocoder 已经支持 'externalGeocoder' 选项,可用于插入 AWS 的 Places API.
如果亚马逊包含一个示例,说明如何在客户端使用地点 API,就像他们使用地图一样。