# Deploying

## Deploying serverless with Zeit Now

Node/npm will be required on your machine in order to deploy XYZ. Installing node will vary depending on your operating system. npm is required to install the [Zeit Now CLI](https://github.com/zeit/now-cli).

With the Zeit Now CLI installed an XYZ instance can be deployed directly from the GitHub repository.

```
now geolytix/xyz
```

This will deploy the XYZ master branch from the GitHub repository with zero configurations.

![](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LPCTfppiSsRRhv-y1qY%2F-LPCVImqStB9mE7HBZJG%2Fxyz%20now%20deploy.gif?alt=media\&token=93a731a7-80e9-4ade-b6f4-b0ac269a0b1e)

You can now follow the link from the now deployment output and will see the zero configuration map in your browser.

![](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LPCTfppiSsRRhv-y1qY%2F-LPCVfBdDAI6VkSceExL%2Fimage.png?alt=media\&token=b513253b-11e8-428d-8f3b-92095e397a0c)

[Zeit Now environment variables](https://zeit.co/docs/features/env-and-secrets) can be added using the -e option. These environment variables which are available to the Node process allow to configure a custom environment for a deployment.

```bash
now geolytix/xyz \
-e DIR="/demo" \
-e ALIAS=”geolytix.xyz” \
-e PRIVATE="postgres://user:***@pg.xyz.geolytix.net:5432/xyz|demo.users" \
-e SECRET="***" \
-e TRANSPORT="smtps:xyz%40geolytix.co.uk:***@smtp.gmail.com" \
-e WORKSPACE="postgres://user:***@pg.xyz.geolytix.net:5432/xyz|demo.settings" \
-e DBS_XYZ="postgres://user:***@pg.xyz.geolytix.net:5432/xyz" \
-e KEY_MAPBOX="access_token=**.***.***"
```

## Deploying on a Ubuntu server

For deployments on Ubuntu we use the [PM2](https://github.com/Unitech/pm2) process manager to run multiple instances of the framework on different ports on the same server. Environment settings for PM2 instances can be provided from a JSON document.

```bash
pm2 start myapplication.json
```

## Deploying on AWS (Elastic Beanstalk)

The first requirement will be to become an AWS customer, if you are not already signed up follow the following link to [Sign up](https://console.aws.amazon.com/elasticbeanstalk).

The next step will be to install the Elastic Beanstalk Command Line Interface (EB CLI). There are different requirments for various operating systems. The following will provide you with an overview specific to your [environment](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb-cli3-install.html).

Another requirement before deploying will be to create AWS access keys to your AWS resources. Log into the AWS Console, and seach under find services for 'IAM'.

![Navigating to IAM](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCNYV0Q2bkcmanyJQZ%2Fimage.png?alt=media\&token=146ec5f2-18a6-4185-8df7-517f94a59d8d)

Navigate to the 'Users' and then select 'Add User'

![IAM User Creation](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCO8D4LX0ZgvlYoAvX%2Fimage.png?alt=media\&token=b5b19cba-72a5-4cca-8f1b-fee690468f2e)

Provide a username and give the user the access type of 'Programmatic access', hit next.

The next step will be to attach a Policy to the User. The Policy that we are going to attach will be the 'AdministratorAccess' . Hit next once complete. Skip the add tags section. And then hit Create User

![User Policy Association](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCObxut4G88OFx23fC%2Fimage.png?alt=media\&token=05ef689f-428f-4733-9ccf-36940b7ac1dc)

![User Creation](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCOyDKPy00NhQCUeWK%2Fimage.png?alt=media\&token=77493130-a4bb-48f6-8a76-c03eb21e4945)

Once the user is created the Access Key ID and Secret Access Key will be available for use.

![User Creation Access Key and Secret Access Key](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCPANDYQEZ6JZWlecp%2Fimage.png?alt=media\&token=587ccde5-5685-4cca-be19-a51fa5e45786)

Keep these keys on hand, as we will need them later on to configure the CLI.

To ensure that you have installed EB CLI correctly run the following : `eb --version`

![EB CLI Version](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCKVCe52RLamAJb8t2%2Fimage.png?alt=media\&token=15b7ce3b-11e9-43c4-8274-c30d20e31357)

Next navigate to the directory of the XYZ application that is ready for deployment. Once at the root directory we need to initiate a EB CLI configuration. `eb init`

The first setting for the deployment will be to select a region, where the application will be deployed.&#x20;

![Region Selection](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCMSOtjYXCDxMGX8EH%2Fimage.png?alt=media\&token=dcfb96a0-1d53-4ecd-84db-c3b4db6efb79)

The next step will be to set the aws-access-id and secret.

![Security Details](https://1429262937-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LMms4_qYZAl-8nd6vhU%2F-LYCHXCJflUna7gaSjH0%2F-LYCQ4vSqH2KlUovnbwH%2Fimage.png?alt=media\&token=8ef3009b-cda3-492b-a34e-2e8a3e6ef835)

The Next step will to select a current application or create a new application. The next setting will be to make use of CodeCommit. This will depend on whether or not you make use of this.

The next step will be to create a .ebignore file that will upload only files that are not ignored, similar to a .gitignore. Create this in the root of your application.

Use the following in the .ebignore&#x20;

```
.idea/
.vscode/
.env
.DS_Store
.sass-cache/
.git
node_modules
public/css/.sass-cache/
```

The next step is to define the instance environment properties. These will differ from instance to instance. These settings need to go into a directory called `.ebextensions` create a file with the `*.config` extension. This file is what AWS will read to create environment properties that are crucial to the XYZ framework. The configuration makes use of YAML.

```
option_settings:
  - option_name: DIR
    value: /test
  - option_name: ALIAS
    value: geolytix.xyz
  - option_name: PRIVATE
    value: 
  - option_name: SECRET
    value: 
  - option_name: TRANSPORT
    value: 
  - option_name: WORKSPACE
    value: 
  - option_name: DBS_XYZ
    value: 
  - option_name: CLOUDINARY
    value: 
  - option_name: KEY_GOOGLE
    value: 
  - option_name: KEY_HERE
    value: 
  - option_name: KEY_MAPBOX
    value: option_name: LOG_LEVEL
    value: info
```

&#x20;Once created, we are ready to deploy. To create an instance use the following command `eb create {name_of_instance}`&#x20;

If all goes well, then once the process is complete you can open exacly what you just deployed with the command `eb open`

For future deployments, you would make use of the command `eb deploy {name_of_instance}`

