How to automatically deploy translations from 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:

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.

Now let's move to the handler.js

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