Skip to content

justinjj16/AWS-Lambda_ImageResize_WaterMark

Repository files navigation

AWS Image Resize And Watermark

Its a JavaScript code for dealing with Aws lambda Image resize and watermark.

Usage

I) Create lambda function

Add imagemagick and ghostscript layer

II) Git clone

Git clone from github and npm install then make zip

III) Import zip

Import zip folder in created lambda function

IV) Create S3 bucket

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

V) S3 Bucket Permission

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
    }
]

VI) S3 bucket properties

Generate Event notification and give prefix as orginalImages/

VII) Set Lambda timeout time

Configuration -->General Configuration -->Edit here

VIII) Give s3 access for lambda

Go to IAM --> Roles --> select your function -->Amazones3fillAccess.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages