Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
92df759
[#671] refactor: WebClient 를 사용하던 로직을 RestClient로 변경
jher235 Dec 26, 2025
c1eed15
[#671] feat: LambdaHandler 작성
jher235 Dec 26, 2025
956b42d
[#671] feat: 배포를 위한 설정 파일 작성
jher235 Dec 26, 2025
926819c
[#671] feat: dev 서버 lambda 배포 스크립트 작성
jher235 Dec 26, 2025
9953401
[#671] chore: 수동 배포를 위한 스크립트 파일 첨부
jher235 Dec 26, 2025
a0791ad
[#671] chore: 불필요한 Redis 관련 주석 제거
jher235 Dec 26, 2025
ba566b5
Merge branch 'dev' of https://github.com/sopt-makers/sopt-backend int…
jher235 Jan 10, 2026
da6e968
[#671] refactor: 유저 생성 로직을 app-service 모든 로직 이후에 진행하도록 변경
jher235 Jan 10, 2026
f0e24cc
[#671] feat: 람다 환경에서의 Swagger 설정 추가
jher235 Jan 10, 2026
9e53437
Merge branch 'dev' of https://github.com/sopt-makers/sopt-backend int…
jher235 Jan 11, 2026
acbfbe6
Merge branch 'dev' of https://github.com/sopt-makers/sopt-backend int…
jher235 Jan 14, 2026
dcd3f19
[#671] feat: dev, lambda 프로필을 조합해서 사용하도록 변경
jher235 Jan 14, 2026
7b25578
[#671] chore: lambda yml 파일 트레이스 제외
jher235 Jan 14, 2026
b85a1ac
[#671] refactor: lambda 설정 분리 및 람다 프로필에서 inActive 하게 설정
jher235 Jan 14, 2026
c0b352e
[#671] refactor: 설정 파일을 s3를 사용하지 않고 git secret을 사용하도록 변경 및 프로필 조합해서 사…
jher235 Jan 14, 2026
8335b2a
[#671] chore: 불필요한 로깅용 생성자 삭제
jher235 Jan 17, 2026
91f6ac3
[#671] refactor: 스케줄러 로직 분리 및 스케줄링 작업을 실행 API 추가
jher235 Jan 17, 2026
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
74 changes: 74 additions & 0 deletions .github/workflows/deploy-lambda-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Deploy Lambda to Dev

on:
workflow_dispatch: # 수동 실행
push:
branches:
- develop # develop 브랜치 푸시 시 자동 실행

jobs:
deploy:
name: Deploy Lambda Dev
runs-on: ubuntu-latest

env:
S3_BUCKET: sopt-makers-app
STACK_NAME: app-dev
AWS_REGION: ap-northeast-2

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

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '17'

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Get application config from S3 (선택사항)
run: |
aws s3 cp \
s3://${{ env.S3_BUCKET }}/dev/deploy/application-lambda-dev.yml \
src/main/resources/application-lambda-dev.yml

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build Lambda JAR
run: ./gradlew clean lambdaJar -x test

- name: Upload JAR to S3
run: |
# 빌드된 ZIP 파일 찾기
JAR_FILE=$(ls build/distributions/*-lambda.zip | head -1)

# 타임스탬프 생성
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
S3_KEY="lambda/${{ env.STACK_NAME }}-${TIMESTAMP}.zip"

# S3 업로드
aws s3 cp "$JAR_FILE" "s3://${{ env.S3_BUCKET }}/$S3_KEY"

echo "S3_KEY=$S3_KEY" >> $GITHUB_ENV

- name: Install SAM CLI
uses: aws-actions/setup-sam@v2

- name: Deploy with SAM
working-directory: ./lambda
run: |
sam deploy \
--config-env dev \
--stack-name ${{ env.STACK_NAME }} \
--no-fail-on-empty-changeset \
--parameter-overrides \
S3Bucket=${{ env.S3_BUCKET }} \
S3Key=${{ env.S3_KEY }}
41 changes: 40 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ dependencies {
// jwt
implementation 'com.nimbusds:nimbus-jose-jwt:9.37.3'
implementation 'com.github.ben-manes.caffeine:caffeine:3.1.8'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

// test
testImplementation 'org.springframework.boot:spring-boot-starter-test'
Expand All @@ -104,6 +103,11 @@ dependencies {
// slack
implementation 'com.slack.api:slack-api-client:1.30.0'

// AWS Lambda Dependencies for JAR deployment
implementation 'com.amazonaws.serverless:aws-serverless-java-container-springboot3:2.1.5'
implementation 'com.amazonaws:aws-lambda-java-core:1.4.0'
implementation 'com.amazonaws:aws-lambda-java-events:3.16.1'

}
tasks.named('test') {
useJUnitPlatform()
Expand All @@ -118,4 +122,39 @@ dependencyManagement {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
mavenBom "software.amazon.awssdk:bom:2.20.0"
}
}

// Lambda ZIP 빌드 설정
task lambdaJar(type: Zip) {
dependsOn bootJar
archiveClassifier = 'lambda'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
zip64 = true // 대용량 ZIP 파일 지원

// lib 디렉토리 구조로 패키징
into('lib') {
from(jar)
from(configurations.runtimeClasspath) {
// Lambda에서 불필요한 파일 제외
exclude "org/apache/tomcat/embed/**"
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
exclude "META-INF/MANIFEST.MF"
exclude "**/module-info.class"
}
}
}

// Lambda 빌드를 기본 빌드에 포함
build.dependsOn lambdaJar

// JAR 설정
jar {
enabled = true
archiveClassifier = ''
}

bootJar {
enabled = true
}
59 changes: 59 additions & 0 deletions lambda/lambda-deploy-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# 간단한 Lambda JAR 배포 스크립트
set -e # 에러 발생시 중단

# 설정
ENV=${1:-dev}
S3_BUCKET="sopt-makers-app"
STACK_NAME="app-${ENV}"
AWS_REGION="ap-northeast-2"

# 색상 정의
GREEN='\033[0;32m'
NC='\033[0m' # No Color

echo "🚀 Lambda JAR 배포 시작 (환경: $ENV)"

# 0. S3에서 yml 파일 가져오기
echo "📥 S3에서 설정 파일 다운로드 중..."
aws s3 cp s3://${S3_BUCKET}/dev/deploy/application-lambda-dev.yml src/main/resources/application-lambda-dev.yml

# 1. JAR 빌드
echo "📦 JAR 빌드 중..."
./gradlew clean lambdaJar -x test

# 2. S3 업로드
JAR_FILE=$(ls build/distributions/*-lambda.zip | head -1)
TIMESTAMP=$(date +"%Y%m%d-%H%M%S")
S3_KEY="lambda/${STACK_NAME}-${TIMESTAMP}-lambda.zip"

echo "☁️ S3 업로드 중..."
echo " 파일: $JAR_FILE"
echo " S3 경로: s3://${S3_BUCKET}/${S3_KEY}"
aws s3 cp "$JAR_FILE" "s3://${S3_BUCKET}/${S3_KEY}"

# 3. SAM으로 배포
echo "🔄 SAM 배포 중..."
cd lambda

sam deploy \
--config-env ${ENV} \
--stack-name ${STACK_NAME} \
--no-fail-on-empty-changeset \
--parameter-overrides \
S3Bucket=${S3_BUCKET} \
S3Key=${S3_KEY}

cd ..

echo -e "${GREEN}✅ 배포 완료!${NC}"

# API 엔드포인트 출력
API_ENDPOINT=$(aws cloudformation describe-stacks \
--stack-name ${STACK_NAME} \
--query "Stacks[0].Outputs[?OutputKey=='ApiEndpoint'].OutputValue" \
--output text \
--region ${AWS_REGION})

echo -e "${GREEN}🌐 API Endpoint: ${API_ENDPOINT}${NC}"
21 changes: 21 additions & 0 deletions lambda/samconfig.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version = 0.1

[default.build.parameters]
cached = true
parallel = true

[dev.deploy.parameters]
stack_name = "app-dev"
region = "ap-northeast-2"
capabilities = "CAPABILITY_IAM"
confirm_changeset = false
template = "template-dev.yaml"
resolve_s3 = true

[prod.deploy.parameters]
stack_name = "app-prod"
region = "ap-northeast-2"
capabilities = "CAPABILITY_IAM"
confirm_changeset = true # 운영은 변경사항 확인
template = "template-prod.yaml"
resolve_s3 = true
79 changes: 79 additions & 0 deletions lambda/template-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
Sopt makers App Backend DEV - Spring Boot JAR on AWS Lambda with SnapStart

Globals:
Function:
Timeout: 300 # 최대 실행 시간 (초)
MemorySize: 3072 # 메모리 (MB) - 프로젝트 크기에 따라 조정
Runtime: java21 # Java 버전

Parameters:
S3Bucket:
Type: String
Default: ""
Description: S3 bucket containing the Lambda JAR
S3Key:
Type: String
Default: ""
Description: S3 key (path) to the Lambda JAR file
Profile:
Type: String
Default: "lambda-dev"
Description: Spring profile to use


Resources:
ApiFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub "${AWS::StackName}-api"
CodeUri:
Bucket: !Ref S3Bucket
Key: !Ref S3Key
Handler: org.sopt.app.LambdaHandler
SnapStart:
ApplyOn: PublishedVersions # SnapStart 활성화
AutoPublishAlias: live
Environment:
Variables:
SPRING_PROFILES_ACTIVE: !Ref Profile
TZ: Asia/Seoul
JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
Policies:
- AWSLambdaBasicExecutionRole
- Statement:
- Effect: Allow
Action:
- s3:GetObject
Resource: !Sub "arn:aws:s3:::${S3Bucket}/*"
Events:
ApiProxy:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /{proxy+}
Method: ANY
ApiRoot:
Type: Api
Properties:
RestApiId: !Ref ApiGateway
Path: /
Method: ANY

ApiGateway:
Type: AWS::Serverless::Api
Properties:
StageName: dev
EndpointConfiguration: REGIONAL # 👈 [추가] 이 한 줄이 핵심입니다!
Cors:
AllowOrigin: "'*'"
AllowHeaders: "'*'"
AllowMethods: "'*'"
AllowCredentials: "'false'"

Outputs:
ApiEndpoint:
Description: "API Gateway endpoint URL"
Value: !Sub "[https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/dev](https://${ApiGateway}.execute-api.${AWS::Region}.amazonaws.com/dev)"
40 changes: 40 additions & 0 deletions src/main/java/org/sopt/app/LambdaHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.sopt.app;

import com.amazonaws.serverless.exceptions.ContainerInitializationException;
import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler;
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class LambdaHandler implements RequestStreamHandler {

private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;

static {
try {
handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(AppApplication.class);

// Swagger
SpringBootLambdaContainerHandler.getContainerConfig().addBinaryContentTypes(
"image/png",
"image/jpeg",
"image/gif",
"application/octet-stream"
);
} catch (ContainerInitializationException e) {
throw new RuntimeException("Could not initialize Spring Boot application", e);
} catch (Exception e) {
throw new RuntimeException("Could not initialize Lambda handler", e);
}
}

@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context)
throws IOException {
handler.proxyStream(inputStream, outputStream, context);
}
}
35 changes: 20 additions & 15 deletions src/main/java/org/sopt/app/common/external/auth/AuthClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,37 @@
import lombok.extern.slf4j.Slf4j;
import org.sopt.app.common.exception.ClientException;
import org.sopt.app.common.response.ErrorCode;
import org.springframework.http.HttpStatusCode;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import org.springframework.web.client.RestClient;

@Slf4j
@Component
@RequiredArgsConstructor
public class AuthClient {

private final WebClient authWebClient;
private final RestClient authRestClient; // WebClient -> RestClient 변경
private final AuthClientProperty authProperty;

public String getJwk() {
try {
return authWebClient.get()
.uri(authProperty.endpoints().jwk())
.retrieve()
.bodyToMono(String.class)
.onErrorMap(WebClientResponseException.class, ex -> {
log.error("Failed to receive response from Auth server: {}", ex.getResponseBodyAsString(), ex);
return new ClientException(ErrorCode.RESPONSE_ERROR);
})
.block();
} catch (RuntimeException e) {
log.error("Unexpected exception occurred during Auth server communication: {}", e.getMessage(), e);
return authRestClient.get()
.uri(authProperty.endpoints().jwk())
.retrieve()
.onStatus(HttpStatusCode::isError, (request, response) -> {
String errorBody = new String(response.getBody().readAllBytes());
log.error("Failed to receive response from Auth server: {}", errorBody);
throw new ClientException(ErrorCode.RESPONSE_ERROR);
})
.body(String.class);

} catch (ClientException e) { // onStatus에서 던진 예외만 그대로 다시 던짐
throw e;
} catch (Exception e) {
log.error("Unexpected exception occurred during Auth server communication: {}",
e.getMessage(), e);
throw new ClientException(ErrorCode.COMMUNICATION_ERROR);
}
}
}

}
Loading