Slide 1

Slide 1 text

AWS CDK Conference Japan
 ͦΕͰ΋Զ͸AWS CDK͕࡞ΔϦιʔεʹ෺ཧ໊Λ෇͚͍ͨ ʙCDKͷϕετϓϥΫςΟε͸ຊ౰ʹϕετͳͷ͔ʙ CXࣄۀຊ෦ IoTࣄۀ෦ 2022/04/09 ࠤ౻ஐथ 1

Slide 2

Slide 2 text

ࣗݾ঺հ @tmk2154 @tomoki10 • ࠤ౻ஐथ • Ϋϥεϝιουגࣜձࣾ • CXࣄۀຊ෦ IoTࣄۀ෦ • ݱࡏɿαʔόʔαΠυ݉ΠϯϑϥΤϯδχΞ ݉QAͱ͔AWSΞΧ΢ϯτͷηΩϡϦςΟ౳ • झຯɿAPEXɺࢄา • ޷͖ͳAWSαʔϏεɿLambdaɺCDK

Slide 3

Slide 3 text

AWS CDKͷϕετϓϥΫςΟεͰ͸Ϧιʔεͷࣗಈ໊෇͚͕ਪ঑͞Εͯ·͢
 ͚Ͳɺࣗಈ໊෇͚ͷϦιʔε໊ਏ͘ͳ͍Ͱ͔͢ʁʁ 3 ໰୊ఏى Fargate Cluster/ServiceͱConstructͷidʹ؀ڥ໊+ݻఆ໊+Ϧιʔε໊Λઃఆͨ͠৔߹ͷදࣔྫ

Slide 4

Slide 4 text

4 ઌਓͷݴ༿ https://www.amazon.co.jp/ιϑτ΢ΣΞΞʔΩςΫνϟͷجૅ-—ΤϯδχΞϦϯάʹجͮ͘ମܥతΞϓϩʔν-Mark-Richards/dp/4873119820/ ʮΞʔΩςΫτʹ͸աڈͷ࣌୅͔Β࢒͞Ε͍ͯΔ લఏ΍ެཧΛٙ͏ͱ͍͏ॏཁͳ੹೚͕͋Δʯ
 P.viiΑΓ

Slide 5

Slide 5 text

5 ໨࣍ • AWS CDKϕετϓϥΫςΟεͱ͸ • ࠓճऔΓ্͛Δ߲໨ • Ϧιʔεͷࣗಈ໊෇͚ͷ֓ཁ • ໰୊ͱߟ͑Δཧ༝ • ղܾࡦ

Slide 6

Slide 6 text

6 AWS CDKϕετϓϥΫςΟεͱ͸ AWS CDKͷϕετϓϥΫςΟεʹ͍ͭͯॻ͔ΕͨAWSϒϩά https://aws.amazon.com/jp/blogs/news/best-practices-for-developing-cloud-applications-with-aws-cdk/ ओͳ಺༰ • CDKͷ఩ֶ • ૊৫ͰͷऔΓ૊Ήࡍͷ৺ಘ • ίʔυ؅ཧํ๏ • ConstructϥΠϒϥϦͷϕετϓϥΫςΟε • AWS CDK ΞϓϦέʔγϣϯͷ
 ϕετϓϥΫςΟε

Slide 7

Slide 7 text

7 AWS CDKϕετϓϥΫςΟεͱ͸ AWS CDKͷϕετϓϥΫςΟεʹ͍ͭͯॻ͔ΕͨAWSϒϩά https://aws.amazon.com/jp/blogs/news/best-practices-for-developing-cloud-applications-with-aws-cdk/ ओͳ಺༰ • CDKͷ఩ֶ • ૊৫ͰͷऔΓ૊Ήࡍͷ৺ಘ • ίʔυ؅ཧํ๏ • ConstructϥΠϒϥϦͷϕετϓϥΫςΟε • AWS CDK ΞϓϦέʔγϣϯͷ
 ϕετϓϥΫςΟε

Slide 8

Slide 8 text

8 ϕετϓϥΫςΟε͸·ͩૣ͍ͱײͨ͡Β ॳ~தڃऀ޲͚ͷ࿩ͰҎલొஃͨ͠ͷͰͪ͜Β΋ݟ͍ͯͩ͘͞(એ఻) https://dev.classmethod.jp/articles/aws-devday-online-japan-know-how-from-initial-development-to-operation-on-how-to-use-aws-cdk/ ओͳ಺༰ • CDKͷ಺෦ߏ଄ͷུ֓ • ։ൃ࣌Α͘೰Ή෦෼ͷิ଍ • ։ൃ࣌ͷϊ΢ϋ΢ • ύΠϓϥΠϯߏங࣌ͷબ୒ࢶ • ӡ༻࣌ͷϊ΢ϋ΢

Slide 9

Slide 9 text

9 AWS CDK ΞϓϦέʔγϣϯͷϕετϓϥΫςΟε ॻ͔Ε͍߲ͯͨ໨(Օ৚ॻ͖ɿ߲໨໊ɺվߦԼͷίϝϯτɿࣗ෼ͷղऍ) • σϓϩΠ࣌Ͱ͸ͳ͘ɺ߹੒࣌ʹܾఆ͢Δ
 CfnͷύϥϝʔλͰͳ͘CDKͷςϯϓϨʔτੜ੒࣌ʹ஋ΛຒΊࠐ΋͏ • ࣗಈͰੜ੒͞ΕΔϦιʔε໊Λ࢖༻͠ɺ෺ཧతͳ໊લΛ࢖༻͠ͳ͍ • σϓϩΠཁ݅ʹԠͯ͡ɺΞϓϦέʔγϣϯͷStageΛෳ਺ͷStackʹ෼ׂ͢Δ
 ׬ᘳͳਖ਼ղ͸ͳ͍͕ελοΫ͸ঢ়گʹԠͯ͡෼ׂ • cdk.context.jsonΛίϛοτͯ͠ɺ֎෦తͳཁҼͰ߹੒݁Ռ͕มΘͬͯ͠·͏͜ͱΛආ͚Δ
 ҙਤͤͣϦιʔεͷߋ৽͕ൃੜ͠ͳ͍Α͏ʹ͢ΔͨΊͷ஌ܙ • AWS CDKͰϩʔϧͱηΩϡϦςΟάϧʔϓΛ؅ཧͰ͖ΔΑ͏ʹ͢Δ
 CDKͰҰ෦ఏڙ͞Ε͍ͯΔϩʔϧ΍ηΩϡϦςΟάϧʔϓੜ੒ػೳΛ࢖͏ͱ࠷খݖݶͰ࣮૷͠΍͍͢ • શͯͷStageΛίʔυͰϞσϧԽ͢Δ
 ؀ڥ͝ͱʹStackϑΝΠϧΛ࡞Βͣɺ؀ڥ͝ͱͷ஋͸ύϥϝʔλͰ੾Γସ͑Δͱ؀ڥࠩҟ͕࠷খʹͳΔ • શͯΛଌఆ͢Δ
 ϝτϦΫε΍μογϡϘʔυͳͲΛ࡞ΕΔϝιουΛ׆༻͠Α͏

Slide 10

Slide 10 text

10 AWS CDK ΞϓϦέʔγϣϯͷϕετϓϥΫςΟε ॻ͔Ε͍߲ͯͨ໨(Օ৚ॻ͖ɿ߲໨໊ɺվߦԼͷίϝϯτɿࣗ෼ͷղऍ) • σϓϩΠ࣌Ͱ͸ͳ͘ɺ߹੒࣌ʹܾఆ͢Δ
 CfnͷύϥϝʔλͰͳ͘CDKͷςϯϓϨʔτੜ੒࣌ʹ஋ΛຒΊࠐ΋͏ • ࣗಈͰੜ੒͞ΕΔϦιʔε໊Λ࢖༻͠ɺ෺ཧతͳ໊લΛ࢖༻͠ͳ͍ɹɹˡ ʂʂʂʂʂʂʂʂʂʂʂʂ • σϓϩΠཁ݅ʹԠͯ͡ɺΞϓϦέʔγϣϯͷStageΛෳ਺ͷStackʹ෼ׂ͢Δ
 ׬ᘳͳਖ਼ղ͸ͳ͍͕ελοΫ͸ঢ়گʹԠͯ͡෼ׂ • cdk.context.jsonΛίϛοτͯ͠ɺ֎෦తͳཁҼͰ߹੒݁Ռ͕มΘͬͯ͠·͏͜ͱΛආ͚Δ
 ҙਤͤͣϦιʔεͷߋ৽͕ൃੜ͠ͳ͍Α͏ʹ͢ΔͨΊͷ஌ܙ • AWS CDKͰϩʔϧͱηΩϡϦςΟάϧʔϓΛ؅ཧͰ͖ΔΑ͏ʹ͢Δ
 CDKͰҰ෦ఏڙ͞Ε͍ͯΔϩʔϧ΍ηΩϡϦςΟάϧʔϓੜ੒ػೳΛ࢖͏ͱ࠷খݖݶͰ࣮૷͠΍͍͢ • શͯͷStageΛίʔυͰϞσϧԽ͢Δ
 ؀ڥ͝ͱʹStackϑΝΠϧΛ࡞Βͣɺ؀ڥ͝ͱͷ஋͸ύϥϝʔλͰ੾Γସ͑Α͏ • શͯΛଌఆ͢Δ
 ϝτϦΫε΍μογϡϘʔυͳͲΛ࡞ΕΔϝιουΛ׆༻͠Α͏

Slide 11

Slide 11 text

11 ϕετϓϥΫςΟεͷৄࡉ ࣗಈͰੜ੒͞ΕΔϦιʔε໊Λ࢖༻͠ɺ෺ཧతͳ໊લΛ࢖༻͠ͳ͍

Slide 12

Slide 12 text

෺ཧ໊Λ࢖͏৔߹ͷσϝϦοτ • ΠϯϑϥͷҰ෦Λෳ਺σϓϩΠ͢Δ͜ͱ͕Ͱ͖ͳ͍ • Ϧιʔεʹഁյతมߋ͕൐͏৔߹ɺ࠶࡞੒ʹࣦഊ͢Δ 12 ϕετϓϥΫςΟεͷৄࡉ Amazon DynamoDB AWS CDK Table A Hoge Table A Fuga Amazon DynamoDB AWS CDK Table A ෺ཧ໊Λݻఆ͠ͳ͍৔߹ ෺ཧ໊Λݻఆ͢Δ৔߹ 1ճ໨ 2ճ໨ ςʔϒϧ ࡞੒ ςʔϒϧ ࡞੒ 1ճ໨ 2ճ໨

Slide 13

Slide 13 text

ܦݧ͔Β෺ཧ໊Λ࢖͏৔߹ͷσϝϦοτ • ࡟আ࣌ͷϙϦγʔΛอޢ(RemovalPolicy.RETAIN)Ͱઃఆͨ͠/͞ΕͯΔ৔߹
 ελοΫ࡟আޙɺ࠶σϓϩΠ࣌ʹલճ࣮ߦͨ͠Ϧιʔε͕ॏෳࣦ͠ഊ͢Δ
 ҙਤͤͣอޢઃఆʹͳ͍ͬͯΔϦιʔε͕͋ΔͱσϓϩΠ͢Δ·Ͱؾ͚ͮͳ͍
 13 ෺ཧ໊ͷσϝϦοτ AWS CDK AWS CDK ෺ཧ໊Λݻఆ͠ͳ͍৔߹ ෺ཧ໊Λݻఆ͢Δ৔߹ 1ճ໨ 2ճ໨ Lambda ࡞੒࣌ Lambda ࡞੒࣌ 1ճ໨ 2ճ໨ Amazon CloudWatch Amazon CloudWatch Logs Hoge Logs Fuga Logs

Slide 14

Slide 14 text

14 ຊ౰ʹͦ͏͔ࠓҰ౓ٙͬͯΈΔ

Slide 15

Slide 15 text

෺ཧ໊Λ࢖͏৔߹ͷσϝϦοτ • ΠϯϑϥͷҰ෦Λෳ਺σϓϩΠ͢Δ͜ͱ͸Ͱ͖ͳ͍
 →ෳ਺ਓ։ൃ࣌ͷ૝ఆ?Ϧιʔε໋໊نଇ͸CDKͷίʔυͱCfnͷ࢓༷Λಡ·ͳ͍ͱ෼͔Βͣ
 ɹࣅͨΑ͏ͳ໊લͷϦιʔε͕ෳ਺Ͱ͖Δͱؔ࿈͕෼͔ΒͣٯʹෆศͰ͸ʁ
 →Ϧιʔε໊ͷিಥ͸໋໊نଇ(ex.Ϧιʔεʹݸਓ͝ͱͷ؀ڥ໊Λ෇͚Δ)Ͱճආ͸Մೳ
 →ͦ΋ͦ΋Stack໊͕ҟͳͬͯ΋Constructͷid͕ಉͩ͡ͱॏෳ͢ΔϦιʔε͕Ұ෦ଘࡏ͢Δ
 • Ϧιʔεʹഁյతมߋ͕൐͏৔߹ɺ࠶࡞੒ʹࣦഊ͢Δ
 →ྫʹ͋ΔDynamoDBͷKeySchemaͷมߋ͸ςʔϒϧ͕Ұ౓ഁغ͞ΕΔ
 ɹϢʔβଆ͸ͦͷةݥੑʹؾ͚ͮΔΑ͏ʹ࡞੒ʹࣦഊͨ͠ํ͕ྑ͍ͷͰ͸ʁ 15 ϕετϓϥΫςΟεͷৄࡉ

Slide 16

Slide 16 text

ࢀর੾Εϩά ࢀর੾Εϩά • ࠶σϓϩΠ࣌ʹલճ࣮ߦͨ͠Ϧιʔε໊͕ॏෳ͠ͳ͍
 →ҎલͷϦιʔε͸࢒ΔͷͰ͜·Ίʹ࡟আ͠ͳ͍ͱେྔʹϦιʔε͕࢒Γ
 ɹͲΕ͕ݟ͍ͨ΋ͷ͔ɺ࡟আͯ͠ྑ͍ͷ͔͕෼͔ΓͮΒ͘ͳΔ 16 ϕετϓϥΫςΟεͷৄࡉ AWS CDK 1ճ໨ Logs AWS CDK 2ճ໨࠶σϓϩΠ Logs Logs AWS CDK nճ໨࠶σϓϩΠ Logs Logs Logs Logs Logs Logs Logs Logs ;͏ɺ៉ྷʹͳͬͨͧʂ ͲͷϩάΛ ݟΕ͹ྑ͍ͷʁ ։ൃऀ

Slide 17

Slide 17 text

17 ผελοΫͰಉ͡ϦιʔεΛ࡞Δ஌ܙ https://speakerdeck.com/tomoki10/know-how-from-initial-development-to-operation-on-how-to-use-aws-cdk?slide=11

Slide 18

Slide 18 text

18 ผελοΫͰಉ͡ϦιʔεΛ࡞Δ஌ܙ ը૾Ҿ༻ݩɿ https://aws.amazon.com/jp/blogs/aws/boost-your-infrastructure-with-cdk/ new dynamodb.Table(this, `${id}-items`, { tableName: `${id}-items`, partitionKey: { name: "itemId", type: dynamodb.AttributeType.STRING, }, }); const app = new cdk.App(); new UserAStack(app, `${envName}-${projectName}-UserAStack`, {} ); ໋໊نଇ͕ϦιʔεͰҟͳΓҰ෦(Aurora/WAFͳͲ)͸ ελοΫ໊͕ҟͳͬͯ΋Ϧιʔε໊͕ಉ͜͡ͱ΋͋Δ ͷͰ id Λ͚ͭΔ͜ͱͰॏෳΛճආͰ͖Δ envNameͱprojectName͸cdk.json͔Β஫ೖ͢Δ envName͸ݸਓ͝ͱ projectName͸PJΛࣝผ͢ΔͨΊઃఆ

Slide 19

Slide 19 text

ௐࠪ/ӡ༻ͰԿ౓΋֬ೝ͢Δ৔߹ɺର৅ͷϦιʔε͕෼͔Γʹͯ͘͘ਏ͍ 19 ܦݧ͔Βࣗಈ໊෇͚ͷ৔߹ͷਏ͍෦෼ Fargate Cluster/ServiceͱConstructͷidʹ؀ڥ໊+ݻఆ໊+Ϧιʔε໊Λઃఆͨ͠৔߹ͷදࣔྫ

Slide 20

Slide 20 text

• ೝ஌ෛՙͷதͷ಺ࡏੑೝ஌(ࠓճ͸ௐࠪʹඞཁͳهԱ)ෛՙ͕ߴ͘ͳΔ
 →։ൃ΍ௐࠪͳͲຊདྷ࣮ࢪ͍ͨ͠࡞ۀ༻ͷϫʔΩϯάϝϞϦ͕গͳ͘ͳΔ
 →ർฐ͠ੜ࢈ੑ௿Լ(ݸਓͷײ૝Ͱ͢) • ҰͭϦιʔεΛࣗಈͰ͚ͭΔͱCloudWatch LogsͷϩάάϧʔϓͳͲ
 ؔ࿈͢ΔϦιʔε΋ࣗಈͰ໊෇͚͞ΕΔ
 20 ܦݧ͔Βࣗಈ໊෇͚ͷ৔߹ͷਏ͍෦෼ ࢖͍͍ͨ ϦιʔεA ϦιʔεAͷ ϋογϡ໊ ϦιʔεA͕ ؔ࿈ͯ͠ੜ੒ ͨ͠ϦιʔεB ϦιʔεBͷ ϋογϡ໊

Slide 21

Slide 21 text

21 ϕετϓϥΫςΟεΛ͋ΒͨΊͯݟฦ͢

Slide 22

Slide 22 text

22 ϕετϓϥΫςΟεΛ͋ΒͨΊͯݟฦ͢

Slide 23

Slide 23 text

23 Ͱ͖·ͤΜͰͨ͠ʂ

Slide 24

Slide 24 text

24 ݁ہϦιʔε໊͸Ͳ͏͢΂͖͔ ࣗ෼ͳΓͷ݁࿦ • ։ൃ/ௐࠪ/ӡ༻ͳͲͰΑ֬͘ೝ͢ΔϦιʔε͸໊લΛݻఆ͢Δ
 αʔϏεͷྫ • ECS΍LambdaͳͲͷίϯϐϡʔςΟϯάαʔϏε • DynamoDB΍S3ͳͲͷετϨʔδ • μογϡϘʔυ໊΍Ξϥʔτ໊ • ্هҎ֎ͷαʔϏε͸Ͱ͖Δ͚ͩݻఆ͠ͳ͍

Slide 25

Slide 25 text

25 ·ͱΊ • CDKͷϕετϓϥΫςΟε͕ຊ౰͔վΊͯߟ͑ͯΈͨ • ެཧΛٙ͏͜ͱ͸ΞʔΩςΫτͷ໾໨ • ࣗಈͰੜ੒͞ΕΔϦιʔε໊Λ࢖༻͠ɺ෺ཧతͳ໊લΛ࢖༻͠ͳ͍ • ϕετϓϥΫςΟεͰड़΂ΒΕ͍ͯΔར఺ΛվΊͯ֬ೝ • ϕετͰͳ͔ͬͨܦݧͷ঺հ • ζϘϥͳਓؒ(ࢲ)ͷ৔߹ɺෆཁϦιʔε͕େྔʹ࢒Δ • ࣗಈϦιʔε໊Ͱೝ஌ෛՙ͕ߴ͘ͳΔ • Ϧιʔε໊ͷࣗಈੜ੒͸΄Ͳ΄Ͳʹɻਏ͍࣌͸ݻఆԽ͠Α͏

Slide 26

Slide 26 text

26 additional JAWS CDK Λ্ཱ͍͖͍ͪ͛ͯͨʂ΋ͬͱ஌ݟΛڞ༗͍ͨ͠ʂ
 CDKͷ஌ݟΛൃද͍ͨ͠ํ΍CDKΛ੝Γ্͍͛ͨํืूʂʂ CDK @tmk2154 #jawsug-cdk νϟϯωϧ https://jaws-ug.jp/jaws-ug-slack/