Skip to content

Instantly share code, notes, and snippets.

@ruseel
Last active October 13, 2023 03:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruseel/04570aa3dea6d0a2650d to your computer and use it in GitHub Desktop.
Save ruseel/04570aa3dea6d0a2650d to your computer and use it in GitHub Desktop.
Amazon EMR 에서 s3-dist-cp 사용하기
  • emr에서 s3-disp-cp를 어떻게 실행하나?
  • 각 option의 의미는 뭔가?
  • 어떻게 escape 시켜야 하나?

amazon emr 4.3.0 distribution 에서는 master 서버에 s3-dist-cp라는 명령을 바로 실행할 수 있다.[1][2]

src dest 옵션만 주면 기본 형태다. cp -R 명령과 동일하게 src 전체를 dest로 복사한다.

   s3-dist-cp --src s3://bucket-src --dest s3://bucket-dest 

여기에 보듯이 여러 옵션을 추가할 수 있다.

그 중에 small file problem을 피하기 위해 쓸 일이 있는 --srcPattern과 --groupBy는 옵션을 주면 이렇게 동작한다 (짐작이다. 이렇게 이해해도 나쁘지 않겠다.[3])

   files = list s3 path
   for f in files:
      if f matches value of --srcPattern 
        add to candidate file
      else
        continue

   merge files, grouped by regexp matching group of --groupBy

emr의 master로 접속할 때는 이렇게 한다.

  aws emr ssh --cluster-id 'j-XXXXXXX' --key-pair-file 'xxxx.pem' 

바로 실행하고 싶을 때는 뒤에 --command 's3-dist-cp --src s3://bucket-src --dest s3://bucket-dest' 붙여서 실행할 수 있다.

  aws emr ssh --cluster-id 'j-XXXXXXX' \
    --key-pair-file 'xxxx.pem' \
    --command 's3-dist-cp --src s3://bucket-src --dest s3://bucket-dest'

Input path does not exist: hdfs:/tmp/../files 라고 hadoop job실행중에 에러가 날 수 있는데 그리고 다들 자주 만나는 에러인 듯 싶은데[4] 내 경우에는 --groupBy나 --srcPattern와 regexp 매칭되는 파일이 없을 때 만났다. 에러메세지만 보고 짐작하기 힘드니 조심하자.

[1]: slowplow-analytics 사이트에 나온 것 처럼 /home/hadoop/lib/emr-s3distcp-1.0.jar 를 실행하지 않아도 된다. 이 글은 2013년도에 쓰여진 글이라서 그런 듯하다.
[2]: http://docs.aws.amazon.com/ElasticMapReduce/latest/DeveloperGuide/UsingEMR_s3distcp.html amazon 에 언급된 것처럼 emr step으로서 추가해도 되겠다. 직접 해보진 않았다.
[3]: FileInfoListing.java 파일을 보고 짐작하기에 그랬다. 직접 실행하고 결과를 보아도 그래 보인다. 그래도 짐작이다.
[4]: https://forums.aws.amazon.com/message.jspa?messageID=501060

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment