Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .github/workflows/deploy-lambda.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Deploy to Lambda (ECR)

on:
push:
branches: [ "develop", "main" ]

# 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' && 'PROD' || 'DEV' }}

steps:
- name: Checkout code
uses: actions/checkout@v4

# AWS ์ž๊ฒฉ ์ฆ๋ช… ์„ค์ •
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
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 .

docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest

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 \
--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.AWS_REGION }}, \
LAMBDA_FUNCTION_NAME=${{ vars.LAMBDA_FUNCTION_NAME }}, \
ECR_REPOSITORY_NAME=${{ vars.ECR_REPOSITORY_NAME }}, \
BUCKET_NAME=${{ vars.BUCKET_NAME }}, \
THUMBNAIL_BUCKET=${{ vars.THUMBNAIL_BUCKET }} \
}"
49 changes: 0 additions & 49 deletions .github/workflows/dev-deploy-lambda.yaml

This file was deleted.

13 changes: 7 additions & 6 deletions lambda_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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=== ํ…Œ์ŠคํŠธ ์™„๋ฃŒ ===")
2 changes: 1 addition & 1 deletion lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down