Its a JavaScript code for dealing with Aws lambda Image resize and watermark.
Add imagemagick and ghostscript layer
Git clone from github and npm install
then make zip
Import zip folder in created lambda function
Create AWS s3 bucket structure what your want.
eg:
bucket
├── orginalInage
│ └── file2.jpeg
│ └── file2.png
├── resizeImage
│ └── 1024x768
│ └── file1.jpeg
│ └── file2.png
│ └── 512x512
│ └── file1.jpeg
│ └── file2.png
│ └── 200x200
│ └── file1.jpeg
│ └── file2.png
i) Make buket permission as public. Permission--> Block public access (bucket settings) --> off all
ii) Create Bucket policy as
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "AllowPublicRead",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
iii) Give Access control lis
iv) Create Cross-origin resource sharing (CORS) as
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"DELETE",
"GET",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"x-amz-server-side-encryption",
"x-amz-request-id",
"x-amz-id-2"
],
"MaxAgeSeconds": 3000
}
]
Generate Event notification and give prefix as orginalImages/
Configuration -->General Configuration -->Edit here
Go to IAM --> Roles --> select your function -->Amazones3fillAccess.