Viewer Request, Origin Request 둘 다 동작
(Viewer Req의 경우 캐싱 동작)
'use strict';
/* This is an origin request function */
exports.handler = (event, context, callback) => {
/*
* Generate HTTP redirect response with 301 status code and Location header based on region.
*/
const request = event.Records[0].cf.request;
const request_uri = request.uri;
const host = request.headers.host[0].value
const path = "/kr/img.jpg"
if(request_uri != "/test"){
return callback(null, request)
}
console.log('https://' + host + path)
const response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://' + host + path,
}],
},
};
callback(null, response);
};
Viewer Response 커스텀 헤더 추가
'use strict';
exports.handler = (event, context, callback) => {
console.log('Adding additional headers to CloudFront response.');
const response = event.Records[0].cf.response;
response.headers['strict-transport-security'] = [{
key: 'Strict-Transport-Security',
value: 'max-age=86400',
}];
response.headers['custom-header'] = [{
key: 'custom-header',
value: 'lambda-edge',
}];
response.headers['leedoing'] = [{
key: 'leedoing',
value: 'test',
}]
callback(null, response);
};
참고
https://aws.amazon.com/ko/blogs/korea/lambdaedge-design-best-practices/
엣지 컴퓨팅을 위한 Lambda@Edge 활용 모범 사례 | Amazon Web Services
이 글은 전 세계에 배포 중인 애플리케이션을 처리하는 데 있어, Lambda@Edge의 사용을 최적화하는 데 도움이 될 수 있는 모범 사례 시리즈 중 첫 번째 게시물입니다. 여기에서 다룰 주제로는 사용
aws.amazon.com
'Compute > Lambda' 카테고리의 다른 글
AWS Lambda X-ray 및 Insight(Serverless, MSA 모니터링) (2) | 2022.02.03 |
---|---|
AWS Lambda Edge 콜드스타트? (0) | 2021.10.12 |
AWS Lambda Edge를 이용한 이미지 리사이징 (0) | 2019.12.26 |
AWS Lambda 활용 태깅 없는 EC2 Instance 정지 (0) | 2017.11.14 |
AWS Lambda 활용 EIP 변경 (0) | 2017.04.12 |