Slide 1

Slide 1 text

LambdaΛ࢖ͬͯJawsDays ΛHackͯ͠ΈΑ͏! +"84%":4 5PTIJIJSP'VSVOP

Slide 2

Slide 2 text

ɾWiFi SSID->jawsdays_workshop ɾWiFi ύεϫʔυ->workshop02 ɾࢿྉ-> https://github.com/toshihirock/ jaws2016-lambda-hands-on

Slide 3

Slide 3 text

લఏ ɾॳ৺ऀ޲͚ͷߨशͳͷͰ೉қ౓͸ߴ͋͘Γ ·ͤΜɻ͕࣌ؒ༨ͬͨํ͸վ଄͢ΔͳͲࣗ༝ ʹ༡ΜͰΈ͍ͯͩ͘͞ɻ ɾLambdaͷίʔυ࣮૷αϯϓϧ͸Node.jsͰ ߦ͓ͬͯΓ·͢ɻJava,PythonͰͷαϯϓϧ͸ ͳ͍఺͸ྃ͝ঝ͍ͩ͘͞ɻ

Slide 4

Slide 4 text

΍Δ͜ͱɺ΍Βͳ͍͜ͱ ΍Δ͜ͱ ɾϋϯζΦϯܗࣜͰLambdaͰԿ͔Λ࡞ͬͯ ༡ΜͰΈΔ(༡ͼͳͷͰۀ຿޲͚Ͱ͸ͳ͍) ΍Βͳ͍͜ͱ ɾLambdaͷৄࡉͳઆ໌ ɾTwitterAPIͷৄࡉ

Slide 5

Slide 5 text

ࣗݾ঺հ ɾݹ໺ढ़޿(@toshihirock) ɾNTTιϑτ΢ΣΞגࣜձࣾ ɾAWSۀ຿͸1೥͙Β͍ ɾ޷͖ - Lambda - Podcast - ϫʔϧυτϦΨʔ

Slide 6

Slide 6 text

ຊ೔ͷϋϯζΦϯ

Slide 7

Slide 7 text

-BNCEBΛ࢖ͬ ͯKBXTEBZTʹπ Πʔτ͠Α͏

Slide 8

Slide 8 text

LambdaΛ࢖ͬͯJawsDaysΛHackͬͧ͢ ɾπΠʔτ͍ͤͨ͞಺༰ͷςΩετΛS3ʹ഑ஔ ɾIAMϩʔϧΛ෇༩ͨ͠LambdaͰS3͔ΒςΩ ετϑΝΠϧΛऔಘ͠ɺϥϯμϜʹϐοΫΞοϓ ɾ༧Ί࡞੒ͯ͋͠ΔAPIGatewayʹ޲͚ͯPOST ϦΫΤετΛ࣮ࢪ ɾAPIGatewayܦ༝Ͱ@jaws2016_lambda͔Β ϋογϡλά #jawsdays Λ෇͚ͯπΠʔτ͞Ε Δ(࡞੒ࡁΈ)

Slide 9

Slide 9 text

֓ཁਤ

Slide 10

Slide 10 text

஌ࣝฤ

Slide 11

Slide 11 text

S3? ɾΦϯϥΠϯετϨʔδ ɾߴ͍ݎ࿚ੑ(99.999999999%) ɾ҆Ձ ɾ༰ྔແ੍ݶ(1ϑΝΠϧ5TB·Ͱ) ࠓճ͸πΠʔτจݴΛஔ͘৔ॴͱͯ͠ར༻

Slide 12

Slide 12 text

Lambda? ɾΠϕϯτυϦϒϯ΍ cronͷΑ͏ʹఆظλΠϛϯάͰϢʔβʔ͕ॻ ͍ͨίʔυΛ࣮ߦͰ͖Δ ɾίʔυ͸Node.js,Java,Python ɾ࠷ۙVPC΋ରԠ ɾৄࡉ͸ެࣜࢀর

Slide 13

Slide 13 text

IAMϩʔϧ? ɾϢʔβʔ΍LambdaɺEC2ͳͲͷϦιʔεʹର ͯ͠໾ׂ(Role)ΛࢦఆͰ͖Δɻྫ͑͹ʮS3ͷRead ݖݶʯͳͲ ɾϩʔϧ͸Lambda࡞੒࣌ʹ෇༩͢Δ͜ͱͰઃఆ ͞ΕͨAPIͷkick͕Ͱ͖Δ ࠓճͷྫͰ͸Lambda͔ΒS3ͷόέοτͷ৘ใΛ औಘ͍ͨ͠ͷͰLambda޲͚ͷ্هʹ֘౰͢Δ IAMϩʔϧΛ࡞੒͢Δ

Slide 14

Slide 14 text

࡞ۀͷྲྀΕ ɾS3όέοτʹπΠʔτจݴͷ഑ஔ ɾLambda༻IAMϩʔϧͷ࡞੒ ɾLambda Functionͷ࡞੒ ɾLambda Functionͷఆظ࣮ߦͷઃఆ

Slide 15

Slide 15 text

४උฤ(S3)

Slide 16

Slide 16 text

αʔϏεҰཡ͔ΒS3ͷબ୒

Slide 17

Slide 17 text

όέοτͷ࡞੒ ʮ$SFBUF#VDLFUʯ Λબ୒ όέο τ໊Λ࡞੒ɻόέοτ ໊͸SFHJPOͰϢχʔΫͳ ඞཁ͋Γ Ϧʔδϣϯ͸ 5PLZP ʮ$SFBUFʯ Λબ୒

Slide 18

Slide 18 text

S3΁഑ஔ͢ΔςΩετϑΝΠϧͷ࡞੒ ɾ֤ࣗͷPCͷ޷͖ͳΤσΟλͰπΠʔτͤ͞ ͍ͨจݴूΛ࡞੒͍ͯͩ͘͠͞ɻจࣈίʔυ ͸UTF-8Ͱอଘ ɾ೚ҙͷσϦϛλ۠੾ΓͰ࡞੒͍ͯͩ͘͠͞ɻ ҎԼྫ͸σϦϛλ͸վߦ(\r\n) ɾ࡞੒ޙɺʮtweetList.txtʯͰϩʔΧϧʹอ ଘ

Slide 19

Slide 19 text

֬ೝ # จࣈίʔυ֬ೝ $nkf -g tweetList.txt # վߦίʔυ֬ೝ.LF = $.CR = ^MͰදࣔ $cat -e tweetList.txt

Slide 20

Slide 20 text

S3΁ςΩετϑΝΠϧͷΞοϓϩʔυ ʮ6QMPBEʯΛ બ୒ ςΩετΛ υϥοάΞϯυυϩο ϓͰΞοϓϩʔυ ʮ4UBSU 6QMPBEʯΛબ୒ ઌ΄Ͳ࡞੒ͨ͠όέοτΛબ୒ޙɺҎԼͷૢ ࡞ͰΞοϓϩʔυ

Slide 21

Slide 21 text

֬ೝ

Slide 22

Slide 22 text

४උฤ(IAMϩʔϧ)

Slide 23

Slide 23 text

αʔϏεҰཡ͔ΒIAMͷબ୒

Slide 24

Slide 24 text

ϩʔϧͷ৽ن࡞੒ ʮ3PMFTʯΛબ ୒ ʮ$SFBUF /FX3PMFʯΛબ ୒

Slide 25

Slide 25 text

ϩʔϧ໊ͷܾఆ ೚ҙͷ 3PMF/BNFΛೖྗ ʮ/FYU 4UFQʯΛબ୒

Slide 26

Slide 26 text

ϩʔϧλΠϓͷબ୒ ʮ"84 -BNCEBʯΛબ୒ LambdaʹΞλον͍ͨ͠ϩʔϧΛ࡞੒͢ΔͷͰLambdaΛ બ୒͠·͢

Slide 27

Slide 27 text

ϙϦγʔͷબ୒ ʮTʯͱೖྗ ʮ"NB[PO43F BE0OMZ"DDFTTʯ Λબ୒ ʮ/FYU 4UFQʯΛબ୒ طʹAWSଆͰ༻ҙ͍ͯ͠ΔS3΁ͷReadOnly ͷϙϦγʔΛ෇༩

Slide 28

Slide 28 text

ϨϏϡʔ ֬ೝޙɺ ʮ$SFBUF3PMFʯ Λબ୒

Slide 29

Slide 29 text

LambdaΛ࡞Ζ͏!

Slide 30

Slide 30 text

(ޙͰར༻)ίʔυͷ४උ ɾҎԼͷ಺༰Λίϐϖͯ͠೚ҙͷςΩετΤ σΟλʹష͓ͬͯ͘ ɾhttps://github.com/toshihirock/jaws2016- lambda-hands-on/blob/master/index.js

Slide 31

Slide 31 text

(ޙͰར༻)ίʔυͷ४උ 4ͷઃఆ͸ దٓࣗ෼ͷઃఆʹ มߋ "1*(BUFXBZͷ ೝূΩʔΛࢦఆ

Slide 32

Slide 32 text

αʔϏεҰཡ͔ΒLambdaͷબ୒

Slide 33

Slide 33 text

Functionͷ࡞੒ ※ॳΊͯͷํͷը໘ ʮ$SFBUFB -BNCEBGVODUJPOʯ Λબ୒ ʮ(FU4UBSUFE /PXʯΛબ୒ ※طʹFunction͕͋Δਓͷը໘

Slide 34

Slide 34 text

Blueprint ར༻͠ͳ͍ ͷͰʮ4LJQʯΛબ ୒

Slide 35

Slide 35 text

Functionͷઃఆ(1/2) /PEFKT /BNFٴͼ %FTDSJQUJPO͸Կ Ͱ΋0, &EJUDPEF JOMJOF ઌ ΄Ͳͷ಺༰Λ ίϐϖ

Slide 36

Slide 36 text

Functionͷઃఆ(2/2) ઌ ΄Ͳ࡞੒ͨ͠4΁ ΞΫηεͰ͖Δ3PMF ໊ *OEFYIBO EMFS /P71$ ࠷ޙʹ ʮ/FYUʯ

Slide 37

Slide 37 text

ϨϏϡʔ ઃఆ͕໰୊ͳ ͚Ε͹ʮ$SFUF GVODUJPOʯ

Slide 38

Slide 38 text

࡞੒ ೔ຊޠ͕จࣈԽ͚͠· ͢ɻɻؾʹͳΔਓ͸ຊϖʔδ Ͱ࠶౓ίϐϖͯ͠ߋ৽͢Δͱ௚ Γ·͢ɻ

Slide 39

Slide 39 text

ςετͯ͠ΈΔ ʮ5FTUʯΛબ୒

Slide 40

Slide 40 text

ςετͯ͠ΈΔ ʮ4BWFBOE UFTUʯΛબ୒ ςϯϓϨʔτ͸ԿͰ ΋0, πΠʔτ৘ใ͸4͔ Βऔಘ͢ΔͷͰ

Slide 41

Slide 41 text

ςετͯ͠ΈΔ ੒ޭ͢Ε͹ը໘Լ෦ ʹπΠʔτͨ͠จࣈྻ͕දࣔ ͞ΕΔ ࣦഊ͢Δͱ੺͍Τϥʔදࣔ ʹͳΔ

Slide 42

Slide 42 text

ςετͯ͠ΈΔ 5XJUUFSͰ΋֬ೝ

Slide 43

Slide 43 text

Τϥʔ͕ൃੜ͍ͯ͠Δ৔߹ ɾը໘Լ෦(Log output)ʹϩά৘ใ͕දࣔ͞ ΕΔͷͰ֬ೝ ɾඞཁʹԠͯ͡console.logͳͲΛ࢓ࠐΜͰσ όοάͯ͠ΈΔ

Slide 44

Slide 44 text

botΒ͘͠ ఆظ࣮ߦͤͯ͞ΈΔ

Slide 45

Slide 45 text

ఆظ࣮ߦͷઃఆ ʮ&WFOUTPVSDFTʯλ ϒΛબ୒ ʮ"EEFWFOU TPVSDFʯΛબ୒

Slide 46

Slide 46 text

ఆظ࣮ߦͷઃఆ ೚ҙͷ࣌ؒؒ ִΛઃఆ ࠷খ෼ ʮ$MPVE8BUDI&WFOUT 4DIFEVMFʯΛબ୒ ໊শΛదٓมߋ 4VCNJUܾͯ͠ఆ

Slide 47

Slide 47 text

֬ೝ 5XJUUFS্Ͱ΋֬ೝ ͠͹͠଴ͬͯ֬ೝ

Slide 48

Slide 48 text

͕࣌ؒ༨ͬͨਓ͸

Slide 49

Slide 49 text

͕࣌ؒ༨ͬͨਓ͸ ɾ޷͖ʹ৭ʑ΍ͬͯΈ͍ͯͩ͘͞ʂʢఆظ࣮ߦ ִؒΛม͑ΔɺจݴͷύλʔϯΛ૿΍͢ͳͲʣ ɾLambda͔Β௚઀TwitterͷAPIΛୟ͘ͳͲΛ ͯ͠Έ͍ͨ৔߹͸Ҏલॻ͍ͨͪ͜ΒΛࢀߟʹ΍ͬ ͯΈ͍ͯͩ͘͞ http://qiita.com/toshihirock/items/ d28505442526e0ae7793

Slide 50

Slide 50 text

Thanks!