Manually install the AWS Lambda@Edge Enforcer
Manually install the AWS Lambda@Edge Enforcer
Manually install the AWS Lambda@Edge Enforcer
If your organization uses AWS CloudFront services, you can use HUMAN’s Lambda@Edge Enforcer to protect against malicious behavior. This Enforcer uses AWS Lambda functions to deploy the Enforcer on your content delivery network (CDN) and determine how traffic to your organization’s server should be handled.
You can learn how to install the Enforcer with this article.
If you do not already have an Enforcer deployed to your environment, we highly recommend using the Deploy Tool method instead. See our documentation for more information.
nvm install stable in your CLI to install it.The Lambda@Edge Enforcer consists of three Lambda functions. Each function is integrated at a different event in an Amazon CloudFront distribution. They are:
For more information on CloudFront events, see AWS’ help article.
The process for defining your Lambda functions is different depending on if you have an existing Lambda project or not.
If you do not have an existing AWS project, then you can use HUMAN’s premade templates to quickly create and install the AWS Lambda@Edge Enforcer. This Enforcer is publicly available from our GitHub repository.
git clone https://github.com/PerimeterX/aws-lambda-edge-template.cd aws-lambda-edge-template.npm install. This installs the necessary dependencies to use the Enforcer template.basic_example/src/custom/config.json and update the px_app_id, px_auth_token, and px_cookie_secret fields with your Application ID, Server Token, and Risk Cookie Key respectively.These are the minimum required settings to configure the Enforcer. To customize it further, see our custom configurations. We recommend adding your configurations before uploading any Lambda function to your CloudFront distribution for the first time.
You can store sensitive information, such as your Server Token and Risk Cookie Key, in the AWS Secrets Manager rather than inserting them directly into your configuration. See AWS’ help article to learn how to do so.
config.json.npm run zip to bundle your Lambda functions into ZIP files. This should create HumanActivities.zip, HumanEnforcer.zip, and HumanFirstParty.zip.Next, see the steps in Deploy the Enforcer to complete your setup.
If you already have a Lambda project that you want to integrate the HUMAN Enforcer with, then you can follow the steps below.
Each Lambda function requires slightly different steps to configure and deploy to CloudFront. Be sure to follow the right section to complete each one.
The HumanEnforcer Lambda is required.
To get started:
package.json file. Typically, this is the root directory of your project.npm i --save @humansecurity/aws-lambda-edge-enforcer. This will update your package.json dependencies with the latest HUMAN AWS Lambda@Edge Enforcer package.config.json file. We recommend doing this if you are creating multiple Lambda functions. If you plan to define custom functions as part of your configuration, you may want to modify this file to be a JavaScript (i.e., config.js) or TypeScript file (i.e., config.ts) rather than a JSON file.Then, follow the appropriate section for each Lambda function:
The HumanEnforcer Lambda is the primary Lambda that determines the behavior of traffic activity in your CloudFront distribution. This Lambda is required so that the AWS Lambda@Edge Enforcer can function.
config.json file, insert the following code and update the APP_ID, AUTH_TOKEN, and COOKIE_SECRET fields with your Application ID, Server Token, and Risk Cookie Key respectively.We recommend using the AWS Secrets Manager to securely store sensitive tokens such as your Server Token and Risk Cookie Key in the AWS Secrets Manager rather than inserting them directly into your configuration. See AWS’ help article to learn how to do so.
If you also want to add any custom configurations, we recommend doing so in this step before uploading any Lambda function to AWS CloudFront for the first time. You can review our available configurations with our help article.
AWS Lambda considers it best practice to use async/await syntax, but a callback-based alternative is available as well if you use it.
config.json.index.ts into the dist directory, you would run: esbuild ./index.ts --bundle --minify --platform=node --target=es2022 --outfile=dist/index.js.Once you’ve zipped your function, see the steps in Deploy the Enforcer to complete your setup.
You only need to configure the HumanActivities Lambda if you want to send the custom HUMAN configuration additional_s2s_activity to the origin. This lets HUMAN analyze data related to the response in addition to the request.
config.json file, insert the following code and update the APP_ID, AUTH_TOKEN, and COOKIE_SECRET fields with your Application ID, Server Token, and Risk Cookie Key respectively.We recommend defining this using the same configuration you used for the HumanEnforcer Lambda.
config.json.index.ts into the dist directory, you would run: esbuild ./index.ts --bundle --minify --platform=node --target=es2022 --outfile=dist/index.js.Once you’ve zipped your function, see the steps in Deploy the Enforcer to complete your setup.
You only need to configure the HumanFirstParty Lambda if you want to support first-party requests. You can learn more about these requests with our help article.
config.json file, insert the following code and update the APP_ID field with your Application ID and add relevant first-party custom configurations you want to include to the definition.We recommend defining this using the same configuration you used for the HumanEnforcer Lambda.
config.json.index.ts into the dist directory, you would run: esbuild ./index.ts --bundle --minify --platform=node --target=es2022 --outfile=dist/index.js.Once you’ve zipped your function, see the steps in Deploy the Enforcer to complete your setup.
Now that you have your Lambda functions ready, you must upload them to AWS CloudFront and deploy them. The steps to upload each type of Lambda are different, so be sure to follow the correct instructions for the Lambda you’re uploading.
Ensure you are on US East (N. Viriginia), us-east-1 when creating Lambda functions. Lambda@Edge functions can only be deployed from us-east-1. For more information, see AWS’ help article.
Complete the following steps to upload the HumanEnforcer Lambda.
You have successfully integrated the HUMAN AWS Lambda@Edge Enforcer with your CloudFront distribution. Make sure to reach out to our support team to complete your tuning process.
Complete the following steps to upload the HumanActivities Lambda.
Make sure you also upload the HumanEnforcer Lambda. Once you do, you have successfully integrated the HUMAN AWS Lambda@Edge Enforcer with your CloudFront distribution. Make sure to reach out to our support team to complete your tuning process.
Complete the following steps to upload the HumanFirstParty Lambda.
If the Enforcer was configured to use custom first party endpoints, you must create additional cache behaviors for the custom first party path patterns. Otherwise, requests using the custom paths will not be handled properly.
/<APP_ID_without_PX>/*. For example, for an ID that is PX123456, the path pattern should be /123456/*.Make sure you also upload the HumanEnforcer Lambda. Once you do, you have successfully integrated the HUMAN AWS Lambda@Edge Enforcer with your CloudFront distribution. Make sure to reach out to our support team to complete your tuning process.
We recommend creating an IAM role for each Lambda you upload. This lets the function create log groups and log streams in CloudWatch. When you deploy a Lambda@Edge function, it distributes across all edge cache locations, and all logs from the Lambda related to those regions will appear in the CloudWatch logs of their respective edge cache areas. For example, if a user accesses the us-east-1 region, the corresponding logs will be found in us-east-1.
AWS CloudFormation is a service that enables users to model and manage infrastructure resources in an automated and secure manner.
Using CloudFormation, developers can define and provision AWS infrastructure resources using a JSON- or YAML-formatted infrastructure as code template.
If one of these applies to you, you can follow the instructions in Deploy the Enforcer.
install the enforcer section and make sure you have the lambda zip files.The following steps are for deploying the HUMAN Enforcer to a new CloudFront distribution. The deployment includes the HumanEnforcer lambda and the HumanFirstParty lambda, but the HumanActivities lambda is not included. To add it, see How to add HumanActivitiesLambda before deploying the CloudFormation stack.
deploy directory.
cfm_deploy.yaml file and replace the placeholders with the relevant values:DomainName: "<ORIGIN_DOMAIN_URL>" - DomainName: "example.com""<PX_APP_ID_SUFFIX>/*"pxapp12345 the PX_APP_ID_SUFFIX is app12345 (Remove the PX prefix from the app_id)Example:
<stack-name> and <bucket-name> ):
HumanActivitiesLambda is an optional additional lambda that runs on the origin response and can be used to send additional activities that require response information to the HUMAN Security API. This Lambda is in charge of generating the HUMAN Security PXHD cookie and needs to be deployed in case you’re using advanced features such as Credential Intelligence or GraphQL protection.
To add the HumanActivitiesLambda to the CloudFormation stack, you must adjust your cfm_deploy.yaml file to include the HumanActivitiesLambda before deployment.
EnforcerExecutionRole, at line 65):LambdaFunctionAssociations an origin-response EventType, with the following association: LambdaFunctionARN: !Ref HumanActivitiesLambdaFunctionVersion. For example:ActivitiesLambdaCodePath variable at the end of the yaml file. For example: