This project will use S3 events that will trigger a lambda. Every time an image is uploaded, it will trigger the Lambda and transform and make the image pixelized.
This lab was a follow along with Adrian Cantrillâs course: https://github.com/acantril/learn-cantrill-io-labs/tree/master/00-aws-simple-demos/aws-lambda-s3-events
Create the S3 Buckets
In the S3 portal, click on âCreate bucketâ we will need to create 2 buckets:
Give it a unique name, I named one âimagepixelationsourceâ and âimagepixelationprocessedâ:
Create the Lambda role
Navigate to IAM and select âRolesâ, click on âCreate roleâ:
Select âAWS serviceâ and choose Lambda:
Give it a name and select âCreate roleâ, we will not be adding any policies yet:
Select the role and select âAdd permissionsâ and âCreate inline policyâ:
Select JSON and paste the JSON copied from https://raw.githubusercontent.com/acantril/learn-cantrill-io-labs/master/00-aws-simple-demos/aws-lambda-s3-events/01_LABSETUP/policy/s3pixelator.json to here. Edit in the bucket names and account ID:
Give the policy a name and click âCreate policyâ:
Create the Lambda Function
Navigate to the Lambda page and click on âCreate a functionâ:
Author from scratch and fill out the required information: Function name Python 3.9 x86_64 Use an existing role (Select the role created in the step above)
Select the âUpload fromâ and choose the .zip file. Upload the .zip file from https://github.com/acantril/learn-cantrill-io-labs/blob/master/00-aws-simple-demos/aws-lambda-s3-events/01_LABSETUP/my-deployment-package.zip :
Click on the âConfigurationâ tab and under âEnvironment Variablesâ, select âEditâ:
Add the processed bucket key and value and hit âSaveâ:
Under âGeneral configurationâ, change the timeout to 1 minute:
Under the âTriggersâ section, add a trigger:
Make sure to select the source bucket or it may cause an exponential look and increase your costs!:
Assembling everything together
Upload an image into the source bucket and see how the processed bucket will output 5 images with varying degrees of pixelation: