Looking for how to use this in your app?See Frontend Libraries →
ジオフェンスコレクションの設定
ジオフェンスは、実世界の地理的領域の仮想的な周囲です。ジオフェンスには、閉じた境界を形成する点または頂点が含まれており、関心のある領域を定義します。ジオフェンスコレクションは、1つ以上のジオフェンスを保存します。
新しいジオフェンスコレクションをセットアップする
amplify/backend.ts
import { defineBackend } from "@aws-amplify/backend";import { Policy, PolicyStatement } from "aws-cdk-lib/aws-iam";import { CfnGeofenceCollection } 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 geofence collectionconst myGeofenceCollection = new CfnGeofenceCollection( geoStack, "GeofenceCollection", { collectionName: "myGeofenceCollection", pricingPlan: "RequestBasedUsage", tags: [ { key: "name", value: "myGeofenceCollection", }, ], });
// create an IAM policy to allow interacting with geofence collection resourceconst myGeofenceCollectionPolicy = new Policy( geoStack, "GeofenceCollectionPolicy", { policyName: "myGeofenceCollectionPolicy", statements: [ new PolicyStatement({ actions: [ "geo:GetGeofence", "geo:PutGeofence", "geo:BatchPutGeofence", "geo:BatchDeleteGeofence", "geo:ListGeofences", ], resources: [myGeofenceCollection.attrArn], }), ], });
// apply the policy to the authenticated and unauthenticated rolesbackend.auth.resources.authenticatedUserIamRole.attachInlinePolicy(myGeofenceCollectionPolicy);backend.auth.resources.unauthenticatedUserIamRole.attachInlinePolicy(myGeofenceCollectionPolicy);
// patch the geofence collection resource to the expected output configurationbackend.addOutput({ geo: { geofence_collections: { default: myGeofenceCollection.collectionName, items: [myGeofenceCollection.collectionName], }, },});ジオフェンスコレクションの料金プラン
ジオフェンスコレクションの料金プランは RequestBasedUsage に設定されます。料金プランの詳細については、ロケーションサービスの料金およびロケーションサービスの利用規約(82.5 セクション)をご確認いただくことをお勧めします。
グループアクセス
Cognito ユーザーグループに基づいてアクセス権限を制限するには
- Cognito ユーザープールグループを作成する
amplify/auth/resource.ts
import { defineAuth } from '@aws-amplify/backend';
export const auth = defineAuth({ loginWith: { email: true, }, groups: ["User"],});- Cognito ユーザープールグループロールに権限を追加する
amplify/backend.ts
const myGeofenceCollectionPolicy = new Policy( geoStack, "GeofenceCollectionPolicy", { policyName: "myGeofenceCollectionPolicy", statements: [ new PolicyStatement({ actions: [ "geo:GetGeofence", "geo:PutGeofence", "geo:BatchPutGeofence", "geo:BatchDeleteGeofence", "geo:ListGeofences", ], resources: [myGeofenceCollection.attrArn], }), ], });
backend.auth.resources.groups["User"].role.attachInlinePolicy(myGeofenceCollectionPolicy);注:
認証/ゲストユーザーアクセスと個別グループアクセスを組み合わせた場合、グループのメンバーであるユーザーには、認証ユーザーの権限ではなく、グループの権限のみが付与されます。権限はコレクション内のすべてのジオフェンスに適用されます。例えば、UserCognito グループにListGeofencesやGetGeofenceなどの読み取り権限を追加した場合、そのグループに追加されたすべてのユーザーは、そのジオフェンスコレクション内のすべてのジオフェンスのプロパティを読み取ることができます。
AWS SDK for JavaScript を使用する
または、AWS SDK for JavaScript を使用してプログラムで既存の Cognito ユーザープールグループにユーザーを追加したい場合は、API ドキュメントを参照してください。