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/
'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 |