Code Monkey home page Code Monkey logo

lampic's Introduction

Create Thumbnail using Sharp JS Library

The code here creates a resized copy of the image you upload to an s3 bucket. It triggers on an event in s3 after an upload to a specified bucket and adds the new resized image to another bucket/location in s3.

The example uses: uploads-bucket (upload location), and creates a resized copy in another bucket (resized-bucket).

Install

  • npm install to get the pre-requisites

  • then zip everything (including the node modules)

  • Add the lambda function and then setup IAM policy to upload, and run lambda etc.

  • Set ObjectCreated(All) for S3 in select Lambda (function uploaded)

  • Upload the zip to Lambda and test

Update Permissions

Sample Cors:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
    </CORSRule>
    <CORSRule>
        <AllowedOrigin>http://localhost:4200</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Sample Bucket Permissions:

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "AddPerm",
			"Effect": "Allow",
			"Principal": "*",
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::ecms/*"
		},
		{
			"Sid": "DelegateS3Access",
			"Effect": "Allow",
			"Principal": {
				"AWS": "arn:aws:iam::786462021999:root"
			},
			"Action": "s3:*",
			"Resource": [
				"arn:aws:s3:::ecms/*",
				"arn:aws:s3:::ecms"
			]
		}
	]
}

Sample Resized Permissions:

{
	"Version": "2012-10-17",
	"Statement": [
		{
			"Sid": "AddPerm",
			"Effect": "Allow",
			"Principal": "*",
			"Action": "s3:GetObject",
			"Resource": "arn:aws:s3:::ecmsresized/*"
		},
		{
			"Sid": "DelegateS3Access",
			"Effect": "Allow",
			"Principal": {
				"AWS": "arn:aws:iam::786462021999:root"
			},
			"Action": "s3:*",
			"Resource": "arn:aws:s3:::ecmsresized/*"
		}
	]
}

lampic's People

Contributors

dioptre avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.