How to do it...

In this recipe, you will configure WAF to run on top of a lambda function that publishes an endpoint via an API Gateway:

  1. Log in to your AWS account, and go to the Lambda dashboard.
  2. Create a new lambda function, and choose Author from scratch. Give it a name and click Create function:

Create function
  1. Add an API Gateway integration trigger:

Add API Gateway trigger
  1. Select Create a new API, and then Save the lambda function:

Configure the trigger
  1. Click the endpoint URL in the API Gateway configuration summary, and you should see Hello from Lambda, if you left the default function code alone:

The API Gateway stage URL for your new function
  1. Go to the API Gateway dashboard, select the new gateway you just created, and then select the default stage. Click Create Web ACL:

The API Gateway stage editor
  1. In the WAF console, create a new web ACL. Review the concepts overview and click Next.
  2. Give the ACL a name, select your region, then select your new API Gateway stage. Click Next:

Web ACL configuration
  1. Create an IP match condition and add you current IP address. If you aren't sure what your IP is, visit a site such as https://www.whatismyip.com/, and then add /32 to the address, in order to make it comply with CIDR (short for Classless Inter-Domain Routing) notation:

Add an IP address
  1. Create a rule. Give the rule a name, select the IP address that you created in the previous step, and then click Create:

Add conditions
  1. Click Review and Create; then Confirm and Create.
  2. Go back to the API stage, and select the new ACL that you just created. Save the changes.
  3. Refresh the endpoint URL, and you should see {"message":"Forbidden"}.

With this recipe, you have successfully integrated AWS WAF with an AWS lambda function. You can apply what you have learned here to other resources, such as EC2 instances sitting behind an application load balancer, and you can create more complex rules in order to meet your needs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset