# concrete.ml.deployment.deploy\_to\_aws.md

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L0)

## module `concrete.ml.deployment.deploy_to_aws`

Methods to deploy a client/server to AWS.

It takes as input a folder with: - client.zip - server.zip - processing.json

It spawns a AWS EC2 instance with proper security groups. Then SSHs to it to rsync the files and update Python dependencies. It then launches the server.

### **Global Variables**

* **DATE\_FORMAT**
* **DEFAULT\_CML\_AMI\_ID**

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L97)

### function `create_instance`

```python
create_instance(
    instance_type: str = 'c5.large',
    open_port=5000,
    instance_name: Optional[str] = None,
    verbose: bool = False,
    region_name: Optional[str] = None,
    ami_id='ami-0d7427e883fa00ff3'
) → Dict[str, Any]
```

Create a EC2 instance.

**Arguments:**

* `instance_type` (str): the type of AWS EC2 instance.
* `open_port` (int): the port to open.
* `instance_name` (Optional\[str]): the name to use for AWS created objects
* `verbose` (bool): show logs or not
* `region_name` (Optional\[str]): AWS region
* `ami_id` (str): AMI to use

**Returns:**

* `Dict[str, Any]`: some information about the newly created instance. - ip - private\_key - instance\_id - key\_path - ip\_address - port

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L253)

### function `deploy_to_aws`

```python
deploy_to_aws(
    instance_metadata: Dict[str, Any],
    path_to_model: Path,
    number_of_ssh_retries: int = -1,
    wait_bar: bool = False,
    verbose: bool = False
)
```

Deploy a model to a EC2 AWS instance.

**Arguments:**

* `instance_metadata` (Dict\[str, Any]): the metadata of AWS EC2 instance created using AWSInstance or create\_instance
* `path_to_model` (Path): the path to the serialized model
* `number_of_ssh_retries` (int): the number of ssh retries (-1 is no limit)
* `wait_bar` (bool): whether to show a wait bar when waiting for ssh connection to be available
* `verbose` (bool): whether to show a logs

**Returns:** instance\_metadata (Dict\[str, Any])

**Raises:**

* `RuntimeError`: if launching the server crashed

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L422)

### function `wait_instance_termination`

```python
wait_instance_termination(instance_id: str, region_name: Optional[str] = None)
```

Wait for AWS EC2 instance termination.

**Arguments:**

* `instance_id` (str): the id of the AWS EC2 instance to terminate.
* `region_name` (Optional\[str]): AWS region (Optional)

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L434)

### function `terminate_instance`

```python
terminate_instance(instance_id: str, region_name: Optional[str] = None)
```

Terminate a AWS EC2 instance.

**Arguments:**

* `instance_id` (str): the id of the AWS EC2 instance to terminate.
* `region_name` (Optional\[str]): AWS region (Optional)

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L445)

### function `delete_security_group`

```python
delete_security_group(security_group_id: str, region_name: Optional[str] = None)
```

Terminate a AWS EC2 instance.

**Arguments:**

* `security_group_id` (str): the id of the AWS EC2 instance to terminate.
* `region_name` (Optional\[str]): AWS region (Optional)

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L456)

### function `main`

```python
main(
    path_to_model: Path,
    port: int = 5000,
    instance_type: str = 'c5.large',
    instance_name: Optional[str] = None,
    verbose: bool = False,
    wait_bar: bool = False,
    terminate_on_shutdown: bool = True
)
```

Deploy a model.

**Arguments:**

* `path_to_model` (Path): path to serialized model to serve.
* `port` (int): port to use.
* `instance_type` (str): type of AWS EC2 instance to use.
* `instance_name` (Optional\[str]): the name to use for AWS created objects
* `verbose` (bool): show logs or not
* `wait_bar` (bool): show progress bar when waiting for ssh connection
* `terminate_on_shutdown` (bool): terminate instance when script is over

***

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L33)

### class `AWSInstance`

AWSInstance.

Context manager for AWS instance that supports ssh and http over one port.

[![](https://img.shields.io/badge/-source-cccccc?style=flat-square)](https://github.com/zama-ai/concrete-ml/blob/release/1.1.x/src/concrete/ml/deployment/deploy_to_aws.py#L41)

#### method `__init__`

```python
__init__(
    instance_type: str = 'c5.large',
    open_port=5000,
    instance_name: Optional[str] = None,
    verbose: bool = False,
    terminate_on_shutdown: bool = True,
    region_name: Optional[str] = None,
    ami_id: str = 'ami-0d7427e883fa00ff3'
)
```


---

# 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.zama.org/concrete-ml/1.1/developer-guide/api/concrete.ml.deployment.deploy_to_aws.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.
