AWS Lambda image resizer function written in Go
Open the S3 management console and create two buckets, one for the source images and one for the resized images:
Important: S3 bucket names have to be globally unique!
Open the IAM managment console and create a new policy:
Create a new role. For use case, select Lambda. Click on next and select the policy from the previous step:
$ go build resizer.go
$ zip resizer.zip resizer
This creates an archive with the resizer binary that can be uploaded as lambda function to AWS.
Open the Lambda managment console and create a new function:
This takes some time. After the function is created, the following screen shold be shown:
Select Upload from on the right-hand side of Code source and upload the resizer.zip archive. Next edit the Runtime settings and change the name of the handler to resizer.
Next we need to configure a trigger so that the image resizer function is called when an image is uploaded to the source bucket. Click on Configuration and select Triggers, then Add trigger:
We also need to add an environment variable for the destination bucket used to store the resized images:
Open the S3 management console and upload an image to the source bucket:
The image resizer function should now be executed automatically and create a resized image in the destination bucket: