From 6b4cda5251d665354238863a7ed765573cd37e06 Mon Sep 17 00:00:00 2001 From: jspark2000 Date: Fri, 1 Mar 2024 18:00:08 +0000 Subject: [PATCH] chore: disable cloudfront edge function --- aws/cdn/archive_file.tf | 5 ----- aws/cdn/cloudfront.tf | 5 ----- aws/cdn/lambda_function/index.js | 15 --------------- backend/libs/storage/src/image-storage.service.ts | 5 ++++- 4 files changed, 4 insertions(+), 26 deletions(-) delete mode 100644 aws/cdn/archive_file.tf delete mode 100644 aws/cdn/lambda_function/index.js diff --git a/aws/cdn/archive_file.tf b/aws/cdn/archive_file.tf deleted file mode 100644 index e47512d..0000000 --- a/aws/cdn/archive_file.tf +++ /dev/null @@ -1,5 +0,0 @@ -data "archive_file" "cdn" { - type = "zip" - source_file = "${path.module}/lambda_function/index.js" - output_path = "${path.module}/lambda_function.zip" -} diff --git a/aws/cdn/cloudfront.tf b/aws/cdn/cloudfront.tf index d8bec29..71475d6 100644 --- a/aws/cdn/cloudfront.tf +++ b/aws/cdn/cloudfront.tf @@ -12,11 +12,6 @@ resource "aws_cloudfront_distribution" "main" { target_origin_id = aws_s3_bucket.cdn_bucket.id viewer_protocol_policy = "redirect-to-https" - lambda_function_association { - event_type = "viewer-request" - lambda_arn = aws_lambda_function.cdn.qualified_arn - } - forwarded_values { query_string = false diff --git a/aws/cdn/lambda_function/index.js b/aws/cdn/lambda_function/index.js deleted file mode 100644 index 6beb274..0000000 --- a/aws/cdn/lambda_function/index.js +++ /dev/null @@ -1,15 +0,0 @@ -// 특정 도메인에서 오는 요청만 허용함 -exports.handler = async (event) => { - const allowedDomain = 'skku-royals.com' - const domainName = event.Records[0].cf.request.headers['host'][0].value - - if (domainName !== allowedDomain) { - return { - status: '403', - statusDescription: 'Forbidden', - body: 'Access denied' - } - } - - return event.Records[0].cf.request -} diff --git a/backend/libs/storage/src/image-storage.service.ts b/backend/libs/storage/src/image-storage.service.ts index f230b71..dd2716e 100644 --- a/backend/libs/storage/src/image-storage.service.ts +++ b/backend/libs/storage/src/image-storage.service.ts @@ -46,7 +46,10 @@ export class ImageStorageServiceImpl implements ImageStorageService { await this.s3.send( new PutObjectCommand({ Bucket: this.configService.get('AWS_CDN_BUCKET_NAME'), - Key: key, + Key: + this.configService.get('NODE_ENV') === 'production' + ? keyWithoutExtenstion + : key, Body: file.buffer, ContentType: fileType })