Amazon Location Service identity-based policy examples - Amazon Location Service

Amazon Location Service identity-based policy examples

By default, IAM users and roles don't have permission to create or modify Amazon Location resources. They also can't perform tasks using the AWS Management Console, AWS CLI, or AWS API. An IAM administrator must create IAM policies that grant users and roles permission to perform specific API operations on the specified resources they need. The administrator must then attach those policies to the IAM users or groups that require those permissions.

To learn how to create an IAM identity-based policy using these example JSON policy documents, see Creating Policies on the JSON Tab in the IAM User Guide.

Policy best practices

Identity-based policies are very powerful. They determine whether someone can create, access, or delete Amazon Location resources in your account. These actions can incur costs for your AWS account. When you create or edit identity-based policies, follow these guidelines and recommendations:

  • Get started using AWS managed policies – To start using Amazon Location quickly, use AWS managed policies to give your employees the permissions they need. These policies are already available in your account and are maintained and updated by AWS. For more information, see Get started using permissions with AWS managed policies in the IAM User Guide.

  • Grant least privilege – When you create custom policies, grant only the permissions required to perform a task. Start with a minimum set of permissions and grant additional permissions as necessary. Doing so is more secure than starting with permissions that are too lenient and then trying to tighten them later. For more information, see Grant least privilege in the IAM User Guide.

  • Enable MFA for sensitive operations – For extra security, require IAM users to use multi-factor authentication (MFA) to access sensitive resources or API operations. For more information, see Using multi-factor authentication (MFA) in AWS in the IAM User Guide.

  • Use policy conditions for extra security – To the extent that it's practical, define the conditions under which your identity-based policies allow access to a resource. For example, you can write conditions to specify a range of allowable IP addresses that a request must come from. You can also write conditions to allow requests only within a specified date or time range, or to require the use of SSL or MFA. For more information, see IAM JSON policy elements: Condition in the IAM User Guide.

Allow users to view their own permissions

This example shows how you might create a policy that allows IAM users to view the inline and managed policies that are attached to their user identity. This policy includes permissions to complete this action on the console or programmatically using the AWS CLI or AWS API.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "ViewOwnUserInfo", "Effect": "Allow", "Action": [ "iam:GetUserPolicy", "iam:ListGroupsForUser", "iam:ListAttachedUserPolicies", "iam:ListUserPolicies", "iam:GetUser" ], "Resource": [ "arn:aws:iam::*:user/${aws:username}" ] }, { "Sid": "NavigateInConsole", "Effect": "Allow", "Action": [ "iam:GetGroupPolicy", "iam:GetPolicyVersion", "iam:GetPolicy", "iam:ListAttachedGroupPolicies", "iam:ListGroupPolicies", "iam:ListPolicyVersions", "iam:ListPolicies", "iam:ListUsers" ], "Resource": "*" } ] }

Permissions required to use the Amazon Location console

To access the Amazon Location Service console, and be able to create, delete, list and view details about Amazon Location resources in your AWS account, you will need to grant permission to access all Amazon Location resources. For more information, see Adding Permissions to a User in the IAM User Guide.

To grant permission to access to all Amazon Location resources for the Amazon Location Service console:

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GeoPowerUser", "Effect": "Allow", "Action": [ "geo:*" ], "Resource": "*" } ] }

Alternatively, you can grant read-only permissions to facilitate read-only access. With read-only permissions, an error message will appear if the user attempts write actions such as creating or deleting resources. As an example, see Read-only policy for tracker resources

Permissions for updating device positions

To update device positions for multiple trackers, you'll want to grant an IAM user in your AWS account access to one or more of your tracker resources. You will also want to allow the user to update a batch of device positions.

In this example, in addition to granting access to the Tracker1 and Tracker2 resources, the following policy grants permission to use the geo:BatchUpdateDevicePosition action against the Tracker1 and Tracker2 resources.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "UpdateDevicePositions", "Effect": "Allow", "Action": [ "geo:BatchUpdateDevicePosition" ], "Resource": [ "arn:aws:geo:us-west-2:account-id:tracker/Tracker1", "arn:aws:geo:us-west-2:account-id:tracker/Tracker2" ] } ] }

Read-only policy for tracker resources

To create a read-only policy for all tracker resources in your AWS account, you'll need to grant access to all tracker resources. You'll also want to grant an IAM user access to actions that allow them to get the device position for multiple devices, get the device position from a single device and get the position history.

In this example, the following policy grants permission to the following actions:

  • geo:BatchGetDevicePosition to retrieve the position of multiple devices.

  • geo:GetDevicePosition to retrieve the position of a single device.

  • geo:GetDevicePositionHistory to retrieve the position history of a device.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetDevicePositions", "Effect": "Allow", "Action": [ "geo:BatchGetDevicePosition", "geo:GetDevicePosition", "geo:GetDevicePositionHistory" ], "Resource": "arn:aws:geo:us-west-2:account-id:tracker/*" } ] }

Policy for creating geofences

To create a policy to allow an IAM user to create geofences, you'll need to grant access to specific actions that allow users to create one or more geofences on a geofence collection.

The policy below grants permission to the following actions on Collection:

  • geo:BatchPutGeofence to create multiple geofences.

  • geo:PutGeofence to create a single geofence.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "CreateGeofences", "Effect": "Allow", "Action": [ "geo:BatchPutGeofence", "geo:PutGeofence" ], "Resource": "arn:aws:geo:us-west-2:account-id:geofence-collection/Collection" } ] }

Read-only policy for geofences

To create a read-only policy for geofences stored in a geofence collection in your AWS account, you'll need to grant access to actions that read from the geofence collection storing the geofences.

The policy below grants permission to the following actions on Collection:

  • geo:ListGeofences to list geofences in the specified geofence collection.

  • geo:GetGeofence to retrieve a geofence from the geofence collection.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetGeofences", "Effect": "Allow", "Action": [ "geo:ListGeofences", "geo:GetGeofence" ], "Resource": "arn:aws:geo:us-west-2:account-id:geofence-collection/Collection" } ] }

Permissions for rendering a map resource

To grant sufficient permissions to render maps, you'll need to grant access to map tiles, sprites, glyphs, and the style descriptor:

  • geo:GetMapTile retrieves map tiles used to selectively render features on a map.

  • geo:GetMapSprites retrieves the PNG sprite sheet and corresponding JSON document describing offsets within it.

  • geo:GetMapGlyphs retrieves the glyphs used for displaying text.

  • geo:GetMapStyleDescriptor retrieves the map’s style descriptor, containing rendering rules.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "GetTiles", "Effect": "Allow", "Action": [ "geo:GetMapTile", "geo:GetMapSprites", "geo:GetMapGlyphs", "geo:GetMapStyleDescriptor" ], "Resource": "arn:aws:geo:us-west-2:account-id:map/Map" } ] }

Permissions to allow search operations

To create a policy to allow search operations, you'll first need to grant access to the place index resource in your AWS account. You'll also want to grant access to actions that let the IAM user search using text by geocoding and search using a position by reverse geocoding.

In this example, in addition to granting access to PlaceIndex, the following policy also grants permission to the following actions:

  • geo:SearchPlaceIndexForPosition allows you to search for places, or points of interest near a given position.

  • geo:SearchPlaceIndexForText allows you to search for an address, name, city or region using free-form text.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "Search", "Effect": "Allow", "Action": [ "geo:SearchPlaceIndexForPosition", "geo:SearchPlaceIndexForText" ], "Resource": "arn:aws:geo:us-west-2:account-id:place-index/PlaceIndex" } ] }

Read-only policy for route calculators

You can create a read-only policy to allow an IAM user access to a route calculator resource to calculate a route.

In this example, in addition to granting access to ExampleCalculator, the following policy grants permission to the following operation:

  • geo:CalculateRoute calculates a route given a departure position, destination positon, and a list of waypoint positions.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "RoutesReadOnly", "Effect": "Allow", "Action": [ "geo:CalculateRoute" ], "Resource": "arn:aws:geo:us-west-2:accountID:route-calculator/ExampleCalculator" } ] }

Control resource access based on tags

When you create an IAM policy to grant access to use your Amazon Location resources, you can use attribute-based access control for better control over which resources a user can modify, use, or delete. You can do this by including tag information in the Condition element of your policy to control access based on your resource tags.

The following example policy shows how you might create a policy that allows an IAM user to create geofences. This grants the permission to the following actions to create one or more geofences on a geofence collection called Collection:

  • geo:BatchPutGeofence to create multiple geofences.

  • geo:PutGeofence to create a single geofence.

However, this policy uses the Condition element to grant the permission only if the Collection tag, Owner, has the value of that user's user name.

  • For example, if a user named richard-roe attempts to view an Amazon Location Collection, the Collection must be tagged Owner=richard-roe or owner=richard-roe. Otherwise the user is denied access.

    Note

    The condition tag key Owner matches both Owner and owner because condition key names are not case-sensitive. For more information, see IAM JSON Policy Elements: Condition in the IAM User Guide.

{ "Version": "2012-10-17", "Statement": [ { "Sid": "CreateGeofencesIfOwner", "Effect": "Allow", "Action": [ "geo:BatchPutGeofence", "geo:PutGeofence" ], "Resource": "arn:aws:geo:us-west-2:account-id:geofence-collection/Collection", "Condition": { "StringEquals": {"geo:ResourceTag/Owner": "${aws:username}"} } } ] }

For a tutorial about how to define permissions to access AWS resources based on tags, see the AWS Identity and Access Management User Guide.