# Deploy Squidex to AWS Elastic Beanstalk

This article demonstrates how to run [Squidex](https://squidex.io/), an open-source headless CMS with an API, on AWS Elastic Beanstalk.

Squidex uses .NET framework 7 and hence the binaries released by default cannot run as it is on the Elastic Beanstalk .NET platforms. The latest **.NET Core on Amazon Linux 2 version 2.5.6** supports .NET Frameworks 6.0.20 and 3.1.32.

One way to work around this is to bundle the application as a self-contained app. Another approach is to update the .NET SDK to 7. This article demonstrates the latter approach implemented using [platform hooks](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html) which are used to extend Elastic Beanstalk Linux platforms. The same can also be achieved using [commands](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-commands) which can be part of configuration files ([*.ebextensions*](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html)*)* used to configure environments.

## Pre-requisites

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">It is assumed that one is familiar with AWS services, especially Beanstalk, EC2, and IAM.</div>
</div>

* AWS Account
    
    * An existing key-pair
        
* A MongoDB cluster
    
* A domain (optional)
    

## Preparing Squidex binaries for deployment to Elastic BeanStalk

1. Download the binaries zip file from [https://github.com/Squidex/squidex/releases](https://github.com/Squidex/squidex/releases)
    
    As an example, *binaries.zip* from the 7.5.0 release of Squidex has been used here.  
    [https://github.com/Squidex/squidex/releases/download/7.5.0/binaries.zip](https://github.com/Squidex/squidex/releases/download/7.5.0/binaries.zip)
    
2. Extract the zip file.
    
3. Create the following directory structure in the extracted folder:  
    `<approot>/.platform/hooks/prebuild`
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691246653654/3e71874b-bbba-467d-8c43-500ff3fc9c00.png align="left")
    
4. Create a bash script, we will call it `01_dotnet7_install.sh` for this demonstration, inside the *prebuild* folder and copy the following code into it. Save and exit.
    
    `#!/bin/bash sudo su curl -sSL` [`https://dot.net/v1/dotnet-install.sh`](https://dot.net/v1/dotnet-install.sh) `| bash /dev/stdin --channel 7.0 --runtime aspnetcore -InstallDir /usr/local/dotnet/`
    
5. The final folder structure along with the file show looks something similar to the screenshot below:
    
    ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691475410575/c90d9714-acfc-4af2-b010-0d463d7bb28e.png align="left")
    
6. Zip the folder. DO NOT zip the extracted folder, rather zip the contents of the folder and make sure to include hidden files. The deployment will fail if this step is not executed properly.
    

## Deploy the binaries to AWS Beanstalk

The process to deploy the binaries is the same as any other Elastic Beanstalk deployment. However, pay attention to the **Environment variables** section and ensure they are correct, failing which the application won't launch properly.

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Familiarity with Elastic Beanstalk is required for the next steps, especially concepts such as Service access using IAM roles and IAM instance profiles.</div>
</div>

<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Before continuing ensure you have an EC2 key pair.</div>
</div>

1. Navigate to the AWS Beanstalk console and click **Create Application** from the Get Started screen.
    
2. This brings us to a **Configure environment** page where we can start configuring the application environment.
    
    1. Select **Web server environment** for Environment tier
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691247277495/a6d3edc9-4eed-42c6-99db-ccb2a633d01b.png align="left")
        
    2. Enter an **Application name** under Application information.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691301100440/f79b5299-c7fd-40e3-96a7-c19c9f9490df.png align="left")
        
    3. Under Environment information, an **Environment name** should be autogenerated, you can leave it as it is or change it as per your preference. If you do not have a domain of your own, set a value for **Domain** and click **Check availability** to see if the name is available.  
        <mark>Leave it blank if you want to use your domain.</mark>
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691301125479/26602578-0916-4d96-a3e2-f193c4336436.png align="left")
        
    4. For Platform, select **Managed Platform**, and choose **.NET Core on Linux**. Leave the rest to defaults.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691301077392/862bffab-2212-45d3-b0ea-774f8c68ab49.png align="left")
        
    5. Next, select **Upload your code**, set a **Version label**, choose **Local file** and click **Choose file** to select the zip file created earlier.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691301183814/53b583bb-bd57-4e67-b12c-ac6cba61d7e3.png align="left")
        
    6. For this demonstration, we leave the rest of the settings as it is. Only **Single instance** configuration is tested for Elastic Beanstalk. Click **Next** to move to the next screen.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691301207991/a9dfa176-12cd-490a-8b99-8effcd470aee.png align="left")
        
    7. In the next step, a **service role** must be created (or an existing one used) along with choosing an existing **EC2 key pair** and **EC2 instance profile**.  
        <mark>The service role can be created in this step by selecting </mark> **<mark>Create and use new service role</mark>**<mark>. If you need to create an EC2 instance profile, you can do so in another tab and refresh the list here. The permissions required to create the profile can be viewed by clicking </mark> **<mark>View permission details</mark>**<mark>.</mark>
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691472900203/5a20975b-d75d-49ca-8e8d-ec19d5b7d7fb.png align="left")
        
    8. The next step allows setting up **networking, database, and tags** but they are optional and can be left as it is. Beanstalk will use the default VPC. Covering this in detail here is out of the scope of this article. Click **Next** to move to the next step.
        
    9. The following step is also optional and one can move forward by clicking **Next**.
        
    10. In the Monitoring step, select your preference for Monitoring, Managed platform updates, Rolling updates etc. and set any environment properties.  
        For this demonstration, a **Basic** health reporting system is selected and managed platform updates are **unchecked**. The rest has been left to their defaults.  
        The following **Environment properties** must be set. Replace example values with actual values. Click **Next** when done.
        
        ![](https://cdn.hashnode.com/res/hashnode/image/upload/v1691476292078/e7a3130f-fe43-45be-9961-ba8696cd932b.png align="left")
        
    11. Finally, review and click **Submit**.
        
3. Monitor the status of the Elastic Beanstalk deployment.
    

## Access Squidex

Navigate to the URL and you should be presented with Squidex welcome screen.
