# Create stack

```
POST /v2/alm/stack
```

| **Parameters** | **Type** | **Required** | **Details**                                                                                                                                                                                                                       |
| -------------- | -------- | ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| vendor         | string   | no           | <p>Reserved namespace. Default value is always <strong>aws</strong>. Other supported values in Enterprise edition API are: <br>- <em>OpenStack</em>, <br>- <em>AliCloud</em>, <br>- <em>SBCloud</em>, <br>- <em>K5Cloud</em>.</p> |
| cred           | string   | yes          | The credential id to which Cloud vendor this stack should be deployed to. You need to set this value in [Save Credential](https://docs.mobingi.com/official/api/v2#save-credentials) API first.                                   |
| region         | string   | yes          | Eg. `ap-northeast-1` for AWS Tokyo region.                                                                                                                                                                                        |
| configurations | json     | yes          | \[see below]                                                                                                                                                                                                                      |

| **Configuration** | **Type** | **Required** | **Details**                                                                                                                                                                                                                                                                                                                                                                                |
| ----------------- | -------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| architecture      | string   | yes          | Specify `art_single` for single stack or `art_elb` for load-balanced stack                                                                                                                                                                                                                                                                                                                 |
| type              | string   | yes          | The server type, eg: `t2.small`                                                                                                                                                                                                                                                                                                                                                            |
| image             | string   | no           | <p>The docker registry path. You can either:<br>- specify the full path, eg: <code>registry.mobingi.com/wayland/lamp</code>, or <br>- omit the domain part for pulling images from <em>hub.docker.com</em>directly, eg:<code>greyltc/lamp/</code></p>                                                                                                                                      |
| dockerHubUsername | string   | no           | Specify your *username* of the docker Hub if this is a private repository.                                                                                                                                                                                                                                                                                                                 |
| dockerHubPassword | string   | no           | Specify your *password* of the docker Hub if this is a private repository.                                                                                                                                                                                                                                                                                                                 |
| min               | int      | no           | The minimum instances in an autoscaling group if your `architecture` parameter is set to `art_elb`. Default value is 1.                                                                                                                                                                                                                                                                    |
| max               | int      | no           | The maximum instances in an autoscaling group if your `architecture` parameter is set to `art_elb`. Default value is 1.                                                                                                                                                                                                                                                                    |
| spotRange         | int      | no           | <p><strong>AWS Only.</strong> The percentage of which spot instances should be deployed within your autoscaling group range, set it between <code>0</code> to <code>100</code>. <br>For eg, if you have a total of 20 instances running in the autoscaling group, and <code>spotRange</code> is set to 50, then there will be a fleet of 10 spot instances and 10 on-demand instances.</p> |
| nickname          | string   | no           |                                                                                                                                                                                                                                                                                                                                                                                            |
| code              | string   | no           | <p>A git repository URI, eg: <code>github.com/mobingilabs/default-site-php</code> <br><em>Note</em>: you can always update the code repository after at any time after the stack creation is complete.</p>                                                                                                                                                                                 |
| gitReference      | string   | no           | A git repository branch tag, default value is `master`                                                                                                                                                                                                                                                                                                                                     |
| gitPrivateKey     | string   | no           | The private key for pulling your code if the repository is a private repo.                                                                                                                                                                                                                                                                                                                 |
| database          | array    | no           | \[see below]                                                                                                                                                                                                                                                                                                                                                                               |
| elasticache       | array    | no           | \[see below]                                                                                                                                                                                                                                                                                                                                                                               |

| **database** | **Type** | **Required** | **Details**                                  |
| ------------ | -------- | ------------ | -------------------------------------------- |
| Engine       | string   | yes          | Specify either `db_mysql` or `db_postgresql` |
| DBtype       | string   | yes          | Eg. `db.m3.medium`                           |
| DBStorage    | string   | yes          | Storage size in GB, between 5 to 6144        |
| ReadReplica1 | string   | no           | `true` or `false`, default is `false`        |
| ReadReplica2 | string   | no           | \[same as above]                             |
| ReadReplica3 | string   | no           | \[same as above]                             |
| ReadReplica4 | string   | no           | \[same as above]                             |
| ReadReplica5 | string   | no           | \[same as above]                             |

| **elasticache**     | **Type** | **Required** | **Details**                                                                                                                                                                                                      |
| ------------------- | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ElastiCacheEngine   | string   | yes          | Specify either `Redis` or `Memcached`                                                                                                                                                                            |
| ElastiCacheNodeType | string   | yes          | Eg. `cache.r3.large`                                                                                                                                                                                             |
| ElastiCacheNodes    | string   | yes          | <p>-Redis, Specify the number of Nodes between <em>1</em> to <em>6</em>. One of them is the primary node, the others are the number of replicas. <br>-Memcached, Specify the number of Nodes between 1 to 20</p> |

Request Header:

```
Authorization: Bearer eyJ0eXAiOiJ83fjQb3LzMeXzQfME
Content-Type: application/json
```

Request body:

```ruby
{
    "region": "ap-northeast-1",
    "nickname": "sample stack",
    "vendor": "AWS",
    "cred": "AKIAJ2*********2DZLA",
    "configurations": {
        "spotRange":"50",
        "nickname":"sample stack",
        "min":"2",
        "max":"10",
        "type":"m3.medium",
        "architecture":"art_elb",
        "image":"mobingi/ubuntu-apache2-php7:7.1",
        "code":"github.com/mobingilabs/default-site-php",
        "region":"ap-northeast-1",
        "nodetype":"cache.r3.large",
        "database":
        [
            "DBStorage":"100",
            "Engine":"db_mysql",
            "DBtype":"db.t2.micro"
        ],
    }
}
```

Response Body:

```ruby
HTTP/1.1 200 OK
{
    "stack_id":"mo-5447826c880e8-v56QbKqA-tk",
    "status":"CREATE_IN_PROGRESS"
}
```

The stack creation usually takes 5 to 30 minutes to complete depends on your infrastructure's complexity. You can either log in to admin UI interface to see the stack creation progress, or make request to describe stack API.

In case if the response return a *CREATE-FAILED* result, you may want to check your Cloud vendor's account to see if you've reached your account limit. Eg. there are a maxium of 20 VPCs per region per AWS account.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.alphaus.cloud/v2.0-english/api-reference/stacks/create-stack.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
