Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,55 @@ CMD [ "main.handler" ]

Available tags are listed [here](https://hub.docker.com/r/umihico/aws-lambda-selenium-python/tags)

## Advanced usage

To get more than a minimal example, change the code and then run the container

```
docker run --name demo -p 9000:8080 umihico/aws-lambda-selenium-python:latest
```

### Dynamic url

Change [this line](https://github.com/umihico/docker-selenium-lambda/blob/main/main.py#L25) to `chrome.get(event.get("url"))` and invoke the url set by [amazon/aws-lambda-python](https://hub.docker.com/r/amazon/aws-lambda-python#usage), any JSON in -d is passed to the function's event argument

```
curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"url": "https://example.com"}'
```

You can also have a fallback like `chrome.get(event.get("url", "https://example.com"))`, in which case you can invoke the url like this

```
curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'
```

With sls, you can pass the url argument to a Lambda deployed on AWS

```
sls invoke --function demo --data '{"url": "https://github.com"}'
```

### Local execution

Add the following to the end of main.py

```
if __name__ == "__main__" and os.getenv("AWS_LAMBDA_FUNCTION_NAME") is None:
print(handler())
```

Now you can run the function outside of Lambda

```
docker exec demo python main.py
```

You can add a dynamic url to this setup with something like

```
event = {"target": sys.argv[1]} if len(sys.argv) > 1 else {}
```

## Side Project

Are you interested in **Node.js** or **Playwright**? Please check out [docker-playwright-lambda](https://github.com/umihico/docker-playwright-lambda)
Expand Down