- English
- 日本語
Working with KV stores
Last updated 2024-11-22
A KV store is a type of container that allows you to store data in the form of key-value pairs for use in high performance reads and writes at the edge. A single KV store can be associated with multiple Compute services in your account. Because KV stores are versionless, the data in them never expires and can be updated at any time after a KV store is created, without requiring you to increment a service's version. Also, because KV stores are stored at the edge, they allow you to offload that data from your origin and keep it closer to your end users.
You can also create and work with KV stores via the API.
Prerequisites
KV Store is only available for Fastly's Compute services, not for CDN (VCL-based) services.
Limitations and considerations
Before working with KV stores, keep the following things in mind:
- KV stores can only be used by Compute services, not CDN (VCL-based) services.
- The number of KV stores you can create is limited to your account’s available resources allotment.
When formatting your key file, keep the following things in mind:
- Key files can use any file type and have a maximum size of 25MB. This maximum can be raised to 100MB upon request. Contact your account manager or sales@fastly.com for more information.
- Keys cannot start with
.well-known/acme-challenge/
or..
. - Key names can contain any sequence of valid Unicode characters of length 1-1024 bytes when UTF-8 encoded. The following characters can be used in key names but can't be searched in a prefix query string:
!
,"
,$
,%
,&
,(
,)
,*
,+
,,
,/
,\
,:
,<
,=
,>
,@
,[
,]
,`
,{
,}
. - Keys may not be named
..
. - Keys cannot use Unicode characters 0 through 32, 65534, and 65535 as single-character key names.
The following characters are invalid and cannot be used in key names:
#
,;
,?
,^
, and|
- line feed characters
- carriage returns
WARNING
Personal information, secrets, or sensitive data should not be included in KV stores or incorporated into edge logic. In addition, we do not maintain version histories of your KV stores. Our Compliance and Law FAQ describes in detail how Fastly handles personal data privacy.
Creating a KV store
Creating a KV store requires you to create at least one key-value pair before you associate it with a service. To create a new KV store and its key-value pairs, follow these steps:
- Log in to the Fastly web interface.
- Go to Resources > KV stores.
- Click Create a KV store.
- In the Name of KV store field, enter a name for the KV store and then click Add.
TIP
KV store names have a maximum length of 255 characters and can contain letters, numbers, dashes (
-
), underscores (_
), and periods (.
) - Click Key-value pairs.
- In the Name of key field, enter a name for the first set of key-value pairs associated with your KV store.
- Upload the values for your key, clicking Browse for file to navigate to the file on your system using the file picker. Alternatively, drag and drop your key file directly into the drag and drop area below these controls.
- Click Add to the right of the key controls.
- Click Add item to continue adding additional key-value pairs as necessary.
TIP
By default, the web interface displays only the first 1,000 keys in the store. To view more keys, click the Load more keys button.
Linking KV stores to a service
Once you've added at least one key-value pair to a KV store, you can link it to a service from the Resources controls or from the service configuration for the service.
Using the Resources controls to link KV stores to a service
To link a KV store to a service from the Resources controls:
- Log in to the Fastly web interface.
Go to Resources > KV stores.
Click Link to services to the right of the store you want to link.
Select the checkbox next to any services you want to link your KV store to and then click Next.
Decide which version of the service to link to. By default, the system will assume you want to clone the most recently active version of your service. You can choose an existing draft version of the service instead by selecting it specifically from the Version menu.
Select one of the following options for linking the store to your service:
- Link only: links the store to the selected service versions but leaves any cloned or draft versions un-activated so you can activate them at a later time.
- Link and activate: links the store to the selected service versions and activates those versions at the same time.
A success message appears once the KV store is linked to the service.
Finally, do one of the following:
- Click Activate versions to activate any cloned or draft versions of services linked to the KV store.
- Click Finish to leave the cloned or draft service versions un-activated so you can make additional configuration changes to them and activate them at a later time.
You can immediately start referencing the KV store in your edge logic.
Using the service configuration to link KV stores to a service
To link a KV store to a service from the service configuration:
- Log in to the Fastly web interface.
- From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
- Click Service configuration.
- From the Resources options in the on-page navigation, click KV stores.
- From the Link KV Store to service menu, select the KV store you want to link to the service. A success message appears indicating the store is linked to your service.
Once linked, you can immediately start referencing the KV store in your edge logic and activate the service when you’re ready.
Unlinking KV stores
You can unlink a KV store from a service from the service configuration.
To unlink a KV store:
- Log in to the Fastly web interface.
- From the Home page, select the appropriate service. You can use the search box to search by ID, name, or domain.
- Click Service configuration.
- From the Resources options in the on-page navigation, click KV stores.
- Click Unlink from service next to the KV store you want to unlink from your service.
- Click Confirm and unlink. A new, draft version of the service is created.
- Activate the service to finalize unlinking the KV store.
Editing a KV store
You can edit the name of a KV store as well as the key-value pairs within the store from Resources > KV stores. You can also access this page by clicking Edit in Resources when accessing a KV store from the service configuration.
To rename a KV store:
- Click the pencil to the right of the store you want to rename.
- Enter a new name for the KV store.
- Click Save and then Confirm and rename to continue.
To add new key-value pairs to a KV store:
- Expand the Key-value pairs section.
- Under Key-value pairs, click Add item.
- Enter a key name and upload a key file that has the values and then click Add.
- Repeat for any additional key-value pairs.
To edit the key-value pairs within a KV store:
- Expand the Key-value pairs section.
- Hover your cursor over the entry you want to edit, then click Edit .
- Drag and drop your key file that has the values into the drag and drop area to upload your list of keys. Alternatively, click Browse for file to navigate to the file on your system using the file picker.
- Click Save.
The changes you make will be immediately applied to your configuration including any deployed service versions associated with the KV store.
Deleting a KV store
You can delete a KV store at any time.
Before deleting a KV store:
- Unlink the KV store from your services. If the KV store is linked to any service, an error will appear when you try to delete the store.
- Update any custom logic that references the key-value pairs in the KV store. Deleting a KV store also deletes all key-value pairs within the store.
To delete a KV store:
- Log in to the Fastly web interface.
- Go to Resources > KV stores.
- Click trash to the right of the store you want to delete.
- Click Confirm and delete.
Do not use this form to send sensitive information. If you need assistance, contact support. This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.