# Installation and Configuration

## Pre-requisites

To successfully integrate using Netacea, you will need:

1. An AWS account with administrative privileges for Lambda and CloudFront.
2. A working Amazon CloudFront distribution.
3. Lambda code file (.zip) - provided by Netacea<mark style="color:green;">\*</mark>
4. Details of the relevant API and Secret keys, and a Kinesis endpoint - provided by Netacea.

{% hint style="info" %} <mark style="color:green;">\*</mark>The .zip file that Netacea has shared with you contains the code dependencies, the three Lambda functions and the configuration file NetaceaConfig.js which should be populated with the details of your integration with Netacea.
{% endhint %}

## Creating the Lambdas

To Start creating the lambda functions, first log into the AWS console and navigate to the 'Lamba' application. This can be completed by running a search from within the UI for 'Lambda'.

Once there please check that your location/region is set to `us-east-1.` If not, please change it to this, Lambda functions must be created in the `us-east-1` AWS region, otherwise they will not be available for use with CloudFront.

### Create Function

Netacea require 3 Lambda functions for this integration and this can be completed by following the steps outlined below. you will need to repeat this process for each Lambda function.

#### Creating the Function

To start creating the function, click the create function button, located in the top right hand corner of the UI

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-1392ab3897c71e301291c828ca22a2658924fbbd%2Fimage%20(128).png?alt=media" alt=""><figcaption></figcaption></figure>

Once you have done this, you will be presented with the below screen.

Please select 'Author from scratch' and then name the function. Netacea suggest that each function be named after each function type, prefixed with 'netacea\_' Examples of these can be found below:

* netacea\_origin\_response
* netacea\_viewer\_request
* netacea\_viewer\_response

Each function should be created with the default settings under "Basic Information"

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-0a71ffad38010a1bfe6816e41895946e06d0afd5%2Fimage%20(56).png?alt=media" alt=""><figcaption><p>Create Function Example Screenshot</p></figcaption></figure>

#### Permissions

When creating the Lambdas, it is important ensure they have the correct **default execution role**. The policy it should contain is **Basic Lambda\@Edge permissions (for CloudFront trigger)**. If there is no role with this policy, one will need to be created. Please see below:

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-ea450178c417c9cd0f6fb53e474b591a15f726fc%2FLambdaPermissions.png?alt=media" alt=""><figcaption><p>Permissions Example Screenshot</p></figcaption></figure>

#### Uploading the Zip File

Once the Lambda function has been created, the Netacea code will need to be added by uploading the supplied zip file. This can be downloaded from the Netacea Admin Portal.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-1134026692fb18f30f2ddd0f42b5fb5113bcd42e%2Fimage%20(55).png?alt=media" alt=""><figcaption></figcaption></figure>

Upload the Netacea supplied zip file.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-efc9ec3dac9e7d9ac2df87cdb7a7fe64ed5052d5%2Fimage%20(66).png?alt=media" alt=""><figcaption><p>Upload the zip file</p></figcaption></figure>

Once the file has been uploaded to the function, open the `NetaceaConfig.json` from the code source UI and populate it with the details provided to you by Netacea.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-f078b5871303806e4b4f039818c0cfcd0dfa2197%2Fimage%20(58).png?alt=media" alt=""><figcaption></figcaption></figure>

For more information regarding each attribute in the config file, please see below:

The code snippet below shows the `NetaceaConfig.json` file discussed above. This must be populated with the details Netacea has provided for your organisation. This can be copied and pasted with all the relevant details from the Netacea Admin portal.

<pre class="language-json"><code class="lang-json">{
    "mitigationType": "CHOSEN-MITIGATION-TYPE",
    "apiKey": "API-KEY-PROVIDED-BY-NETACEA",
    "cookieEncryptionKey": "ENCRYPTION-KEY-PROVIDED-BY-NETACEA",
    "secretKey": "SECRET-KEY-PROVIDED-BY-NETACEA",
    "mitigationServiceUrl": "PROVIDED-BY-NETACEA",
    "ingestType": "KINESIS",
    "kinesis": {
<strong>        "kinesisStreamName": "NAME-PROVIDED-BY-NETACEA",
</strong>        "kinesisAccessKey": "KEY-PROVIDED-BY-NETACEA",
        "kinesisSecretKey": "KEY-PROVIDED-BY-NETACEA",
        "logBatchSize": 20,
        "maxLogAgeSeconds": 5
    },
    "netaceaCookieName": "_cookieName",
    "netaceaCookieAttributes": "HttpOnly; Secure",
    "netaceaCaptchaCookieName": "_captchaCookieName",
    "netaceaCaptchaCookieAttributes": "HttpOnly; Secure"
} 
</code></pre>

{% hint style="info" %}
The attribute `mitigationType` is used to determine the mode of the integration. This can be one of three values:

* "**INGEST**" - This integration mode is monitoring only, meaning that no mitigation actions will be executed. This is recommended during POCs.
* "**MITIGATE**" - This is the "normal" integration mode, meaning that the Netacea solution will monitor and actively mitigate requests.
* "**INJECT**" - This mode is used in custom solutions in which the mitigation action by Netacea will only be a recommendation using HTTP headers added to the request.
  {% endhint %}

{% hint style="danger" %}
The last three configuration variables are used to increase security by concealing Netacea's default cookie names and values from public view.
{% endhint %}

Once the `NetaceaConfig.json` code has been updated, click the **Deploy** button to save your changes.

#### Edit Runtime Settings

The Runtime settings will need to be updated.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-51845614bf736420753eb773c15e92f5fc7c7ccf%2Fimage%20(65).png?alt=media" alt=""><figcaption><p>Edit Runtime Settings</p></figcaption></figure>

Scroll below Code Source to the Runtime settings section and click the **Edit** button.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-263680f56b0a813f2dea33f116341eba7d7fec2f%2Fimage%20(62).png?alt=media" alt=""><figcaption></figcaption></figure>

Here, change the default handler from `index.handler` to the relevant function's name you are creating (e.g. use `OriginResponse.handler` for the *netacea\_origin\_response* function) . Use the below list to correlate the function name with the correct handler function:

* netacea\_origin\_response -> `OriginResponse.handler`
* netacea\_viewer\_request -> `ViewerRequest.handler`
* netacea\_viewer\_response -> `ViewerResponse.handler`

Once the correct handler has been specified, click **Save**.

#### Adding the Triggers

Once the changes have been saved and deployed, a CloudFront trigger needs to be added to the Lambda function. This allows the CloudFront distribution to execute the Lambda.\
\
At the bottom left of the **Function overview** section, click Add Trigger.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-098b656b17d674bacf00535c3cfabb102138afc1%2FFunction.png?alt=media" alt=""><figcaption></figcaption></figure>

A **Trigger configuration** page will be displayed, where the option to select a trigger from the dropdown will be presented to the user. For the source, select CloudFront.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-659e8b7f8a4cd463683e6b65af38d511ac817d70%2Fimage%20(61).png?alt=media" alt=""><figcaption></figcaption></figure>

Select **Deploy to Lambda\@Edge** and select the correct distribution, and CloudFront Event, which will be the **same name as the function you just created** (e.g. Viewer Request).

{% hint style="info" %}
For the **Netacea\_Viewer\_Request** based event, it is required that you select the option to **Include Body**.
{% endhint %}

Select **Confirm deploy to Lambda\@Edge** and then click **Deploy.**

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-143e709ab2c747740389d21d3d98917f8baf39fb%2Fimage%20(60).png?alt=media" alt=""><figcaption></figcaption></figure>

Once deployed, this will create a new version of the function and associate the CloudFront trigger. This function will be replicated across all regions and the associated distribution will be updated also.

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-4286ca1cfbad7e8e0a2de50c91daeab940605133%2FFunctionOverview.png?alt=media" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
Please ensure the above steps for creating the function and adding a trigger have been completed for each Lambda\@Edge function (**netacea\_viewer\_response**, **netacea\_viewer\_request**, and **netacea\_origin\_response**)
{% endhint %}

### POST Method

The Netacea Lambdas also require the ability to perform POST methods as part of our Captcha challenge. To enable this, please navigate to CloudFront within the UI. This can be done by running a search for 'CloudFront' within the UI

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-a0a881d21ece8aabf7eda8df6e75a5840d6f3f2e%2Fimage%20(129).png?alt=media" alt=""><figcaption><p>Search for CloudFront</p></figcaption></figure>

One within the CloudFront application, select the distribution that the Lambdas are going to be used with. The please select 'Behaviors'

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-2c66be7feaad4b690dd54f3e6871b533f629695c%2Fimage%20(130).png?alt=media" alt=""><figcaption><p>Behaviors</p></figcaption></figure>

Then select the default behaviour and click 'Edit' within this page there will be a section titled 'Allowed HTTP methods' if not already selected, please click the radial button next to 'GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE'

<figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-47b0618974f18b45a1a42bdde0d16d06b429ad75%2Fimage%20(131).png?alt=media" alt=""><figcaption><p>HTTP Methods</p></figcaption></figure>

You should also be able to see the **Function associations** at the bottom of this page. This shows the Function Type (Viewer request, Viewer response, Origin request) and their associated Lambda\@Edge function. please ensure that 'Include body' is ticked for the 'Viewer request' function.

Please then select 'Save changes'

### Testing

To test the Lambdas, select the **Test** tab and create a new event.

<div align="left"><figure><img src="https://3359534748-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8KQH1bDl0sVMvZgHUjkC%2Fuploads%2Fgit-blob-e020cb855a03ec3d2430e537a3f9bc6d8e8b32ea%2FTesting.png?alt=media" alt=""><figcaption></figcaption></figure></div>

### Finishing Up

Once the the above steps have been completed and the functions are deployed, the Netacea plugin will be active.

Please get in touch with Netacea to discuss the next steps and ensure the implementation of the integration with Netacea has been successful.
