Save JSON Objects to AWS S3 with Google Recaptcha

181 words1 min read

Download audio
Chain fence locked
Chain fence locked

This post will show you how to save messages from a public endpoint to your backend using AWS Lambda, AWS S3 and Google Recaptcha.

Wrote the GIST for myself but I had enough requests to share it in a blog post. Copy/paste what you want.

Request from a frontend source

Add this to the frontend index.html (or anywhere a form will be sent from). Replace the _reCAPTCHA_site_key with a real one.

<script src="https://www.google.com/recaptcha/api.js?render=_reCAPTCHA_site_key"></script>
<script>
  grecaptcha.ready(function() {
      grecaptcha.execute('_reCAPTCHA_site_key_', {action: 'homepage'}).then(function(token) {
      ...
      });
  });
</script>

Docs: https://developers.google.com/recaptcha/docs/v3

Backend Setup

Start by creating an AWS Lambda function that has access to add items to S3. Using a node.js/javascript lambda function.

Environment Keys:

API Gateway Setup

  • Create an AWS API Gateway API with a resource form with a method POST.
  • Integration type Lambda Function
  • Use Lambda Proxy integration: checked
  • Select Lambda function