A simple image resizer using Golang and AWS Lambda.
OUTPUT_BUCKET- output bucketSIZES- a JSON that containers resized image size,width and save directory.
Examples:
OUTPUT_BUCKET: my-bucket
SIZES:[{"OutputDirectory":"/thumbnail/","SizeWidth":600,"SizeHeight":300},{"OutputDirectory":"/medium/","SizeWidth":1920,"SizeHeight":1020}]
Simplity execute the build.sh script
-
Create a S3
-
Create a SQS
-
Create the following policies:
- SQS Policy
{ "Version": "2012-10-17", "Statement": [ { "Sid": "SQSRole", "Effect": "Allow", "Action": [ "sqs:DeleteMessage", "sqs:ChangeMessageVisibility", "sqs:ReceiveMessage", "sqs:GetQueueAttributes" ], "Resource": "<%your-sqs-arn%>" } ] } - S3 Policy
{ "Version": "S3-role", "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObjectAcl", "s3:GetObject", "s3:PutObjectTagging", "s3:PutObjectAcl" ], "Resource": "<%your-s3-bucket-arn%>/*" } ] }
- SQS Policy
-
Create a role with following policies:
SQS Role,S3 RoleandAWSLambdaBasicExecutionRole. -
Create a S3 event notification to post to SQS whenever a file is uploaded
-
Apply following policy to your SQS(
Access policytab){ "Version": "2012-10-17", "Id": "golang-resizer", "Statement": [ { "Sid": "golang-resizer", "Effect": "Allow", "Principal": { "Service": "s3.amazonaws.com" }, "Action": "SQS:SendMessage", "Resource": "<%your-sqs-arn%>", "Condition": { "ArnLike": { "aws:SourceArn": "<%your-s3-bucket-arn%>" } } } ] } -
Create a Lambda function with role from step 4, handler
mainand trigger with SQS queue created from step 2.
