aws-samples / image-optimization

Simple, performant and cost efficient solution for optimizing images using Amazon CloudFront, Amazon S3 and AWS Lambda
MIT No Attribution
173 stars 106 forks source link

Edit code, ¿where? #17

Closed CifGom closed 7 months ago

CifGom commented 8 months ago

I would like to be able to edit the code, I already have it deployed in AWS, is it possible to do so? What lambda is it located in?

function handler(event) { var request = event.request; var originalImagePath = request.uri; // validate, process and normalize the requested operations in query parameters var normalizedOperations = {}; if (request.querystring) { Object.keys(request.querystring).forEach(operation => { switch (operation.toLowerCase()) { case 'format': var SUPPORTED_FORMATS = ['auto', 'jpeg', 'webp', 'avif', 'png', 'svg', 'gif']; if (request.querystring[operation]['value'] && SUPPORTED_FORMATS.includes(request.querystring[operation]['value'].toLowerCase())) { var format = request.querystring[operation]['value'].toLowerCase(); // normalize to lowercase if (format === 'auto') { format = 'jpeg'; if (request.headers['accept']) { if (request.headers['accept'].value.includes("avif")) { format = 'avif'; } else if (request.headers['accept'].value.includes("webp")) { format = 'webp'; }

achrafsouk commented 8 months ago

yes! you can find them in the 'functions' folder

CifGom commented 8 months ago

Thank you I have seen in functions / url rewrite but if I have already deployed everything in aws, can I can edit it?

The lambda is called ImgTransformationStack-imageoptimization? I see it is a ZIP. What files does the lambda have in this zip? To edit it and upload it again

Thank you so much

achrafsouk commented 8 months ago

yes you can edit it. The best way is to edit the downloaded CDK code, and then deploy again. Changes will propagate.