Skip to content

Conversation

@geniusYoo
Copy link
Contributor

Related issue 🛠

Work Description ✏️

Situation

기존에 spring-cloud-starter-aws (AWS SDK v1 기반)를 사용하고, AWS 자격 증명을 application.yml에서 @Value로 주입받아 설정하는 방식을 사용하고 있었어요.

이 상황에서 자동 AWS 자격 증명 메커니즘을 사용하도록 변경하니, 오래된 spring-cloud-starter-aws가 의존하는 Jackson 라이브러리 버전과, 다른 최신 라이브러리(Spring Boot, Feign 등)가 의존하는 Jackson 버전이 충돌하여 NoSuchFieldError (Jackson 필드 없음) 오류가 발생했어요.

Action

다음과 같이 개선 작업을 진행했어요.

  1. AWS SDK v2 마이그레이션:

    • 오래된 spring-cloud-starter-aws 의존성을 제거했습니다.
    • build.gradle에 AWS SDK v2 BOM 및 필요한 s3 모듈 의존성을 추가하여 최신 SDK를 사용하도록 변경했습니다.
  2. 관련 코드 수정:

    • AwsConfig.java를 AWS SDK v2의 S3Client, S3Presigner 빈을 생성하도록 수정했습니다.
    • S3Service.java에서 AWS SDK v1 API 대신 SDK v2 API (S3Client, S3Presigner 사용)를 사용하도록 Pre-signed URL 생성 및 객체 삭제 로직 등을 수정했습니다.

작업 내용은 다음과 같아요.

  1. build.gradle 의존성 수정 (SDK v1 제거, SDK v2 BOM 및 s3 모듈 추가)

    // build.gradle
    
    // implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' // 제거
    
    dependencyManagement {
        imports {
            mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
            mavenBom "software.amazon.awssdk:bom:2.25.30" 
        }
    }
    
    dependencies {
        // ... 다른 의존성 ...
        implementation 'software.amazon.awssdk:s3' // SDK v2 S3 모듈 추가
    }
  2. AwsConfig.java 수정 (SDK v2 사용 및 명시적 자격 증명 제거)

    package org.sopt.app.common.config;
    
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.s3.S3Client;
    import software.amazon.awssdk.services.s3.presigner.S3Presigner;
    
    @Configuration
    public class AwsConfig {
    
        @Value("${cloud.aws.region.static}")
        private String regionValue;
    
        @Bean
        public S3Client s3Client() {
            Region region = Region.of(regionValue);
            return S3Client.builder()
                    .region(region)
                    .build(); // 기본 자격 증명 체인 사용
        }
    
        @Bean
        public S3Presigner s3Presigner() {
            Region region = Region.of(regionValue);
            return S3Presigner.builder()
                    .region(region)
                    .build(); // 기본 자격 증명 체인 사용
        }
    }
  3. S3Service.java 수정

Trouble Shooting ⚽️

Related ScreenShot 📷

Uncompleted Tasks 😅

To Reviewers 📢

@geniusYoo geniusYoo requested a review from Copilot April 25, 2025 16:29
@height
Copy link

height bot commented Apr 25, 2025

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR migrates AWS SDK v1 usage to AWS SDK v2 to resolve Jackson version conflicts and remove deprecated dependency usage. Key changes include:

  • Replacing AWS SDK v1 beans in AwsConfig.java with S3Client and S3Presigner beans from AWS SDK v2.
  • Updating S3Service.java to use AWS SDK v2 APIs for generating pre-signed URLs and deleting S3 objects.
  • Refactoring JwtTokenService.java to use LocalDateTime-based conversions for JWT token issuance.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/main/java/org/sopt/app/common/config/AwsConfig.java Migrated from AWS SDK v1 to AWS SDK v2 bean creation and updated variable naming.
src/main/java/org/sopt/app/application/s3/S3Service.java Replaced legacy S3 API calls with SDK v2 methods and updated pre-signed URL and deletion logic.
src/main/java/org/sopt/app/application/auth/JwtTokenService.java Updated date conversion for JWT tokens using LocalDateTime and ZoneId.
Comments suppressed due to low confidence (1)

src/main/java/org/sopt/app/application/auth/JwtTokenService.java:50

  • [nitpick] The variable name 'nowDate1PlusDays' could be renamed to 'expirationDate' to improve clarity about its purpose.
        val nowDate1PlusDays = Date.from(now.plusDays(1).atZone(ZoneId.systemDefault()).toInstant());

Comment on lines +108 to +111
// SDK v2 예외 처리
LoggerFactory.getLogger(S3Service.class).error("Error deleting S3 object {}: {}", objectKey, e.awsErrorDetails().errorMessage());
} catch (SdkException e) {
LoggerFactory.getLogger(S3Service.class).error("AWS SDK error deleting S3 object {}: {}", objectKey, e.getMessage());
Copy link

Copilot AI Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the deleteFile method, errors caught from SdkException and S3Exception are only logged without propagating the failure. Consider rethrowing the exception or handling it appropriately if deletion failure must be communicated to callers.

Suggested change
// SDK v2 예외 처리
LoggerFactory.getLogger(S3Service.class).error("Error deleting S3 object {}: {}", objectKey, e.awsErrorDetails().errorMessage());
} catch (SdkException e) {
LoggerFactory.getLogger(S3Service.class).error("AWS SDK error deleting S3 object {}: {}", objectKey, e.getMessage());
LoggerFactory.getLogger(S3Service.class).error("Error deleting S3 object {}: {}", objectKey, e.awsErrorDetails().errorMessage());
throw new RuntimeException("Failed to delete S3 object: " + objectKey, e);
} catch (SdkException e) {
LoggerFactory.getLogger(S3Service.class).error("AWS SDK error deleting S3 object {}: {}", objectKey, e.getMessage());
throw new RuntimeException("AWS SDK error deleting S3 object: " + objectKey, e);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] 배포 단계에서 AWS Credential 설정하도록 변경

1 participant