# How to prepare Amazon AMI Finmars CE

Guide how to prepare web-form only installation Ubuntu 24.04 for Amazon AMI

# Getting Started

1\) Request VM with Ubuntu 24.04

2\) Install required packages

```
sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release ntp unzip zip make

wget -qO- https://get.docker.com/ | sh

sudo usermod -aG docker $USER
newgrp docker
```

3\) Create Finmars Folder

```
sudo mkdir -p /opt/finmars
sudo chown $USER:$USER /opt/finmars
```

4\) Clone Finmars Community Edition

```
cd /opt/finmars
git clone https://github.com/finmars-platform/finmars-community-edition.git .
```

5\) Install requirements

`<span class="editor-theme-code">pip install -r requirements.txt</span>`

<span style="white-space: pre-wrap;">6) Create systemd service </span>

`<span class="editor-theme-code">sudo vim /etc/systemd/system/init-setup.service</span>`  
  
<span style="white-space: pre-wrap;">Paste following content </span>

```
[Unit]
Description=Finmars Initial Setup
After=network.target

[Service]
WorkingDirectory=/opt/finmars
ExecStart=/usr/bin/python3 -m community_edition.main
Restart=no

[Install]
WantedBy=multi-user.target
```

Reload Systemd

```
sudo systemctl daemon-reload
sudo systemctl enable init-setup
sudo systemctl start init-setup
```

7\) Add crontab to execute step

`<span class="editor-theme-code">sudo crontab -e</span>`

Add following line to crontab

`<span class="editor-theme-code">* * * * * cd /opt/finmars && /usr/bin/python3 -m community_edition.services.setup</span>`

And Pull Finmars Images (for faster user insallation

```
docker pull postgres:13-alpine
docker pull rabbitmq:3.11.3-management
docker pull redis
docker pull certbot/certbot
docker pull nginx
docker pull quay.io/keycloak/keycloak:24.0.3
docker pull finmars/finmars-start-page:latest
docker pull finmars/finmars-excelgen:latest
docker pull finmars/finmars-pdfgen:latest
```

```
docker pull finmars/finmars-core:1.23.3-stable
docker pull finmars/finmars-workflow:1.23.0-stable
docker pull finmars/finmars-portal:1.23.0-stable
docker pull finmars/finmars-vue-portal:1.23.0-stable
docker pull finmars/finmars-workflow-portal:1.23.0-stable
```

When All done you need to remove keys and logout

```
sudo rm /home/ubuntu/.ssh/authorized_keys
sudo rm /root/.ssh/authorized_keys
```

You need to logout and proceed to AWS ec2 console, you need to export AMI template to us-east-1 region  
  
Select your ec2 VM, go to Actions -&gt; Images and Templates -&gt; Create Image  
<span style="white-space: pre-wrap;">Then wait until your AMI Exported (Go to </span>[https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1](https://us-east-1.console.aws.amazon.com/ec2/home?region=us-east-1)<span style="white-space: pre-wrap;">) </span>  
  
<span style="white-space: pre-wrap;">After that you need to make your AMI public - Edit AMI Permissions (right click on ami row) - </span>**AMI availability**<span style="white-space: pre-wrap;"> - Public</span>  
Then go to AWS Marketplace and proceed with publishing new version  
  
<span style="white-space: pre-wrap;">Go to </span>[https://aws.amazon.com/marketplace/management/products/server](https://aws.amazon.com/marketplace/management/products/server)