Put and get values from Cloudflare KV.
Create an API Token with Workers KV Storage permissions.
- name: cloudflare-kv-action
uses: zentered/cloudflare-kv-action@v2
id: cloudflare_kv
env:
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
with:
namespace_identifier: '123'
key_name: 'hello'
value: 'world'
expiration_ttl: 120
- name: Value
run: echo "${{ steps.cloudflare_kv.outputs.value }}"- name: cloudflare-kv-action
uses: zentered/cloudflare-kv-action@v2
id: cloudflare_kv
env:
CLOUDFLARE_API_KEY: ${{ secrets.CLOUDFLARE_API_KEY }}
CLOUDFLARE_ACCOUNT_EMAIL: ${{ secrets.CLOUDFLARE_ACCOUNT_EMAIL }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
with:
namespace_identifier: '123'
key_name: 'hello'
value: 'world'
expiration_ttl: 120
- name: Value
run: echo "${{ steps.cloudflare_kv.outputs.value }}"In the repository, go to "Settings", then "Secrets" and add your Cloudflare credentials. You can retrieve them on your Cloudflare account.
| Variable | Required | Description |
|---|---|---|
CLOUDFLARE_ACCOUNT_ID |
required | From the URL: https://dash.cloudflare.com/123abc.... |
CLOUDFLARE_API_KEY |
required | API Token (Bearer) or Global API Key (legacy) |
CLOUDFLARE_ACCOUNT_EMAIL |
optional | Required only for legacy API Key auth |
| Name | Requirement | Description |
|---|---|---|
namespace_identifier |
required | Cloudflare namespace ID |
key_name |
required | KV key name |
value |
optional | Use "value" to set a key; omit to retrieve the current value |
expiration |
optional | Absolute expiration (Unix timestamp) |
expiration_ttl |
optional | Relative expiration in seconds. If both expiration and expiration_ttl are set, expiration takes precedence. |
| Name | Description |
|---|---|
value |
KV value |
Requirements: Node >= 20
# Install dependencies
npm install
# Copy and fill in your Cloudflare credentials
cp .env.example .env
# Run linter
npm run lint
# Run tests (unit tests run without credentials; integration tests require .env)
npm test
# Rebuild dist/ after code changes
npm run prepareSee CONTRIBUTING.
See LICENSE.