Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wearetechnative/terraform-aws-html-form-action

Simple self-hosted form handler with Lambda and API Gateway. Great for static websites.
https://github.com/wearetechnative/terraform-aws-html-form-action

api-gateway aws html-form jamstack lambda terraform terraform-module

Last synced: 25 days ago
JSON representation

Simple self-hosted form handler with Lambda and API Gateway. Great for static websites.

Awesome Lists containing this project

README

        

# TAHFA (Terraform AWS HTML Form Action)

TAHFA implements a simple form handler for plain html forms. Great for static
websites. Sets up Lambda and API Gateway.

[![](we-are-technative.png)](https://www.technative.nl)

## Features

- Creates Lambda mailform POST endpoint
- Optional Success URL redirect
- Optional Failure URL redirect
- Optional [ALTCHA](https://altcha.org) Spam Protection
- Optional Mail reply template

## How does it work

The TAHFA module creates an API Gateway POST resource and connects this to a
lambda function. When a HTML form is submitted the API Gateway forwards the
formdata to the lambda function and this sends the email.

## Altcha Implementation

![](altcha.png)

Since version 0.2 TAHFA features [ALTCHA](https://altcha.org) challege and validation funcions.
ALTCHA is a free, open-source CAPTCHA alternative. ALTCHA uses a proof-of-work
mechanism to protect your website, APIs, and online services from spam and
unwanted content. ALTCHA is free, open-source, does not use cookies nor
fingerprinting, does not track users, and is fully compliant with GDPR.

## Requirements

- A configured SES domain or SES emails available in the same account.

## Example

Checkout the [examples](./examples) for complete implementations. The inline example below
shows a simple usa case.

### terraform

```hcl
module "form_action_example_com" {
source = "TechNative-B-V/html-form-action/aws"

name = "example-com-form-action-handler"
to_email = "[email protected]"
from_email = "[email protected]"
}

output "form_action_example_com_url_for_form" {
description = "Place this URL in your the action attribute of your form element."
value = module.form_action_example_com.message_post_url
}
```

### Simple html form

The form html looks like this.

```html









```

## Providers

| Name | Version |
|------|---------|
| [aws](#provider\_aws) | >= 4.0.0 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| [lambda\_function\_altchachallenge](#module\_lambda\_function\_altchachallenge) | terraform-aws-modules/lambda/aws | 3.3.1 |
| [lambda\_function\_formpost](#module\_lambda\_function\_formpost) | terraform-aws-modules/lambda/aws | 3.3.1 |
| [resource\_cors\_altchachallenge](#module\_resource\_cors\_altchachallenge) | mewa/apigateway-cors/aws | 2.0.0 |
| [resource\_cors\_formpost](#module\_resource\_cors\_formpost) | mewa/apigateway-cors/aws | 2.0.0 |

## Resources

| Name | Type |
|------|------|
| [aws_api_gateway_deployment.altcha_challenge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment) | resource |
| [aws_api_gateway_deployment.formpost](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment) | resource |
| [aws_api_gateway_integration.message_altchachallenge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration) | resource |
| [aws_api_gateway_integration.message_formpost](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration) | resource |
| [aws_api_gateway_method.message_altchachallenge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
| [aws_api_gateway_method.message_formpost](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource |
| [aws_api_gateway_resource.message_altchachallenge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
| [aws_api_gateway_resource.message_formpost](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_resource) | resource |
| [aws_api_gateway_rest_api.altcha_challenge](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api) | resource |
| [aws_api_gateway_rest_api.formpost](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api) | resource |
| [aws_lambda_permission.lambda_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |
| [aws_lambda_permission.lambda_permission_formpost](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| [allowed\_origin](#input\_allowed\_origin) | Which origin to allow submissions from. Use * when testing | `string` | `"*"` | no |
| [altcha\_hmac\_key](#input\_altcha\_hmac\_key) | HMAC Key to sign and validate Altcha Challenge | `string` | `"change.me.now"` | no |
| [from\_email](#input\_from\_email) | Receiving email address for forwarded messages, can also be configured in html form | `string` | `""` | no |
| [name](#input\_name) | Name to use for function and api gateway | `string` | n/a | yes |
| [to\_email](#input\_to\_email) | 'From' email to use when forwarding a message, defaults to recipient email in the Lambda, can also be configured in html form | `string` | `""` | no |
| [use\_altcha](#input\_use\_altcha) | Enable Altcha Spam protection | `bool` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| [message\_altcha\_challenge\_url](#output\_message\_altcha\_challenge\_url) | GET URL for Altcha Challenge requests |
| [message\_post\_url](#output\_message\_post\_url) | POST URL for message requests |