Más contenido relacionado
La actualidad más candente (20)
Similar a Serverless로 이미지 크롤링 프로토타입 개발기::유호균::AWS Summit Seoul 2018 (20)
Más de Amazon Web Services Korea (20)
Serverless로 이미지 크롤링 프로토타입 개발기::유호균::AWS Summit Seoul 2018
- 1. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
유호균
AWS KRUG STUDENT SUPPORT GROUP
Serverless로 이미지 크롤링
프로토타입 개발기
- 2. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
발표자 소개
• 유호균
• (현) AUSG(AWS KRUG Student Support)
• (현) 인하대학교 학부생 4학년 (취준생)
• (전) 스타트업 Team Mondrian 인턴
• (전) 소프트웨어 마에스트로 연수생
• (전) 대학생 연합 IT 동아리 Nexters 활동
• (전) 대학생 연합 IT 동아리 멋쟁이 사자처럼 활동
- 3. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
- 개발 동기
- 서버리스 & 크롤링 & 포스트모템이란?
- 어디서 크롤링을 해야 할까?
- 실패 & 실패 & …
- 포스트모템
발표 순서
- 4. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
개발 동기
- 5. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
대표님: 인턴도 3주 정도 남았는데,
기존 프로젝트도 잘 마무리되었고…
- 6. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
대표님: 3주 동안, 본인이 팀에 도움이
될만한 프로젝트를 직접 기획하고
개발하고 최종 발표를 해주세요
- 7. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
주니어 개발자인 내가
내가 3주 만에 무엇을 해낼 수 있을까…?
- 8. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
프로젝트가 끝나고 잠시 여유를 가지는
주변 팀원들을 관찰해봤더니…
회고록을 적으며 블로그를 쓰는 사람,
기술 문서를 정리하는 사람,
머신러닝을 POC하는 사람
- 9. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
머신러닝을 배우기에는 시간은 짧으니
데이터 수집&분류에 도움이 되는 도구를 만들자!
- 10. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
피자 Image 분류피자 Image 수집
No Pizza! -> Drop or 검증용으로 사용
이미지 학습Pizza!
기계학습된 모델 검증
또는
사람이 직접 Pizza & Non Pizza 분류
데이터 크롤러
또는
사람이 직접 수집
- 11. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
어떻게 정확히 이미지 분류 & 정제를 할까?
- 12. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
- 13. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
우리 스타트업 사람 뽑을 돈이 없어요
이미 정교하게 만들어진 모델도 없어요
어차피 최종 분류는 사람이 한다.
수집에 도움 되는 도구를 만들자!
- 14. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
프로그램을 만들 때 가장 먼저 해야 할 것.
Spec.
- 15. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. 스타트업은 돈이 없다. 가능한 Free Plan
2. 스타트업은 일손이 부족하다. 가능한 Automation
3. 나는 인턴이다. 나는 3주 후에 탈주해야 한다. 내가 없으면 프로그램을
못 사용할 수 있다. 가능한 Documentation
4. 팀원들이 익숙한 언어로 작성한다. 가능한 Node.js, Python
5. 3주의 데드라인 (진짜 Dead 할 것 같다)
- 16. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
서버리스 & 크롤링 & 포스트모템
- 17. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Monolithic Vs Microservice
- 18. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
이때 중요한 것이
AWS Lambda + API Gateway
Micro Service의 핵심
- 19. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
AWS 기반 마이크로서비스 아키텍처의 진화
S3
CloudFront
RDS
ElastiCache
EC2
Elastic Load
Balancing
EC2
Elastic Load
Balancing
Static
Content
Content
Delivery
API
Layer
Application
Layer
Persistency
Layer
Auto Scaling
Group
Auto Scaling
Group
출처: aws reinvent 2016 윤석찬님 Serverless 특집 中
Micro Service
- 20. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
AWS 기반 마이크로서비스 아키텍처의 진화
S3
CloudFront
Static
Content
Content
Delivery
API
Layer
Application
Layer
Persistency
Layer
API
Gateway
DynamoDBAWS
Lambda
출처: aws reinvent 2016 윤석찬님 Serverless 특집 中
Micro Service
- 21. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Web Crawling Vs Web Scraping
- 22. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• 부검, 즉 시체를 해부해서 사망 원인을 살펴보는 것.
• 잘된 점
• 아쉬운 점
• 후기, 개선해야 할 사항
Postmortem
- 23. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Serverless:
- Monolithic -> Microservice 의 방향으로 가는데 도움이 되는 도구&방법
Crawling:
- 웹 상의 원하는 정보를 추출
Postmortem:
- 프로젝트 후기, 잘한 점, 아쉬운 점, 개선해야할 점
Terms
- 24. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
어디서 이미지 크롤링을 해야할까?
- 25. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. Instagram API 2. Google Custom Search API 3. Image Net
Google Image
후보군들
- 26. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
실패 & 실패 & …
- 27. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. Instagram API 2. Google Custom Search API 3. Image Net
Google Image
후보군들
Bot, Block, Captcha…
- 28. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. Instagram API 2. Google Custom Search API 3. Image Net
Google Image
후보군들 이미 팀원이 사용하고 있음
- 29. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• 이미지 공유 서비스의 대명사 Instagram
• Instangram API를 사용해본 경험이 있음
• 앱에서 검색한 검색결과가 훌-륭
• 이미지들이 빠르게 업데이트되어 풍부한
자료로 학습 가능
혹시 Instagram?
- 30. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Instagram-API Limit
- 31. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
SandBox Mode?
• 앱에 10명 초대가능
• 초대된 유져에 한해 최대 20개의 미디어 표시
• API 사용량 및 속도제한
• 그 안에서 올바르게 동작하고, 앱을 출시해서 보내면
• IOS AppStore처럼 심사 후 정식 API 사용 허가
• ??? 3주밖에 없는데 Production 용으로 만들어서 제출해서 심사까지???
Instagram SandBox
- 32. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. Instagram API 2. Google Custom Search API 3. Image Net
Google Image
(슬슬 걱정되기 시작.
CSE마저 안된다면?)
- 33. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Google Custom Search Engine
• 맞춤형 검색 엔진을 만들 수 있음
• Endpoint API 형식으로도 제공
• API Query parameter가 많음
• 100query/1day 무료
• 추가 쿼리 10k까지 1000query/$5
- 34. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
https://www.googleapis.com/customsearch/v1?key=blabla
bla&cx=blablabla:qrg6sa_2mt8&q=김치&searchType=im
age&start=1&lowRange=0
Google CSE Example
- 35. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Google CSE API 단점 (Google Custom Search Engine)
• 구글 이미지 검색과 다른 Rank
• 세팅해야 할 파라미터들도 많다.
• 파라미터를 정교하게 세팅하지 않으면 검색결과 Bad
• 1p당 10개 * 100page = 최대 1000장 이상을 가져올 수 없음
• 원래 사용 용도가 특정 URL 내 검색용 (Ex. 내 블로그에 검색엔진 달기)
- 36. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. Instagram API 2. Google Custom Search API 3. Image Net
Google Image
모든 방법이 Fail…?
- 37. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. Instagram API 2. Google Custom Search API 3. Image Net
Google Image
혹시 캡차에 막히지
않지 않을까?
- 38. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
구글에서 높은 랭크를 가진
이미지를 추출할 수 있다면 당연 BEST!
(하지만 캡차가 출동한다면 어떨까)
Google Image Search
- 39. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• Selenium, Beautifulsoup, Scrapy
• Best Solution 일까 비교중 iCrawler 발견
• 그런데 우리 믿음의 지표인 Star 갯수가 너무 낮다
iCrawler
- 40. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
밑져야 본전, 예제대로 Just Try
고양이 검색결과.jpg
Just Try
- 41. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
밑져야 본전, 예제대로 Just Try
고양이 검색결과.jpg
Just Try
편-안
- 42. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
궁금증: 왜 되는 걸까? 내부는 어찌 동작하는 걸까?
-> iCralwer 소스코드를 까봄
-> 단순히 query string을 붙이는 구조
- 43. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Problem 1. 구글의 제한으로 1,000장이 최대 한계치다.
Solving :
- 라이브러리 내부 동작은 Custom Search API를 이용하는 게 아니다.
- https://www.google.co.kr/search?blahblahblah
- GET Request, Ajax이고, Paging offset 1000 이상 불가
- 그런데 1년 단위로도 여전히 1,000개씩 검색 가능
- 11년 x 1,000장 = 하나의 키워드에 11,000장
Problem & Solving
- 44. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Problem & Solving
Solving :
- 회사 계정으로 AWS S3의 Bucket에 저장한다.
- 내가 퇴사하더라도 AWS가 잘 저장해 두겠지.
Problem 2. 데이터가 로컬에 저장된다. 추후에 다른 개발자들과 공유해야 함.
- 45. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
2008년
“Cat”
2009년
“Cat”
2010년
“Cat”
2018년
“Cat”
…
= 1,750초 = 약 28분155초 + 155초 + 155초 + + 155초…
Problem & Solving
Problem 3. 이미 멀티 쓰레드 구조의 툴인데 너무 느리다.
11,000장당 28분 의 소요시간
- 46. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Trigger
Function
2008년
“Cat”
2018년
“Cat”
....
11개의 함수를
실행해도,
1개의 함수를 실행한
것과 동일한 소요시간
같은 함수에,
2008, 2009, …, 2018
파라미터만 바꿔서 실행지시
동시에 독립된 환경에서 병렬하게 실행!
155초
155초!
searchGoogle(2009, “cat”)
…
Problem & Solving
Solving :
- 람다의 병렬 실행구조
- 47. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Problem & Solving
Problem 4. 기다리는 시간이 지루하다. 알림이 필요하다.
Solving :
- 팀이 이용하고 있는 메신저 Slack의 Web-hook
- 크롤링이 끝나면 Slack Notification
- 48. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
인턴 종료
최종 발표 결과물
- 49. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
First Architecture
- 50. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Final Result
- 51. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Final Result
- 52. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Final Result
Bucket/음식_이름/검색엔진_년도/이미지 번호.jpgBucket/음식_이름/검색엔진_년도/이미지 번호.jpg
- 53. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Final Result
Bucket/음식_이름/검색엔진_년도/이미지 번호.jpgBucket/음식_이름/검색엔진_년도/이미지 번호.jpg
- 54. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
포스트모템
- 55. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
못한 점 & 그리고 개선
- 56. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
CTO : 왜 API Gateway는 붙이지 않았나요?
매번 크롤링하려면 AWS Lambda Dashboard를 통해서
트리거 해야 해서 불편해요
Me: Slack으로 Notification이 오니깐 Slack으로 Trigger
하도록 수정하면 좋을 것 같아요!
못한 점 1. API Gateway
- 57. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
외부 API Gateway가 있다면?
못한 점 1. API Gateway
- 58. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Slack Verification Token으로 Lambda의 실행 여부 인증
못한 점 1. API Gateway
- 59. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
- 60. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Lambda의 State를 어디에 보관하는 게 좋을까?
SQS: 연결 요청 대기등 순서조건을 만족해야 할 때 사용
RDS: Lambda에서 Connection 유지 문제로 어려움
ElasticCache: 항상 캐시 서버가 띄워져 있어야 함
DynamoDB: Connection 문제없이 빠른 응답으로 적합함
못한 점 2. Lambda State
Amazon
DynamoDB
Amazon
SQS
Amazon
RDS
Amazon
ElastiCache
- 61. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
- 62. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• 코드를 의존성(node_modules, pip)과 항상 함께 묶어서 수동 업로드해야 함
• AWS Lambda Dashboard에서 코드를 수정 후 일일이 적용해야 함
• CLI로 배포, 템플릿 형식으로 자동화된 배포를 진행하고 싶음
• CI/CD Process: Circle CI
• Code 관리, 자동화: Serverless Framework
• Template: AWS CloudFormation
못한 점 3. Code 관리가 어려움
AWS
CloudFormation
- 63. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
$ serverless deploy
Code Build & TestCode Push To VCS Automaton, Deploy
Framework
AWS
CloudFormation
- 64. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
잘한 점
- 65. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• 추후 이미지 Post Processing(리사이즈, 색변환)이
필요하면, 새로운 Lambda를 만들어서 확장하기 편함
• 구조가 유연해 단위 서비스당 적합한 언어를 사용 가능
(Lambda가 지원하는 언어들: python, node.js, Go, C#,
java)
잘한 점 1. 확장성 고려
- 66. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
- 이미지 리사이즈
- 색 공간 변환
- 이미지 정확도
등등 다양한 Post processing
추가 가능
잘한 점 1. 확장성 고려
- 67. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
- 오히려 개발할 때 보다, 지난 프로젝트를 뒤돌아보며
되짚어 볼 때 더 많이 배움
- 문서화를 잘 남겨놓아서 퇴사 후 자유로운 영혼
잘한 점 2. 포스트모템
- 68. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
최종 아키텍쳐
- 69. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Final Architecture
Total View
- 70. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Final Architecture
Service View
/crawl 피자
- 71. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
1. 프로젝트 전체 개발 과정을 리딩해본 유익한 경험
(비즈니스로직 개발, CI/CD Process, 유지 보수)
2. 커뮤니티에서 공부한 것을 실제 필요한 곳에 적용
3. 삽질은 항상 블로그 아티클과 발표자료로 공유
4. 개발 중에 항상 팀원들과 활발한 커뮤니케이션 필요
5. 주니어의 성장의 위의 과정으로 진행된다
Lessons Learned
- 72. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
최종 결과물
AWS
S3
(crawl-google-dev)
AWS CLOUD
SLACK
- 73. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
https://github.com/philographer/crawl-google
최종 결과물
- 74. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
ETC.
- 75. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• 항상 떠 있지 않아도 되는 서비스들
Ex) Batch성 작업, cron job, 이미지 리사이즈 서버
• 이전 작업과 관련이 없는, State가 없는 작업
(Elastic Cache, Dynamo를 이용하면 State를
이용할 수도 있음)
• 오래 걸리지 않으면서 병렬로 처리해야 하는 작업
Lambda 사용 예제
- 76. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
• 최대 메모리 3GB, 최대 수행시간 5분 제한
• Lambda는 SLA(Service Level Agreement)가 없음
• 기본 동시 수행 제한 1000개
• 임시파일, 다운로드는 “/tmp” 폴더에만 가능
Lambda 사용시 유의사항
- 77. © 2018, Amazon Web Services, Inc. or Its Affiliates. All rights reserved.
Cloud Craft
https://cloudcraft.co/
- 79. Now I’m Looking For a Job
- Summer Intern (2018.06.18 ~ 2018.08)
- Contract job (2018.08 ~ 2018.12)
- Full-Time (2019.01 ~ )
Github: https://github.com/philographer
LinkedIn: https://www.linkedin.com/in/yuhogyun/
Blog: https://philographer.github.io/about
Email: yoohoogun114@gmail.com