|
2 | 2 | A solution to dynamically handle images on the fly, utilizing Thumbor (thumbor.org). |
3 | 3 | Published version, additional details and documentation are available here: https://aws.amazon.com/answers/web-applications/serverless-image-handler/ |
4 | 4 |
|
5 | | -## OS/Python Environment Setup |
| 5 | +_Note:_ it is recommend to build the application binary on Amazon Linux. |
| 6 | + |
| 7 | +## Running unit tests for customization |
| 8 | +* Clone the repository, then make the desired code changes |
| 9 | +* Next, run unit tests to make sure added customization passes the tests |
| 10 | +``` |
| 11 | +cd ./deployment |
| 12 | +chmod +x ./run-unit-tests.sh \n |
| 13 | +./run-unit-tests.sh \n |
| 14 | +``` |
| 15 | + |
| 16 | +## Building distributable for customization |
| 17 | +* Configure the bucket name of your target Amazon S3 distribution bucket |
| 18 | +``` |
| 19 | +export TEMPLATE_OUTPUT_BUCKET=my-bucket-name # bucket where cfn template will reside |
| 20 | +export DIST_OUTPUT_BUCKET=my-bucket-name # bucket where customized code will reside |
| 21 | +export VERSION=my-version # version number for the customized code |
| 22 | +``` |
| 23 | +_Note:_ You would have to create 2 buckets, one named 'my-bucket-name' and another regional bucket named 'my-bucket-name-<aws_region>'; aws_region is where you are testing the customized solution. Also, the assets in bucket should be publicly accessible. |
| 24 | + |
| 25 | +* OS/Python Environment Setup |
6 | 26 | ```bash |
| 27 | +yum install yum-utils epel-release -y |
7 | 28 | sudo yum-config-manager --enable epel |
8 | 29 | sudo yum update -y |
9 | | -sudo yum install git libpng-devel libcurl-devel gcc python-devel libjpeg-devel -y |
10 | | -sudo pip install --upgrade pip |
| 30 | +sudo yum install zip wget git libpng-devel libcurl-devel gcc python-devel libjpeg-devel -y |
11 | 31 | alias sudo='sudo env PATH=$PATH' |
12 | | -sudo pip install --upgrade setuptools |
13 | | -sudo pip install --upgrade virtualenv |
| 32 | +sudo pip install setuptools==39.0.1 |
| 33 | +sudo pip install virtualenv==15.2.0 |
| 34 | +``` |
| 35 | +* Clone the github repo |
| 36 | +```bash |
| 37 | +git clone https://github.com/awslabs/serverless-image-handler.git |
14 | 38 | ``` |
15 | 39 |
|
16 | | -## Building Lambda Package |
| 40 | +* Navigate to the deployment folder |
17 | 41 | ```bash |
18 | | -cd deployment |
19 | | -./build-s3-dist.sh source-bucket-base-name |
| 42 | +cd serverless-image-handler/deployment |
20 | 43 | ``` |
21 | | -source-bucket-base-name should be the base name for the S3 bucket location where the template will source the Lambda code from. |
22 | | -The template will append '-[region_name]' to this value. |
23 | | -For example: ./build-s3-dist.sh solutions |
24 | | -The template will then expect the source code to be located in the solutions-[region_name] bucket |
25 | 44 |
|
26 | | -## CF template and Lambda function |
27 | | -Located in deployment/dist |
| 45 | +* Now build the distributable |
| 46 | +```bash |
| 47 | +sudo ./build-s3-dist.sh $DIST_OUTPUT_BUCKET $VERSION |
| 48 | +``` |
28 | 49 |
|
| 50 | +* Deploy the distributable to an Amazon S3 bucket in your account. Note: you must have the AWS Command Line Interface installed. |
| 51 | +```bash |
| 52 | +aws s3 cp ./dist/ s3://$DIST_OUTPUT_BUCKET-[region_name]/serverless-image-handler/$VERSION/ --recursive --exclude "*" --include "*.zip" |
| 53 | +aws s3 cp ./dist/serverless-image-handler.template s3://$TEMPLATE_OUTPUT_BUCKET/serverless-image-handler/$VERSION/ |
| 54 | +``` |
| 55 | +_Note:_ In the above example, the solution template will expect the source code to be located in the my-bucket-name-[region_name] with prefix serverless-image-handler/my-version/serverless-image-handler.zip |
| 56 | + |
| 57 | +* Get the link of the serverless-image-handler.template uploaded to your Amazon S3 bucket. |
| 58 | +* Deploy the Serverless Image Handler solution to your account by launching a new AWS CloudFormation stack using the link of the serverless-image-handler.template |
| 59 | +```bash |
| 60 | +https://s3.amazonaws.com/my-bucket-name/serverless-image-handler/my-version/serverless-image-handler.template |
| 61 | +``` |
| 62 | + |
| 63 | +## SafeURL hash calculation |
| 64 | +* For hash calculation with safe URL, use following snippet to find signed_path value |
| 65 | +```bash |
| 66 | +http_key='mysecuritykey' # security key provided to lambda env variable |
| 67 | +http_path='200x200/smart/sub-folder/myimage.jpg' # sample options for myimage |
| 68 | +hashed = hmac.new(str(http_key),str(http_path),sha1) |
| 69 | +encoded = base64.b64encode(hashed.digest()) |
| 70 | +signed_path = encoded.replace('/','_').replace('+','-') |
| 71 | +``` |
29 | 72 |
|
30 | 73 | *** |
31 | 74 |
|
|
0 commit comments