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) 정책을 다음 작업에 사용할 수 있습니다.
Amazon Cognito ID 풀 생성
Amazon Cognito ID 풀을 만들어 인증되지 않은 게스트가 Amazon Cognito 콘솔AWS CLI 또는 Amazon Cognito API를 통해 애플리케이션에 액세스하는 것을 허용할 수 있습니다.
중요
생성하는 풀은 사용 중인 Amazon Location Service 리소스와 동일한 AWS 계정 및 AWS 리전에 있어야 합니다.
웹에서 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))