From 8f5b253e7b9c482b184a7d7e4ebf4c22edd2a2de Mon Sep 17 00:00:00 2001 From: esc Date: Wed, 28 Jan 2026 00:55:11 +0900 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20OICD=EB=A1=9C=20=EB=B0=B0?= =?UTF-8?q?=ED=8F=AC=20=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-deploy-lambda.yaml | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dev-deploy-lambda.yaml b/.github/workflows/dev-deploy-lambda.yaml index b405bc7..dc0325b 100644 --- a/.github/workflows/dev-deploy-lambda.yaml +++ b/.github/workflows/dev-deploy-lambda.yaml @@ -1,38 +1,44 @@ -name: Dev Deploy ECR +name: Deploy to Lambda (ECR) on: push: - branches: [ "main" ] + branches: [ "develop" ] -env: - AWS_REGION: ${{ secrets.AWS_REGION }} - ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY_NAME }} - LAMBDA_FUNCTION_NAME: ${{ secrets.LAMBDA_FUNCTION_NAME }} +# OIDC 인증을 위한 권한 설정 +permissions: + id-token: write + contents: read jobs: deploy: name: Build, Push to ECR, and Deploy to Lambda runs-on: ubuntu-latest + # 브랜치에 따라 사용할 환경 선택 + environment: ${{ github.ref == 'refs/heads/main' && 'DEV' }} + steps: - name: Checkout code uses: actions/checkout@v4 + # AWS 자격 증명 설정 - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v4 with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ env.AWS_REGION }} + role-to-assume: ${{ vars.AWS_ROLE_ARN }} + aws-region: ${{ vars.AWS_REGION }} + # Amazon ECR 로그인 - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v2 + # Docker 이미지 빌드 및 푸시 - name: Build, tag, and push image to Amazon ECR id: build-image env: ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} + ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY_NAME }} IMAGE_TAG: ${{ github.sha }} run: | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -t $ECR_REGISTRY/$ECR_REPOSITORY:latest -f Dockerfile . @@ -42,6 +48,7 @@ jobs: echo "image_uri=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + # Lambda 함수 업데이트 - name: Deploy new image to AWS Lambda run: | aws lambda update-function-code \ From 7e9ef86f06570eecf3fe12d7809e4a68ff06a404 Mon Sep 17 00:00:00 2001 From: esc Date: Wed, 28 Jan 2026 01:06:46 +0900 Subject: [PATCH 2/6] =?UTF-8?q?refactor:=20lambda=20=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev-deploy-lambda.yaml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dev-deploy-lambda.yaml b/.github/workflows/dev-deploy-lambda.yaml index dc0325b..eb686b3 100644 --- a/.github/workflows/dev-deploy-lambda.yaml +++ b/.github/workflows/dev-deploy-lambda.yaml @@ -53,4 +53,17 @@ jobs: run: | aws lambda update-function-code \ --function-name $LAMBDA_FUNCTION_NAME \ - --image-uri ${{ steps.build-image.outputs.image_uri }} \ No newline at end of file + --image-uri ${{ steps.build-image.outputs.image_uri }} + + # Lambda 환경 변수 설정 + - name: Update Lambda Environment Variables + run: | + aws lambda update-function-configuration \ + --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} \ + --environment "Variables={ \ + REGION_NAME=${{ vars.REGION_NAME }}, \ + LAMBDA_FUNCTION_NAME=${{ vars.LAMBDA_FUNCTION_NAME }}, \ + ECR_REPOSITORY_NAME=${{ vars.ECR_REPOSITORY_NAME }}, \ + BUCKET_NAME=${{ vars.BUCKET_NAME }}, \ + THUMBNAIL_BUCKET=${{ vars.THUMBNAIL_BUCKET }} \ + }" \ No newline at end of file From eb3dc97b6682aa8c2331a4508286b09935d7456c Mon Sep 17 00:00:00 2001 From: esc Date: Wed, 28 Jan 2026 01:07:33 +0900 Subject: [PATCH 3/6] =?UTF-8?q?refactor:=20lambda=20=ED=99=98=EA=B2=BD=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lambda_compare.py | 13 +++++++------ lambda_function.py | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lambda_compare.py b/lambda_compare.py index 140c63b..2fc3fe9 100644 --- a/lambda_compare.py +++ b/lambda_compare.py @@ -3,12 +3,13 @@ import base64 import re import time +import os -REGION_NAME = "ap-northeast-2" -BUCKET_NAME = "snorose-bucket" +REGION_NAME = os.environ.get('REGION_NAME') +BUCKET_NAME = os.environ.get('BUCKET_NAME') IMAGE_KEY = "test/12345/test_video.mp4" -FUNC_CON = "CreateThumbnail" -FUNC_IMG = "CreateThumbnailECR" +LAMBDA_FUNCTION_NAME = os.environ.get('LAMBDA_FUNCTION_NAME') +ECR_REPOSITORY_NAME = os.environ.get('ECR_REPOSITORY_NAME') client = boto3.client('lambda', region_name=REGION_NAME) @@ -91,9 +92,9 @@ def run_test(func_name, label): print("=== Lambda 성능 비교 테스트 시작 ===\n") # Console 버전 테스트 - run_test(FUNC_CON, "Console Version") + run_test(LAMBDA_FUNCTION_NAME, "Console Version") # Container 버전 테스트 - run_test(FUNC_IMG, "Container Image Version") + run_test(ECR_REPOSITORY_NAME, "Container Image Version") print("\n=== 테스트 완료 ===") \ No newline at end of file diff --git a/lambda_function.py b/lambda_function.py index 52fda2e..8ccdfd7 100644 --- a/lambda_function.py +++ b/lambda_function.py @@ -4,7 +4,7 @@ import subprocess s3_client = boto3.client('s3') -thumbnail_bucket = 'snorose-public-bucket' +thumbnail_bucket = os.environ.get('THUMBNAIL_BUCKET') IMG_EXT_LIST = ["jpg","jpeg","png","jfif","bmp","webp"] VDO_EXT_LIST = ["mp4","mov"] From d917009619a764f2472bc972186a939fb7cb3f34 Mon Sep 17 00:00:00 2001 From: esc Date: Wed, 28 Jan 2026 01:15:41 +0900 Subject: [PATCH 4/6] =?UTF-8?q?refactor:=20prod=20=EB=B0=B0=ED=8F=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../workflows/{dev-deploy-lambda.yaml => deploy-lambda.yaml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{dev-deploy-lambda.yaml => deploy-lambda.yaml} (95%) diff --git a/.github/workflows/dev-deploy-lambda.yaml b/.github/workflows/deploy-lambda.yaml similarity index 95% rename from .github/workflows/dev-deploy-lambda.yaml rename to .github/workflows/deploy-lambda.yaml index eb686b3..ff3bf0c 100644 --- a/.github/workflows/dev-deploy-lambda.yaml +++ b/.github/workflows/deploy-lambda.yaml @@ -2,7 +2,7 @@ name: Deploy to Lambda (ECR) on: push: - branches: [ "develop" ] + branches: [ "develop", "main" ] # OIDC 인증을 위한 권한 설정 permissions: @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest # 브랜치에 따라 사용할 환경 선택 - environment: ${{ github.ref == 'refs/heads/main' && 'DEV' }} + environment: ${{ github.ref == 'refs/heads/main' && 'PROD' || 'DEV' }} steps: - name: Checkout code From c401f4dc7e1d03382d4a88b0d51935e516ec6328 Mon Sep 17 00:00:00 2001 From: esc Date: Wed, 28 Jan 2026 01:39:03 +0900 Subject: [PATCH 5/6] =?UTF-8?q?fix:=20lambda-function-name=EC=9D=84=20?= =?UTF-8?q?=EB=B3=80=EC=88=98=EB=A1=9C=20=EB=B0=9B=EC=95=84=EC=98=A4?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-lambda.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-lambda.yaml b/.github/workflows/deploy-lambda.yaml index ff3bf0c..a359835 100644 --- a/.github/workflows/deploy-lambda.yaml +++ b/.github/workflows/deploy-lambda.yaml @@ -52,7 +52,7 @@ jobs: - name: Deploy new image to AWS Lambda run: | aws lambda update-function-code \ - --function-name $LAMBDA_FUNCTION_NAME \ + --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} \ --image-uri ${{ steps.build-image.outputs.image_uri }} # Lambda 환경 변수 설정 From 8327bf56d2ea6d0f8e8dab815efd8f2309cb167c Mon Sep 17 00:00:00 2001 From: esc Date: Wed, 28 Jan 2026 01:44:19 +0900 Subject: [PATCH 6/6] =?UTF-8?q?fix:=20=EC=BD=94=EB=93=9C=20=EC=97=85?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=8A=B8=EA=B0=80=20=EC=99=84=EB=A3=8C?= =?UTF-8?q?=EB=90=A0=20=EB=95=8C=EA=B9=8C=EC=A7=80=20=EB=8C=80=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-lambda.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-lambda.yaml b/.github/workflows/deploy-lambda.yaml index a359835..576fb0e 100644 --- a/.github/workflows/deploy-lambda.yaml +++ b/.github/workflows/deploy-lambda.yaml @@ -55,13 +55,19 @@ jobs: --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} \ --image-uri ${{ steps.build-image.outputs.image_uri }} + # 코드 업데이트가 완료될 때까지 대기 + - name: Wait for Lambda function update to complete + run: | + aws lambda wait function-updated \ + --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} + # Lambda 환경 변수 설정 - name: Update Lambda Environment Variables run: | aws lambda update-function-configuration \ --function-name ${{ vars.LAMBDA_FUNCTION_NAME }} \ --environment "Variables={ \ - REGION_NAME=${{ vars.REGION_NAME }}, \ + REGION_NAME=${{ vars.AWS_REGION }}, \ LAMBDA_FUNCTION_NAME=${{ vars.LAMBDA_FUNCTION_NAME }}, \ ECR_REPOSITORY_NAME=${{ vars.ECR_REPOSITORY_NAME }}, \ BUCKET_NAME=${{ vars.BUCKET_NAME }}, \