This project contains source code and supporting files for a serverless application - Thumbnail Creator. This application creates a thumbnail for image, pdf, and video files once uploaded into an S3 bucket. See Usage section.
The application uses several AWS services including a Lambda function and S3 buckets with three custom Lambda Layers. These resources are defined in the template.yaml
file in this project. You can update the template, e.g., change parameters' Default
value and update your application.
- Upload image, video, or pdf file to the S3 upload bucket
- Thumbnail files will be created and stored in the S3 result bucket
- app.py: Create a thumbnail for the image, pdf, and video file that uploaded to an S3 bucket
- sharedutils: a custom Lambda Layer filetype - Python package to infer binary file types
Note: this application use below three custom Lambda Layers and you must deploy these Lambda Layers before deploy this application.
Click Next to continue
Name | Description | Example value |
---|---|---|
Stack name | any valid stack name | filethumbnail |
ImageMagickLayer | ImageMagick Lambda Layer ARN | arn:aws:lambda:us-east-1:<account#>:layer:image-magick:1 |
GhostscriptLayer | Ghostscript Lambda Layer ARN | arn:aws:lambda:us-east-1:<account#>:layer:image-magick:1 |
FfmpegLayer | Ffmpeg Lambda Layer ARN | arn:aws:lambda:us-east-1:<account#>:layer:image-magick:1 |
ConversionFileType | a valid file type | jpg |
ConversionMimeType | a valid mime type | image/jpeg |
ThumbnailWidth | a valid number | 150 |
Leave it as is and click Next
Make sure all checkboxes under Capabilities section are CHECKED
Click Create stack
To use the SAM CLI, you need the following tools.
- SAM CLI - Install the SAM CLI
- Python 3 installed
- Docker - Install Docker community edition
To build and deploy your application for the first time, run the following in your shell:
sam build --use-container
Above command will build the source of the application. The SAM CLI installs dependencies defined in requirements.txt
, creates a deployment package, and saves it in the .aws-sam/build
folder.
To package the application, run the following in your shell:
sam package --output-template-file packaged.yaml --s3-bucket BUCKETNAME --region us-east-1
Above command will package the application and upload it to the S3 bucket you specified.
Run the following in your shell to deploy the application to AWS:
sam deploy --template-file packaged.yaml --stack-name STACKNAME --s3-bucket BUCKETNAME \
--parameter-overrides 'ImageMagickLayer=layerARN GhostscriptLayer=layerARN FfmpegLayer=layerARN ThumbnailWidth=150' \
--capabilities CAPABILITY_IAM --region us-east-1
You should see the cloudformation resource like below
- Upload files to the
UploadBucket
- Thumbnail files will be created and stored in the
ResultsBucket
To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
aws cloudformation delete-stack --stack-name stackname