Metadata-Version: 2.5
Name: anakin-appflow-connector
Version: 0.1.0
Summary: Amazon AppFlow custom source connector for Anakin: scrape URLs and run Wire actions into S3, Redshift and other AppFlow destinations.
Project-URL: Homepage, https://anakin.io
Project-URL: Documentation, https://anakin.io/docs/integrations
Project-URL: Source, https://github.com/Anakin-Inc/anakin-appflow-connector
Author: Anakin Inc
License-Expression: MIT
License-File: LICENSE
Keywords: anakin,appflow,aws,lambda,web-scraping
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Requires-Python: <3.13,>=3.10
Requires-Dist: custom-connector-sdk==1.0.5
Provides-Extra: dev
Requires-Dist: boto3>=1.34; extra == 'dev'
Requires-Dist: build>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.5; extra == 'dev'
Description-Content-Type: text/markdown

# Anakin connector for Amazon AppFlow

A custom [Amazon AppFlow](https://aws.amazon.com/appflow/) source connector for [Anakin](https://anakin.io). Scrape a list of URLs, or run a [Wire action](https://anakin.io/catalog), on a schedule or on demand, and load the records into S3, Redshift or any other AppFlow destination.

You deploy it as a Lambda function in your own AWS account and register it with AppFlow. Source only.

## Entities

| Entity | One record per | Settings |
|---|---|---|
| `url_scrape` | URL | `urls` or `urls_s3_uri`, plus optional `use_browser`, `country`, `generate_json` |
| `wire_action` | action run | `action_id`, plus optional `action_params_json`, `credential_id` |

`url_scrape` fields: `url`, `status`, `markdown`, `generated_json`, `error`, `job_id`, `cached`, `duration_ms`, `completed_at`, `truncated`.

`wire_action` fields: `job_id`, `status`, `params_json`, `result_json`, `files_json`, `error`, `credits_used`, `duration_ms`, `truncated`.

A URL that can't be scraped becomes a row with `status` = `failed` and an `error`, so one bad page doesn't fail the flow. Filter on `status` downstream.

## Install

You need Python 3.12, the [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html), the AWS CLI and an [Anakin API key](https://anakin.io/account#developer) (`ask_...`). New accounts get 300 free credits.

```bash
curl -LO https://raw.githubusercontent.com/Anakin-Inc/anakin-appflow-connector/main/template.yaml
curl -LO https://raw.githubusercontent.com/Anakin-Inc/anakin-appflow-connector/main/scripts/build_bundle.sh
bash build_bundle.sh

sam deploy --template template.yaml --stack-name anakin-appflow --resolve-s3 --capabilities CAPABILITY_IAM

aws appflow register-connector --connector-label anakin --connector-provisioning-type LAMBDA \
  --connector-provisioning-config "lambda={lambdaArn=$(aws cloudformation describe-stacks --stack-name anakin-appflow \
  --query "Stacks[0].Outputs[?OutputKey=='FunctionArn'].OutputValue" --output text)}"
```

To read URL lists from S3, also pass `--parameter-overrides UrlListBucket=your-bucket` to `sam deploy`.

Then in the AppFlow console, create a flow with **anakin** as the source, create a connection with your API key, choose an entity and fill in its settings.

## Limits

AppFlow caps each setting at 2048 characters with no whitespace.

- **URLs:** `urls` holds about 40 URLs, comma-separated. For more (up to 10,000), use `urls_s3_uri`: a file with one URL per line. A URL containing a comma must go in the file.
- **Wire params:** write spaces as ` ` in `action_params_json`, for example `{"query":"data engineer"}`. Use a JSON array to run the action once per object.
- **Page size:** AppFlow limits a connector response to 6 MB, so a page larger than 4 MB has its `markdown` cut, or `result_json` dropped, and `truncated` set to `true`.
- **Throughput:** Anakin's job submission limits apply: 60 URLs/min and 20 Wire runs/min per API key, shared with your other Anakin usage.
- **Incremental pulls:** not supported. Every run fetches everything again and uses credits for every URL.

## How it fits AppFlow's limits

AppFlow requires each read call to answer within 30 seconds. Scrapes can take longer, so the connector submits each URL as its own job and returns what has finished after at most 22 seconds. The pagination token carries the jobs still running, so the next call resumes them. A job still unfinished after 300 seconds becomes a `failed` row.

## Compatibility

The AppFlow SDK (`custom-connector-sdk` 1.0.5) fails on import on Python 3.13, so the Lambda runtime is pinned to `python3.12`.

Tested end to end on 2026-11-06 with real AppFlow flows writing to S3: `url_scrape` from inline URLs and from an S3 file, `wire_action`, runs spanning several pages, and pages with no finished records. Flows were created through the AppFlow API. A scheduled flow was accepted at creation, but no scheduled run has been tested.

## Development

```bash
python -m venv .venv && .venv/bin/pip install -e '.[dev]'
.venv/bin/pytest && .venv/bin/ruff check . && .venv/bin/mypy

# Run AppFlow's paging loop against the live Anakin API, no AWS needed:
ANAKIN_API_KEY=... .venv/bin/python scripts/local_flow.py url_scrape urls=https://example.com

# Full test in a real AWS account:
ANAKIN_API_KEY=... .venv/bin/python scripts/aws_e2e.py --profile P --region us-east-1 --function-arn ARN --bucket B run
```
