{"id":13749363,"url":"https://github.com/sourcedennis/aws-lambda-z3","last_synced_at":"2025-05-09T12:32:47.137Z","repository":{"id":216843093,"uuid":"471668311","full_name":"sourcedennis/aws-lambda-z3","owner":"sourcedennis","description":"A tutorial on running Z3 on AWS Lambda, with Rust","archived":false,"fork":false,"pushed_at":"2022-03-19T16:57:25.000Z","size":14,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-05-22T22:34:35.813Z","etag":null,"topics":["aws-lambda","z3"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sourcedennis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-03-19T10:57:00.000Z","updated_at":"2022-03-19T16:59:18.000Z","dependencies_parsed_at":"2024-01-13T07:20:32.459Z","dependency_job_id":"8913b190-9859-41d0-ba79-91e9238a97a2","html_url":"https://github.com/sourcedennis/aws-lambda-z3","commit_stats":null,"previous_names":["sourcedennis/aws-lambda-z3"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcedennis%2Faws-lambda-z3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcedennis%2Faws-lambda-z3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcedennis%2Faws-lambda-z3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sourcedennis%2Faws-lambda-z3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sourcedennis","download_url":"https://codeload.github.com/sourcedennis/aws-lambda-z3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224863108,"owners_count":17382279,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","z3"],"created_at":"2024-08-03T07:01:00.259Z","updated_at":"2024-11-16T00:30:30.100Z","avatar_url":"https://github.com/sourcedennis.png","language":"Rust","funding_links":[],"categories":["Resources"],"sub_categories":["Demos"],"readme":"# aws-lambda-z3\n\nA *Tutorial* on setting up the [Z3 theorem prover](https://github.com/Z3Prover/z3), for use within a Rust program, within [AWS Lambda](https://aws.amazon.com/lambda/). The tutorial is mostly for myself, as I'll have forgotten this in two weeks. Hopefully it is useful for others too.\n\nThis Rust project is merely a *proof-of-concept*. It performs:\n\n* Take a HTTP POST request with a value, in JSON (formatted as `{\"val\": 42}`).\n* Invokes Z3 to find two non-zero positive integers `x` and `y` (which are less than `val`), which sum to `val`.\n  * That is, `x \u003e 0`, `y \u003e 0`, `x \u003c val`, `y \u003c val`, `x + y = val`\n* In the HTTP response, it returns those values, as JSON. (formatted as `{\"x\":6,\"y\":36}`).\n\nNote that Z3 is a *dynamically linked* dependency of our program, which needs to be shipped along. To accomplish that, we pack everything into a Docker image, which we push to AWS.\n\nThe contents of both `src/main.rs` and `Dockerfile` are documented. The remainder of this README elaborates on getting the project into Lambda.\n\n## Build the Docker image\n\nSimply run:\n\n```\ndocker build . --tag=aws-lambda-z3\n```\n\nNote that this pull [Z3 from GitHub](https://github.com/Z3Prover/z3) and builds it from scratch. This may take a while.\n\n## Push the Docker image to AWS\n\n* Create a Docker repository on [Amazon ECR](https://console.aws.amazon.com/ecr/home/).\n* Push the image to the repository\n  * Inside the repository (in AWS console), follow the instructions described in **View push commands**.\n\n## Creating the Lambda Function\n\n* Go to the [AWS Lambda Console](https://console.aws.amazon.com/lambda/home)\n* Click **Create function**\n* Select **Container image**\n* Give your function a name (e.g., `aws-lambda-z3`)\n* Select your pushed image in the **Container image URI** field\n\n## Make the Function publicly accessible\n\n* Click **+ Add trigger**\n* Select for API: **Create an API**\n* Select for API type: **REST API**\n* Select for Security: **Open**\n* Keep the default \"Additional settings\"\n* Click **Add**\n\nAWS offers Lambda Proxy Integration, which seemingly interferes with our program's ability to parse a request. For simplicity, disable it:\n\n* Go to the [Amazon API Gateway Console](https://console.aws.amazon.com/apigateway/home)\n* Select **Integration Request**\n* **Uncheck** the box for **Use Lambda Proxy Integration**\n* **Important!** Click `Actions \u003e Deploy API` and redeploy to the default stage\n\nNow the program should be publicly accessible through an URL - as listed in Lambda's trigger information. This URL looks like:\n```\nhttps://*.execute-api.*.amazonaws.com/default/aws-lambda-z3\n```\n\n## Testing\n\nTo test the Lambda function, make a POST request with (replace `[URL]`):\n```\ncurl -X POST -d '{\"val\": 42}' \"[URL]\"\n```\nThis should return:\n```\n{\"x\":6,\"y\":36}\n```\n\nNote that the [Amazon API Gateway Console](https://console.aws.amazon.com/apigateway/home) also offers utilities to perform HTTP requests.\n\nWell done! Now you have Z3 running inside Lambda.\n\n## Common Errors\n\nWhile setting this up, I ran into several HTTP errors:\n\n* `403` - Forbidden. This likely occurs when you've sent the request *to the wrong URL*.\n* `500`/`502` - Internal Server Error. This happens when the program crashes. Possibly because the JSON string does not contain the `val` field. Alternatively, make sure *Lambda Proxy Integration* is disabled (and then redeploy); As it seemingly modifies the input JSON message.\n\n## License\n\nBSD-3 - See the `LICENSE` file\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcedennis%2Faws-lambda-z3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsourcedennis%2Faws-lambda-z3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsourcedennis%2Faws-lambda-z3/lists"}