How to automatically deploy translations from lokalise.com to AWS S3 with serverless?

This article is also good for any use case when you want to add/change/remove something from AWS S3 after your endpoint is triggered. The perfect use case for that is when you want to update your translations files after every update in the localization service.

So first let's write how we want to design an AWS architecture for this.

  • Lambda function — this function will be responsible for downloading and updating translations on s3
  • API gateway — It will create endpoint from Lambda function
  • S3 Bucket — It will store translation files

You need to install serverless based on this instruction: https://www.serverless.com/framework/docs/getting-started/.

After that, you should have 3 files in the project (important ones are handler.js and serverless.yml). Go to serverless.yml, and now I will show you something that you can’t find in the documentation.

Below you can see how to allow to use S3 Bucket by Lambda and how to pass S3 Bucket name to Lambda function.

code_part_1

Now let's move to the handler.js

code_part_2

Now you only need to add your logic for downloading translations, deploy your serverless project and connect webhook with your endpoint.

I am the author of this article, you can find its original version under this link.

Published: 07.06.2023
© 2024, By Damian Sowa