Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 에 파일을 업로드 하기 위해, 의존성과 configuration 설정을 추가하라 #47

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

yongjin5184
Copy link
Collaborator

@yongjin5184 yongjin5184 commented Jun 5, 2021

개요

  • 이미지 업로드를 구현하기 위해 S3 버킷을 할당하였습니다.
  • AWS 계정은 노션 문서의 dz-dark-brown 입니다

작업 내용

  • S3 에 파일을 업로드 하기 위해, 의존성과 configuration 설정을 완료하였습니다.

참고 사항

  • 프리티어 S3 무료 구간

AWS 프리 티어를 사용하는 고객은 Amazon S3를 무료로 시작할 수 있습니다. AWS 신규 가입 고객은 1년 동안 매달 5GB의 Amazon S3 스토리지(S3 Standard 스토리지 클래스), 20,000건의 GET 요청, 2,000건의 PUT, COPY, POST 또는 LIST 요청, 15GB의 데이터 송신 혜택을 받게 됩니다.

출처: https://aws.amazon.com/ko/s3/pricing/

  • S3 정책은 다음과 같이 주었습니다.
    { "Version": "2012-10-17", "Id": "Policy1622876424748", "Statement": [ { "Sid": "Stmt1622876421024", "Effect": "Allow", "Principal": "*", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::{bucket명}/*" } ] }

region:
static: ap-northeast-2
credentials:
access-key: AKIAYXA537A74IOP4V27
Copy link
Collaborator

Choose a reason for hiding this comment

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

access-key, secre-key 를 github에 올리면 유출 위험이 있습니다.

application-private.yml 파일을 만들어서 application.yml 파일에 include 하는 방법으로 수정을 제안드립니다.

그리고 application-private.yml 파일은 github ignore 에서 제외 되어야하고요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아하, 여기 있군요...
아래처럼 되어있네요.
adapter-client-api 에는 @SpringBootApplication 을 가진 클래스가 없는데데 추가해도 되나요?

@SpringBootApplication
public class Application {

    public static final String APPLICATION_LOCATIONS = "spring.config.location="
            + "classpath:application.yml,"
            + "classpath:aws.yml";

    public static void main(String[] args) {
        new SpringApplicationBuilder(Application.class)
                .properties(APPLICATION_LOCATIONS)
                .run(args);
    }
}```

Copy link
Collaborator

Choose a reason for hiding this comment

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

adapters/web/adapter-client-api layer 에는 @SpringBootApplication 애노테이션 추가하면 안됩니다.

@SpringBootApplication 는 applications layer 에만 추가되어야합니다.

@@ -5,6 +5,7 @@ dependencies {
implementation project(':domain')
implementation project(':common')

implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
Copy link
Collaborator

Choose a reason for hiding this comment

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

root/build.gradle 의 subprojects 안에 dependencyManagement안에 아래와 같이 추가해서
spring cloud stater 와 연관된 의존성들을 관리하는하는게 어떨지 제안드립니다.


    ext {
        springBootVersion = "2.3.4.RELEASE"
        springCloudVersion = "Hoxton.SR11"
        mockitoVersion = "3.4.0"
        lombokVersion = "1.18.12"
    }
...
dependencyManagement {
            imports {
                mavenBom "org.springframework.boot:spring-boot-dependencies:${springBootVersion}"
                mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
            }
        }
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

adapter-client-api layer 에서 s3 를 언제 사용해야하나요???

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아래와 같이 현재 작업 중입니다.
(익숙한 MVC 구조로 먼저 작업하고 현재 아키텍처로 바꾸고 있음)

S3 로 업로드하는 Component 를 하나 만들고, Component 를 Service 에서 가져다 쓰는 구조입니다.

@Component
public class UploadImageS3 {

  private final AmazonS3 amazonS3;

  @Value("${aws.s3.image.bucket}")
  private String bucket;

  public ... upload() {}
}

@Service
public class ImageManagerService {
  private final UploadImageS3 uploadImageS3;
  
  public ... Upload() {
    uploadImageS3.upload();
  }
}

@truman-show
Copy link
Collaborator

로컬 또는 테스트 환경에서는 access-key, secreat-key 를 사용하나 보안상

개발 또는 스테이지, 운영에서는 IamRole 인증을 사용하는게 좋을거같습니다.

용진님 생각은 어떠신가요?

@truman-show
Copy link
Collaborator

truman-show commented Jun 11, 2021

aws key를 삭제하는 커밋을 올린다음 머지가 될 경우 github에 영원히 기록이 남게됩니다.

key 와 관련된 커밋 자체를 삭제해야합니다.

git rebase -i hashCode 명령어를 이용하여 해당 커밋을 삭제해주세요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants