{"id":19536255,"url":"https://github.com/salvatoretosti/htmx-lambda-url-example","last_synced_at":"2025-04-26T14:36:29.226Z","repository":{"id":82047939,"uuid":"493630868","full_name":"SalvatoreTosti/htmx-lambda-url-example","owner":"SalvatoreTosti","description":"HTMX is online λ","archived":false,"fork":false,"pushed_at":"2022-05-19T00:21:29.000Z","size":17,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-21T21:05:22.184Z","etag":null,"topics":["aws","htmx","lambda"],"latest_commit_sha":null,"homepage":"https://www.saltosti.com/projects/htmx-lambda-url-example/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SalvatoreTosti.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-18T11:19:00.000Z","updated_at":"2024-08-06T20:53:15.000Z","dependencies_parsed_at":"2023-03-07T11:30:14.478Z","dependency_job_id":null,"html_url":"https://github.com/SalvatoreTosti/htmx-lambda-url-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalvatoreTosti%2Fhtmx-lambda-url-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalvatoreTosti%2Fhtmx-lambda-url-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalvatoreTosti%2Fhtmx-lambda-url-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SalvatoreTosti%2Fhtmx-lambda-url-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SalvatoreTosti","download_url":"https://codeload.github.com/SalvatoreTosti/htmx-lambda-url-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251001562,"owners_count":21520973,"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","htmx","lambda"],"created_at":"2024-11-11T02:21:54.519Z","updated_at":"2025-04-26T14:36:29.212Z","avatar_url":"https://github.com/SalvatoreTosti.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HTMX AWS Lambda URL Example\n\n### [Hosted Example](https://www.saltosti.com/projects/htmx-lambda-url-example/)\n\n### Configuring the Lambda\n1. Create a new lambda with the following settings:\n* Function name - HTMX-example-lambda\n* Runtime - Python 3.9\n* Architecture - x86_64\n\n2. Under the `Code` tab, locate the `lambda_function.py` file and edit it to be as follows:\n```python\nimport base64\nfrom urllib.parse import parse_qs\n\ndef lambda_handler(event, context):\n    body_dec = base64.b64decode(event.get(\"body\",\"\")).decode('UTF-8')\n    parsed_body = parse_qs(body_dec)\n    name = parsed_body.get('name')\n    message = parsed_body.get('message')\n    return {\n        'headers': {'content-type': 'text/html'},\n        'statusCode': 200,\n        'body': f'''\n          \u003ch2 class=\"text-center text-xl my-5\"\u003eHello {name} from a lambda!\u003c/h2\u003e\n          \u003ch3 class=\"text-center text-xl my-5\"\u003eYour message: {message}\u003c/h3\u003e\n          '''\n    }\n```\n3. Click the ‘Deploy’ button\n4. Under the `Configuration` tab select `Function URL` from the left navigation panel\n5. Then click the `Create function URL` button\n6. Create a Function URL with the following properties:\n* Auth type - `NONE`\n* Configure cross-origin resource sharing (CORS) - Enabled\n* Allow origin - `*` (allow all)\n* Add the following values under “Expose headers”\n  - access-control-allow-origin\n  - access-control-allow-methods\n  - access-control-allow-headers\n* Add the following values under “Allow headers”\n  - hx-current-url\n  - hx-request\n* Select the following values under “Allow methods”\n  - POST\n7. Click “Save\"\n8. In the main menu, look for the `Function URL` and open it in a new tab, you should see:\n  ```\n    Hello None from a lambda!\n    Your message: None\n  ```\n  \n### Testing Locally\n1. Edit the `index.html` file and set the `form.hx-post` attribute to your lambda’s URL\n2. Drag `index.html` to your browser\n3. Enter values into the `Name` and `Message` fields and click “Submit”\n4. Observe that the form is replaced by:\n```\nHello \u003cyour name\u003e from a lambda!\nYour message: \u003cyour message\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalvatoretosti%2Fhtmx-lambda-url-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalvatoretosti%2Fhtmx-lambda-url-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalvatoretosti%2Fhtmx-lambda-url-example/lists"}