# Scale with the Cloud API

This page demonstrates how to use the Aerospike Cloud API to scale your cluster. You will manually invoke the API to verify it works.

One approach to automate scaling is to connect a Grafana webhook contact point to a serverless function (such as AWS Lambda) that calls this API when alerts fire.

## Prerequisites

-   An API key (ID and secret) for the Aerospike Cloud API. See [Create an API key](https://aerospike.com/docs/cloud/manage-apis/cloud-api-use). Save the secret when created - it’s only shown once.
-   Your cluster ID from the Cloud Console.

## Generate an API token

The Cloud API uses OAuth2. First, exchange your API key credentials for a bearer token.

1.  Set your API key credentials:
    
    Terminal window
    
    ```shell
    export AEROSPIKE_API_KEY_ID="YOUR_KEY_ID"
    
    export AEROSPIKE_API_KEY_SECRET="YOUR_KEY_SECRET"
    
    export AEROSPIKE_CLUSTER_ID="YOUR_CLUSTER_ID"
    ```
    
    Replace the values with your API key ID, secret, and cluster ID from the Cloud Console.
    
2.  Generate a bearer token:
    
    Terminal window
    
    ```shell
    export AEROSPIKE_API_TOKEN=$(curl -s --request POST \
    
      'https://auth.control.aerospike.cloud/oauth/token' \
    
      --header 'Content-Type: application/json' \
    
      --data "{\"client_id\":\"$AEROSPIKE_API_KEY_ID\",\"client_secret\":\"$AEROSPIKE_API_KEY_SECRET\",\"grant_type\":\"client_credentials\"}" | jq -r '.access_token')
    ```
    
3.  Verify the token was generated:
    
    Terminal window
    
    ```shell
    echo $AEROSPIKE_API_TOKEN
    ```
    
    You should see a long JSON Web Token (JWT) string starting with `eyJ...`.
    

## Get your cluster details

1.  Retrieve your cluster details:
    
    Terminal window
    
    ```shell
    curl -s "https://api.aerospike.com/v1/database/clusters/$AEROSPIKE_CLUSTER_ID" \
    
      -H "Authorization: Bearer $AEROSPIKE_API_TOKEN" | jq '{
    
        clusterSize: .aerospikeCloud.clusterSize,
    
        replicationFactor: .aerospikeServer.namespaces[0]["replication-factor"]
    
      }'
    ```
    
    ```json
    {
    
      "clusterSize": 4,
    
      "replicationFactor": 2
    
    }
    ```
    
    Expected result
    

## Scale your cluster

Cost consideration

Scaling up increases your Aerospike Cloud costs. For this tutorial, you will scale up briefly and then scale back down to minimize additional charges.

Entitlements required

Scaling requires sufficient node entitlements in your Aerospike Cloud subscription. If you receive an error about entitlements, your account may not have capacity for additional nodes. Contact your Aerospike account team or check your subscription plan.

Cluster size must be a multiple of the number of zones, and must be greater than or equal to the replication factor. For balanced replication, cluster size divided by replication factor must equal a whole number.

1.  Note your current cluster size from the previous step. You will need this to scale back down.
    
2.  Send a scale request to add nodes:
    
    Terminal window
    
    ```shell
    curl -X PATCH "https://api.aerospike.com/v1/database/clusters/$AEROSPIKE_CLUSTER_ID" \
    
      -H "Authorization: Bearer $AEROSPIKE_API_TOKEN" \
    
      -H "Content-Type: application/json" \
    
      -d '{
    
        "aerospikeCloud": {
    
          "clusterSize": 6
    
        }
    
      }'
    ```
    
    Replace `6` with a size larger than your current cluster (must be a multiple of the replication factor).
    
3.  Monitor the operation in the Cloud Console. The cluster status shows **Updating** until complete. Wait for the operation to finish before proceeding.
    

## Scale back down

After verifying that scaling works, scale the cluster back to its original size to minimize costs.

1.  Send a scale request to reduce nodes:
    
    Terminal window
    
    ```shell
    curl -X PATCH "https://api.aerospike.com/v1/database/clusters/$AEROSPIKE_CLUSTER_ID" \
    
      -H "Authorization: Bearer $AEROSPIKE_API_TOKEN" \
    
      -H "Content-Type: application/json" \
    
      -d '{
    
        "aerospikeCloud": {
    
          "clusterSize": 4
    
        }
    
      }'
    ```
    
    Replace `4` with your original cluster size.
    
2.  Monitor the operation in the Cloud Console. The cluster status shows **Updating** until the operation completes.
    

Wait for each scaling operation to complete before starting another. Scaling typically takes several minutes.

::: undefined
-   I’ve verified the Cloud API can scale my cluster.
:::

[Previous  
Create alert rules](https://aerospike.com/docs/cloud/monitor-cloud-with-grafana/step/2/part/1/create-alerts) [Next  
Clean up resources](https://aerospike.com/docs/cloud/monitor-cloud-with-grafana/step/4/part/0/cleanup)