Note
API keys are available to use only with map, place, and route resources, and you can't modify or create those resources. If your application needs access to other resources or actions for unauthenticated users, you can use Amazon Cognito to provide access along with, or instead of, API keys. For more information, see Use Amazon Cognito to authenticate.
API keys are a key value that is associated with specific Amazon Location Service resources or API in your AWS account, and specific actions that you can perform on those resources. You can use an API key in your application to make unauthenticated calls to the Amazon Location APIs for those resources.
For example, if you associate an API key with a resource and/or the
GetPlace*
API, then an application that uses that API key will be able
to call specific APIs. That same API key would not give permissions to change or update
any resource or call APIs that it isn't associated with.
When you call Amazon Location Service APIs in your applications, you typically make this call as an authenticated user who is authorized to make the API calls. However, there are some cases where you don't want to authenticate every user of your application.
For example, you might want a web application that shows your business location to be available to anyone using the website, whether they are logged in or not. In this case, one alternative is to use API keys to make the API calls.
See API key best practices for additional information about when to use API keys.
Create an API key for Amazon Location Service
You can create an API key through the Amazon Location Service console, AWS CLI, or Amazon Location API. Continue with the appropriate procedures below.
To create an API key using the Amazon Location Service console
-
In the Amazon Location console
, choose API keys from the left menu. -
On the API keys page, choose Create API key.
-
On the Create API key page, fill in the following information:
-
Name – A name for your API key, such as
ExampleKey
. -
Description – An optional description for your API key.
-
Resources – In the dropdown, choose the Amazon Location resources to give access to with this API key. You can add more than one resource by choosing Add resource.
-
Actions – Specify the actions you want to authorize with this API key. You must select at least one action to match each resource type you have selected. For example, if you selected a place resource, you must select at least one of the choices under Places Actions.
-
Expiration time – Optionally, add an expiration date and time for your API key. For more information, see API key best practices.
-
Referrers – Optionally, add one or more domains where you can use the API key. For example, if the API key is to allow an application running on the website
example.com
, then you could put*.example.com/
as an allowed referrer. -
Tags – Optionally, add tags to the API key.
-
-
Choose Create API key to create the API key.
-
On the detail page for the API key, you can see information about the API key that you have created. Choose Show API key to see the key value that you use when calling Amazon Location APIs. The key value will have the format
v1.public.
.a1b2c3d4...
Use an API key to call an Amazon Location
API
After you create an API key, you can use the key value to make calls to Amazon Location APIs in your application.
The APIs that support API keys have an additional parameter that takes
the API key value. For example, if you call the GetPlace
API, you can fill in the key parameter, as follows
curl --request GET —url 'https://places.geo.eu-central-1.amazonaws.com/v2/place/{
PLACEID
}?key={APIKEY
}&language=jp'
API key best practices
API keys include a plain text value that gives access to one or more resources or APIs in your AWS account. If someone copies your API key, they can access those same resources and APIs. To minimize the potential impact, review the following best practices:
-
Limit the API key
To avoid the situation above, it is best to limit your API key. When you create the key, you can specify the domain or referrer where the key can be used.
-
Manage API key lifetimes
You can create API keys that work indefinitely. However, if you want to create a temporary API key, rotate API keys on a regular basis, or revoke an existing API key, you can use API key expiration.
-
You can set the expiration time for an API key when you create or update it.
-
When an API key reaches its expiration time, the key is automatically deactivated. Inactive keys can no longer be used to make requests.
-
You can change a temporary key to a permanent key by removing the expiration time.
-
You can delete an API key 90 days after deactivating it.
-
If you attempt to deactivate an API key that has been used within the last seven days, you'll be prompted to confirm that you want to make the change.
If you are using the Amazon Location Service API or the AWS CLI, set the
ForceUpdate
parameter totrue
, otherwise you'll receive an error.
-