AWS WAF and other CAPTCHAs
AWS WAF image puzzles explained
AWS WAF can show a picture grid such as "choose all the beds". You can answer it image by image with a classification task at $0.42 per 1,000, or skip the grid and get the cookie with a token task.
Two ways to get past the same puzzle
The AWS WAF CAPTCHA has one goal: issue an aws-waf-token cookie after a visitor proves they are human. You can reach that cookie in two ways, and choosing the right one saves a lot of code.
- Token route. An
AntiAwsWafTaskProxyLesstask takes the page URL and returns the cookie directly. You never look at the pictures. This is the right default for HTTP clients and most browser automation; the Python guide walks through it. - Classification route. An
AwsWafClassificationtask takes the puzzle images and the question, and returns which images match. Your code then clicks them in a real browser and presses the confirm button, so the page's own script earns the cookie.
This page is about the second route: what the task needs, how to collect the images, and when the extra work is worth it.
When the classification route makes sense
Choose classification when the interaction itself is part of what you need to reproduce. Typical cases:
- End to end QA. Your team protects its own app with AWS WAF and wants a test that walks through the puzzle as a person would, to confirm the widget renders and submits.
- Embedded puzzles. The site renders the CAPTCHA inside its own form with the JavaScript API, and the form's script only continues after the visible puzzle reports success.
- RPA on a visible desktop. A robot drives a real browser session that a person may watch or take over, and swapping cookies behind its back is not wanted.
For bulk data collection, the token route is shorter and cheaper per page because one cookie covers many requests. Price both options on the pricing page: the classification task costs $0.42 per 1,000 and the token task $1.40.
What the puzzle looks like
The grid puzzle shows a short instruction, such as "Choose all the beds", above a set of square images, usually a 3 by 3 layout. The visitor selects matching images and clicks Confirm. Other puzzle styles exist; at the time of writing AWS also offers an audio option and, on some sites, puzzles of other shapes. The classification task on this page targets the image grid.
The task fields
| Field | Required | Content |
|---|---|---|
| type | Yes | AwsWafClassification |
| images | Yes | Array of base64 strings, one per grid image, in on screen order |
| question | Yes | The challenge text, for example aws:grid:bed |
The answer arrives as {"objects": [1, 4]}: zero based positions in the order you sent the images. If you sent nine images from top left to bottom right, index 0 is the top left tile and 8 the bottom right. For puzzle styles where a position list does not fit, the solution carries the values to enter instead, so always read objects as "what to select or type".
Collecting the images and question
The grid lives inside the CAPTCHA container on the page. Its exact markup is not documented and may change, so locate it in DevTools first: inspect one tile and note how the image is delivered. Two patterns are common:
- Each tile is an
imgor acanvaselement. Screenshot each element and encode the bytes as base64. - The tiles are cut from one larger image. Screenshot each tile's bounding box so every array entry is one tile.
The question text is shown above the grid. Turn "Choose all the beds" into the form the task expects by taking the object word: aws:grid:bed. Keep a small mapping table in your code if the site uses plural forms or several languages.
import base64
from playwright.sync_api import Page
def grid_payload(page: Page, tile_css: str, prompt_css: str) -> dict:
tiles = page.locator(tile_css)
pictures = [base64.b64encode(tiles.nth(i).screenshot()).decode()
for i in range(tiles.count())]
words = page.locator(prompt_css).inner_text().lower().split()
target = words[-1].rstrip("s.") if words else ""
return {"type": "AwsWafClassification", "images": pictures,
"question": f"aws:grid:{target}"}
The selectors are parameters on purpose: read them from the live page rather than hardcoding a guess. The crude plural trimming works for "beds" or "chairs", but keep exceptions in a dictionary for words like "buses".
Sending the task and clicking the answer
Image tasks are fast, so poll every second instead of every three. When the indexes arrive, click the matching tiles, then the Confirm button, and wait for the container to disappear.
import time
import requests
GRID_URL = "https://gatesolver.com"
def classify_grid(task: dict, key: str = "YOUR_API_KEY") -> list[int]:
made = requests.post(f"{GRID_URL}/createTask", timeout=30,
json={"clientKey": key, "task": task}).json()
if made.get("errorId"):
raise RuntimeError(made["errorCode"])
for _ in range(120):
time.sleep(1)
res = requests.post(f"{GRID_URL}/getTaskResult", timeout=30,
json={"clientKey": key, "taskId": made["taskId"]}).json()
if res.get("status") == "ready":
return res["solution"]["objects"]
if res.get("errorId") or res.get("status") == "failed":
raise RuntimeError(res.get("errorCode", "task failed"))
raise RuntimeError("no answer for the grid")
def answer_grid(page, tile_css: str, confirm_css: str, picks: list[int]) -> None:
tiles = page.locator(tile_css)
for pos in picks:
tiles.nth(pos).click()
page.wait_for_timeout(250)
page.locator(confirm_css).click()
The short wait between clicks mirrors how a person selects tiles and gives the widget time to update its state. After Confirm, check whether a new round appeared: some configurations ask for a second grid, and your loop should simply collect and classify again.
Verifying success
Success is visible in two places. The puzzle container closes and the page continues, and the browser context now has an aws-waf-token cookie. Checking the cookie with context.cookies() is the more reliable signal, because the visual change depends on the site's own design. Once the cookie exists, you can keep browsing or even hand it to a plain HTTP client for the rest of the job.
Troubleshooting
- Wrong tiles clicked. The image order in the array must match the on screen order. Sort locators by position if the DOM order differs from the layout.
- ERROR_INVALID_TASK_DATA. Usually an empty
imagesarray (the selector matched nothing) or a data URI prefix left on the base64 strings. Send the raw base64 only. - New grid after Confirm. Normal on some sites. Repeat the collect, classify and click cycle; each task is billed only when solved.
- Puzzle never appears. The site may use the silent challenge only. In that case use the token task from the guide on how to find AWS WAF parameters.
The AWS WAF image classification page lists the current price and speed, and the image classification CAPTCHA entry explains the general idea behind picture grids.
Common questions
Should I use AwsWafClassification or AntiAwsWafTask?
Use the token task for HTTP clients and bulk work. Use classification when you must answer the visible grid in a browser, for example in end to end tests.
In which order should I send the grid images?
In on screen order from top left to bottom right. The returned indexes refer to positions in the array you sent.
How often should I poll an image classification task?
Every second. Image tasks finish faster than token tasks, and a one second interval keeps total requests reasonable.
What question value do I send for a grid of chairs?
Use the object from the instruction in the aws:grid form, for example aws:grid:chair. Keep a mapping for irregular plurals.
Does the classification task return the aws-waf-token cookie?
No. It returns which images match. The page's own script issues the cookie after you click them and confirm.
Keep reading
- AWS WAF Image Classification solver$0.42 per 1,000 tasks, answers under 1 seconds.
- Image classification CAPTCHAGrid puzzles that ask you to select every tile with a bus or a crosswalk, and how solvers return tile indexes.
- Find AWS WAF CAPTCHA parametersWhere key, iv and context sit on the AWS WAF puzzle page, and how each value maps to a task field.
- AWS WAF solver$1.40 per 1,000 tasks, answers under 3 seconds.