Learn How to Use Lambda Layers by Building an Image Resize Function Using Sharp | HackerNoon

United States News News

Learn How to Use Lambda Layers by Building an Image Resize Function Using Sharp | HackerNoon
United States Latest News,United States Headlines
  • 📰 hackernoon
  • ⏱ Reading Time:
  • 191 sec. here
  • 5 min. at publisher
  • 📊 Quality Score:
  • News: 80%
  • Publisher: 51%

'Learn How to Use Lambda Layers by Building an Image Resize Function Using Sharp' awslambda lambda

4.) Now let’s publish the Layer. Run the following command to create and publish the Layer: aws lambda publish-layer-version --layer-name sharp --description "Sharp dependency for image transformation" --zip-file fileb://nodejs.

zip --compatible-runtimes "nodejs14.x" --region "us-east-1" --output "json"Please note the{ "Content": { "Location": "https://prod-04-2014-layers.s3.us-east-1.amazonaws.com/snapshots/400803493251/sharp-539dd937-e29c-4418-bb52-2089f3945afc?versionId=4AMhQSZjY3uw3WI85Jcbf7j7Wj1x1X9i&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEJz%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLWVhc3QtMSJHMEUCIQDu5lMXWxGc7ydyD6HbmtJk2tnqLLxfRbCYqP7tAwi8wAIgAt3KpyhdECs9I7a2mSGNPjk1n4fq1BKjA7iOmBxOquUq%2BgMIRBAAGgw3NDk2Nzg5MDI4MzkiDOj9vGzyeEXkicvNUirXA9YvAlIvZPE3WdpgIYp51YCl28ISR4eL93paFfqBC0IguHOz%2BctOG2P5MwSc2Vj10UVBUBE4qTiGXYTbB3Gk4jCzTvgDEN90fXdMqQYWXCd8zDpq6OIcZ59qVTQPIFdjo2JZ8U3Tfu68BkIynFNLIiX4Y2WvBqxpJoFUlrmOcU4%2FtuXhSmiW6E7xyQus%2F%2BTq3A2n7JaJ2XgKOKPyINyOOBD3ZsonHjiZw0Djtjk7IgvwMjWVLb6Gn73c%2BG9bLKsHHW7aUnRaNEYSdhWejPpz1QEUlcOKpAkLI87kAgTMPCsljZMujUgWxozAth76hWebjXoE7OHUFx870jscKhpMH2DfJhaOCOsmyme69jpqc4%2FEN6jT2WGjIG42xlfUnxB90DpNBjkPguXFyghOHFlhR07bp9Rom0oW1XOriN9jnbxSZqyQsqDFwbrua4oKtOcJJrzDnUGmhKAlWPMkwE81wDyxXSB%2BGYlYQb%2F%2BXScqvqsieBtIpN5KOfAlB0VuoN17gi5BFXsP5ePaGeJPZ5MJ9COQtm6nXdvclUc8ENc0xPfw0l0485%2BVWe%2BzME%2FIIB0Sclg8TuyNSNcqrSxVxb7VVZMZfFrmMpXpU2FD1chXDGTv1tOP3x%2BthjDLvtWSBjqlATnNWnlBoAfJJE7C6ZqVOgRZU4EvDCpLchTmHT%2F99LoBvqYUU0qospR1VT4pGKtfBBEuNGgg9%2F8Dkj6l0q7p62mlxwt%2BENpVp2QOczzj6CDCjMg1E6jnsVGNzCoPeYiEEx8q6LBM51EOMcm2sSSVjNeVNRhTFrF84ch%2FCteFF5Ilr%2FTHW7pb9pJCaOOuJ%2FMZIpXy2w9CtOXxbO8%2BkG4kHHDarz8M9w%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Date=20220412T121324Z&X-Amz-SignedHeaders=host&X-Amz-Expires=600&X-Amz-Credential=ASIA25DCYHY3S4VTGYGI%2F20220412%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Signature=d84c5f4e44cf6473e0a924f3a5fd57aea32c00b17480af1551a869e41693b030", "CodeSha256": "f9IchJrdt01ftKIlcSZ25z6ZRbf780hO8xVYCd6Uxhs=", "CodeSize": 8748397 }, "LayerArn": "arn:aws:lambda:us-east-1:400803493251:layer:sharp", "LayerVersionArn": "arn:aws:lambda:us-east-1:400803493251:layer:sharp:1", "Description": "Sharp dependency for image transformation", "CreatedDate": "2022-04-12T12:13:27.990+0000", "Version": 4, "CompatibleRuntimes": [ "nodejs14.x" ] }Lambda Layer. As discussed earlier, this Lambda function will be invoked when an object is created in the source bucket. Then it will create the respective thumbnail image and store it in the target bucket. The code example below assumes that you are following the S3 bucket name convention that is mentioned in Step-1.// dependencies const AWS=require; const util=require; const sharp=require; // get reference to S3 client const s3=new AWS.S3; exports.handler=async =>{ // Read options from the event parameter. console.log); const srcBucket=event.Records[0].s3.bucket.name; // Object key may have spaces or unicode non-ASCII characters. const srcKey =decodeURIComponent); const dstBucket=srcBucket + "-resized"; const dstKey ="resized-" + srcKey; // Infer the image type from the file suffix. const typeMatch=srcKey.match$/); if { console.log; return; } // Check that the image type is supported const imageType=typeMatch[1].toLowerCase; if { console.log; return; } // Download the image from the S3 source bucket. try { const params={ Bucket: srcBucket, Key: srcKey }; var origimage=await s3.getObject.promise; } catch { console.log; return; } // set thumbnail width. Resize will set the height automatically to maintain aspect ratio. const width=200; // Use the sharp module to resize the image and save in a buffer. try { var buffer=await sharp.resize.toBuffer; } catch { console.log; return; } // Upload the thumbnail image to the destination bucket try { const destparams={ Bucket: dstBucket, Key: dstKey, Body: buffer, ContentType: "image" }; const putResult=await s3.putObject.promise; } catch { console.log; return; } console.log; };containing your Lambda function code and its dependencies.index.js

We have summarized this news so that you can read it quickly. If you are interested in the news, you can read the full text here. Read more:

hackernoon /  🏆 532. in US

 

United States Latest News, United States Headlines

Similar News:You can also read news stories similar to this one that we have collected from other news sources.

Huge black hole at galaxy's center seen in first-ever imagesHuge black hole at galaxy's center seen in first-ever imagesUsing telescopes worldwide, astronomers have captured the first image of the supermassive black hole at the center of the Milky Way.
Read more »

This is the first image of our galaxy's black holeThis is the first image of our galaxy's black holeAstronomers have managed to capture the first image of the Milky Way's black hole using the Event Horizon Telescope network.
Read more »

University of Illinois produces first image of a black holeUniversity of Illinois produces first image of a black holeThe images were made possible by a collaboration of 300 scientists globally, using eight radio telescopes positioned around the world.
Read more »

Transcriptomic mapping uncovers Purkinje neuron plasticity driving learning - NatureTranscriptomic mapping uncovers Purkinje neuron plasticity driving learning - NatureSubpopulations of Purkinje neurons display distinct transcriptomic responses and functions in associative learning.
Read more »

Great Expectations: Chapter IV | HackerNoonGreat Expectations: Chapter IV | HackerNoonGreat Expectations: Chapter by Charles Dickens is part of HackerNoon’s Book Blog Post series.
Read more »

Comment Like it is HOT, and Other HackerNoon Product Updates | HackerNoonComment Like it is HOT, and Other HackerNoon Product Updates | HackerNoonA big thank you to our team of uber-talented developers who use their superBrain skills to make HackerNoon a better place.
Read more »



Render Time: 2026-04-02 00:05:39