Using Lambda@Edge to alter HTML

0

A customer is hosting static HTML on S3 and is looking to user Lambda@Edge to add meta tags dynamically.

Is this an appropriate use case for Lambda@Edge or do we have other tools that could be a good fit?

Thanks!

질문됨 4년 전2195회 조회
2개 답변
0
수락된 답변

I do not believe it is feasible to modify the body of HTTP response in Lambda@Edge response triggers. See the documentation below:

https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-updating-http-responses.html

When you’re working with the HTTP response, Lambda@Edge does not expose the HTML body that is returned by the origin server to the origin-response trigger.

profile picture
답변함 4년 전
0

I just want to provide an updated answer to this question. Using a Lambda@Edge origin response function, you can fetch the current html file from S3 and load it into a variable. From there you can modify the payload and then reset it as a new payload. Here is a simple example of fetching the file from S3, but you would still need to write something to modify the payload.

 https.get(`https://bucketname.s3.amazonaws.com/index.html`, (res) => {
            res.on('data', (d) => {
                let file = decoder.write(Buffer.from(d, 'base64'));
                response.status = '200';
                response.statusDescription = "OK";
                response.body = file;
                return response;
            });
        }).on('error', (e) => {
            console.error(e);
        });
profile pictureAWS
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인