This example shows you how to setup a dynamic image resizer API
In this example, we set up a dynamic image resizing solution with AWS S3 and a Serverless framework function written in Node.js. We use the
sharp package for image resizing.
sharp includes native dependencies, so in this example we are building and deploying the Serverless function from a Docker container that’s based on Amazon Linux.
In order to deploy the function, you will need the following:
yarn global add serverless.
docker-compose up --build
Make sure that your S3 bucket is public. Then follow these additional setup steps:
<RoutingRules> <RoutingRule> <Condition> <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals> </Condition> <Redirect> <Protocol>https</Protocol> <HostName>your_api_endpoint.execute-api.us-east-1.amazonaws.com</HostName> <ReplaceKeyPrefixWith>dev-1/</ReplaceKeyPrefixWith> <HttpRedirectCode>307</HttpRedirectCode> </Redirect> </RoutingRule> </RoutingRules>
You will need to replace
your_api_endpoint part with the URL of your Serverless endpoint. You can find out what’s the endpoint URL by running:
or observing the output of the deployment step.
Please feel free to open an issue on this repository if something doesn’t work is doesn’t behave as described here. Thanks for giving this project a try!