Amazon Cognito를 사용하여 인증 - Amazon Location Service

Amazon Cognito를 사용하여 인증

프론트엔드 SDK 요청에서 AWS Identity and Access Management(IAM) 사용자를 직접 사용하는 대신 Amazon Cognito 인증을 사용할 수 있습니다.

Amazon Cognito는 웹 및 모바일 앱에 대한 인증, 권한 부여 및 사용자 관리를 제공합니다. Amazon Location과 함께 Amazon Cognito 비인증 자격 증명 풀을 애플리케이션에서 범위가 축소된 임시 AWS자격 증명을 검색하는 방법으로 사용할 수 있습니다.

자세한 내용은 Amazon Cognito 개발자 안내서사용자 풀 시작하기를 참조하세요.

다음과 같은 이유로 이 인증 형식을 사용하는 것이 좋습니다.

  • 인증되지 않은 사용자 – 익명 사용자가 있는 웹 사이트가 있는 경우 Amazon Cognito 자격 증명 풀을 사용할 수 있습니다.

    자세한 내용은 Amazon Cognito를 사용하여 인증 섹션을 참조하세요.

  • 자체 인증 – 자체 인증 프로세스를 사용하거나 여러 인증 방법을 결합하려는 경우 Amazon Cognito 페더레이션 ID를 사용할 수 있습니다.

    자세한 내용은 Amazon Cognito 개발자 안내서페더레이션 ID 시작하기를 참조하세요.

Amazon Cognito 및 Amazon Location Service 사용

인증되지 않은 자격 증명 역할과 연결된 AWS Identity and Access Management(IAM) 정책을 다음 작업에 사용할 수 있습니다.

Maps

맵 작업의 목록

  • geo-maps:GetStaticMap

  • geo-maps:GetTile

참고

위 작업의 리소스 이름은 다음과 같습니다.

arn:aws:geo-maps:region::provider/default
Places

장소 작업의 목록:

  • geo-places:Geocode

  • geo-places:ReverseGeocode

  • geo-places:SearchNearby

  • geo-places:SearchText

  • geo-places:Autocomplete

  • geo-places:Suggest

  • geo-places:GetPlace

참고

위 작업의 리소스 이름은 다음과 같습니다.

arn:aws:geo-places:region::provider/default
Routes

경로 작업의 목록:

  • geo-routes:CalculateRoutes

  • geo-routes:CalculateRouteMatrix

  • geo-routes:CalculateIsolines

  • geo-routes:OptimizeWaypoints

  • geo-routes:SnapToRoads

참고

위 작업의 리소스 이름은 다음과 같습니다.

arn:aws:geo-routes:region::provider/default
Geofences and Trackers

지오펜스 및 트래커 작업의 목록

  • geo:GetGeofence

  • geo:ListGeofences

  • geo:PutGeofence

  • geo:BatchDeleteGeofence

  • geo:BatchPutGeofence

  • geo:BatchEvaluateGeofences

  • geo:GetDevicePosition*

  • geo:ListDevicePositions

  • geo:BatchDeleteDevicePositionHistory

  • geo:BatchGetDevicePosition

  • geo:BatchUpdateDevicePosition

참고

위 작업의 리소스 이름은 다음과 같습니다.

arn:aws:geo:region:accountID:tracker/ExampleTracker
Previous version

이전 버전 작업의 목록:

  • geo:GetMap*

  • geo:SearchPlaceIndexForText

  • geo:SearchPlaceIndexForPosition

  • geo:GetPlace

  • geo:CalculateRoute

  • geo:CalculateRouteMatrix

참고

위 작업의 리소스 이름은 다음과 같습니다.

Maps

arn:aws:geo:region:accountID:map/ExampleMap

Places

arn:aws:geo:region:accountID:place-index/ExamplePlaceIndex

Routes

arn:aws:geo:region:accountID:route-calculator/ExampleCalculator

Amazon Cognito ID 풀 생성

Amazon Cognito ID 풀을 만들어 인증되지 않은 게스트가 Amazon Cognito 콘솔AWS CLI 또는 Amazon Cognito API를 통해 애플리케이션에 액세스하는 것을 허용할 수 있습니다.

중요

생성하는 풀은 사용 중인 Amazon Location Service 리소스와 동일한 AWS 계정 및 AWS 리전에 있어야 합니다.

Console

Amazon Cognito 콘솔을 사용하여 자격 증명 풀을 만들려면

  1. Amazon Cognito 콘솔로 이동합니다.

  2. 자격 증명 풀 관리를 선택합니다.

  3. 새 자격 증명 풀 생성을 선택한 다음 ID 풀의 이름을 입력합니다.

  4. 축소 가능한 인증되지 않은 자격 증명 섹션에서 인증되지 않은 자격 증명에 대한 액세스 활성화를 선택합니다.

  5. 풀 생성을 선택합니다.

  6. ID 풀에서 사용하려는 IAM 역할을 선택합니다.

  7. 세부 정보 보기를 확장합니다.

  8. 인증되지 않은 ID에서 역할 이름을 입력합니다.

  9. 정책 문서 보기 섹션을 확장한 다음, 정책을 추가하기 위해 편집을 선택합니다.

  10. 정책을 추가하여 리소스에 대한 액세스 권한을 부여합니다.

    참고

    작업 목록은 위의 Amazon Cognito 및 Amazon Location Service 사용 섹션을 참조하세요.

    { "Version": "2012-10-17", "Statement": [ { Sid": "RoutesReadOnly", Effect": "Allow", Action": [ // add comma separated value from the previous section ], Resource": "value from previous section" } ] }
  11. 허용를 선택하여 ID 풀을 생성하세요.

웹에서 Amazon Cognito ID 풀 사용

다음 예제에서는 생성한 인증되지 않은 ID 풀을 자격 증명으로 교환한 다음 이 자격 증명을 사용하여 CalculateIsolines를 호출합니다. 이 작업을 단순화하기 위해 이 예제에서는 Amazon Location 인증 도우미 사용 방법 프로시저를 사용합니다. 이는 자격 증명을 가져오고 새로 고치는 작업을 모두 대신합니다.

이 예제에서는 JavaScript v3용 AWS SDK를 사용합니다.

import { GeoRoutesClient, CalculateIsolinesCommand , } from "@aws-sdk/client-geo-routes"; // ES Modules import import { withIdentityPoolId } from "@aws/amazon-location-utilities-auth-helper"; const identityPoolId = "<identity pool ID>"; // for example, us-east-1:1sample4-5678-90ef-aaaa-1234abcd56ef const authHelper = await withIdentityPoolId(identityPoolId); const client = new GeoRoutesClient({ ...authHelper.getClientConfig(), region: "<region>", // The region containing the identity pool }); const input = { DepartNow: true, TravelMode: "Car", Origin: [-123.12327, 49.27531], Thresholds: { Time: [5, 10, 30], }, }; const command = new CalculateIsolinesCommand(input); const response = await client.send(command); console.log(JSON.stringify(response, null, 2))