Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AWSの研修環境構築のためにAWS CDKとAmplify Console使った話 / jaw...

kasacchiful
September 12, 2020

AWSの研修環境構築のためにAWS CDKとAmplify Console使った話 / jaws sonic 2020

JAWS SONIC 2020 & MIDNIGHT JAWS 2020 で、発表した資料です。

kasacchiful

September 12, 2020
Tweet

More Decks by kasacchiful

Other Decks in Programming

Transcript

  1. • ৽ׁࢢࡏॅ • ஍ݩSIerۈ຿ͷΤϯδχΞ • ޷͖ͳݴޠ: • ίϛϡχςΟ: • JAWS-UG

    ৽ׁ • JaSST Niigata ࣮ߦҕһձ • ASTER ਖ਼ձһ • etc. Hiroshi Kasahara @kasacchiful @kasacchiful 2
  2. JAWS-UG Niigata • 2018೥11݄ʹ্ཱͪ͛ • ৽ׁݝ಺ʹ3ͭ͋Δࢧ෦ͷ1ͭ • ৽ׁͱ͍͑͹ɺञ • ࠙਌ձ͕ʮʹ͍͕ͨञͷਞʯͷ࣌΋

    • ΦϑϥΠϯ։࠵ͷࡍʹ͸ɺ͓͍͍͓͠ञ ͱ͓৯ࣄΛᅂΈʹɺͥͻ৽ׁ΁͓ӽ͘͠ ͍ͩ͞ 3
  3. ϋϯζΦϯͷ಺༰ • 2019೥ʹʮJAWS-UG৽ׁʯͱ ʮJAWS-UG৽ׁݝʯͰ࣮ࢪͨ͠ɺ EC2ͱS3ͷϋϯζΦϯΛݩʹߏ੒ɻ • ๯಄30෼આ໌ͷޙɺ2࣌ؒ൒Ͱ WordPressαΠτߏங·ͰҰ௨ΓͰ͖ ΔΑ͏ʹɻ •

    ૣ͘ऴΘͬͨਓ޲͚ʹΦϓγϣϯϋϯ ζΦϯΛ༻ҙɻ 1. Amazon EC2 • ΠϯελϯεىಈɺΠϯελϯελΠϓมߋɺ Πϯελϯε࡟আ 2. Amazon S3 • όέοτ࡞੒ɺΦϒδΣΫτอଘɺόέοτ࡟ আɺެ։ઃఆɺ੩తWebαΠτϗεςΟϯά 3. WordPressαΠτߏங • Marketplace AMIΛ࢖༻ͯ͠Πϯελϯεىಈɺ ը૾ϑΝΠϧΛS3ʹอଘͯ͠഑৴ 4. Φϓγϣϯ • WordPressͷMySQLσʔλΛRDSʹҠߦ • ALBͰෛՙ෼ࢄ • ΦʔτεέʔϦϯάઃఆ 8
  4. ՝୊΁ͷରԠ (1) 1. ࣾ಺ͷωοτϫʔΫ؀ڥͰ͸ɺEC2ʹϩάΠϯͰ͖ͳ͍ • ձ৔ʹϋϯζΦϯઐ༻ΞΫηεϙΠϯτ͕͋ΔͷͰɺҰ࣌తʹ༗ޮԽ͢ Δ 2. ޿͍ձٞࣨͰ΋ɺͨ͘͞ΜͷਓΛೖΕͨ͘ͳ͍ •

    ΦϯϥΠϯͰࢹௌͰ͖ΔΑ͏ʹ͢Δ (ฐࣾͰ͸ɺMicrosoft Teams) • ϋϯζΦϯ࣌ؒଳͰ͸ɺࢲͷϋϯζΦϯ಺༰ͷϥΠϒߏஙΛ഑৴ • ձ৔಺ࢀՃऀ޲͚ͷϋϯζΦϯαϙʔτ͸ɺผͷਓʹ͓೚ͤͨ͠ 13
  5. ՝୊΁ͷରԠ (2) 3. ϋϯζΦϯͷॳظઃఆ͸ɺࢀՃਓ਺ʹԠͯ͡ਝ଎ʹ࡞Γ͍ͨ • AWS CDKͰઃఆͰ͖ΔΑ͏ʹͨ͠ (ࣾ಺NW͔ΒCDKίϚϯυͰΞΫηεͰ͖ͨ) 4. ։࠵ޙʹ෮श͢ΔͨΊͷ؀ڥΛ༩͍͑ͯ͋͛ͨ

    • ϋϯζΦϯࢿྉΛAWS Amplify ConsoleͰެ։͠ɺࣗ୐Ͱ෮शͰ͖ΔΑ͏ʹͨ͠ • ॳظઃఆ͸CDKͰग़ྗͨ͠CloudFormationςϯϓϨʔτͰઃఆͰ͖ΔΑ͏ʹͨ͠ • ࢲͷϋϯζΦϯϥΠϒߏங഑৴ಈը͸ɺ࿥ը͢ΔͱࣗಈతʹMicrosoft Streamsʹ อଘ͞ΕΔͷͰɺࣗ୐ͰϥΠϒߏஙಈըΛݟͳ͕ΒߏஙͰ͖ΔΑ͏ʹͨ͠ 14
  6. CDKͰઃఆͨ͠΋ͷ ࢀՃऀ͋ͨΓ • VPC: 1ͭ • Πϯλʔωοτήʔτ΢ΣΠ: 1ͭ (VPCʹΞλον) •

    αϒωοτ: 4ͭ • publicαϒωοτ͸ɺIGW΁ͷϧʔςΟϯά௥ Ճ • ηΩϡϦςΟάϧʔϓ: 2ͭ (web ͱ db) • IAMϢʔβ • ڞ௨ͷIAMάϧʔϓʹ௥Ճ 20 ࢀՃऀڞ௨ • IAMάϧʔϓ • ֤छϙϦγʔΛΞλον • IAMϩʔϧ • EC2ʹʮAmazonEC2RoleforSSMʯͱ ʮAmazonS3FullAccessʯΛڐՄ͢ΔͨΊ • ΠϯελϯεϓϩϑΝΠϧͷ࡞੒Λ๨Εͣʹ ࠓճ͸PythonͰॻ͖·ͨ͠
  7. ߏஙྫ (IAMϢʔβͱIAMάϧʔϓ) # IAM Group iam_group = iam.Group(self, "HandsonGroup", group_name

    = "HandsonGroup", managed_policies = [ iam.ManagedPolicy.from_aws_managed_policy_name("AmazonS3FullAccess"), ] ) # IAM Users cnt = 10 for i in range(1, cnt + 1): iam_user = iam.User(self, f"handson-seminar-iamuser-{i}", user_name = f"handson-seminar-iamuser-{i}", groups = [iam_group], ) 21
  8. AWS CDKͷ࢖༻ײ • ͍ͭ΋ͷϓϩάϥϛϯάݴޠͰॻ͚Δ҆৺ײ (ݸਓతʹ) • ݁ߏলུͯ͠هड़Ͱ͖Δ • ϋϯζΦϯͰࢿྉʹهड़͢Δඞཁ͕͋ͬͨͷͰVPC໊͸ࢦఆ͕ͨ͠ɺ CloudFormationςϯϓϨʔτΑΓهड़ྔ͕ݮͬͨ

    • ݟ௚͕͠ϥΫ • ࠔͬͨͱ͖͸ɺAPIϦϑΝϨϯε΍ઌۦऀͷTypeScriptίʔυ౳Λࢀর • ݴޠ͸ҟͳͬͯ΋ɺΫϥε΍ϝιου͕ڞ௨Խ͞Ε͍ͯΔ 23
  9. ͳͥAmplify ConsoleΛ࢖ͬͨͷ͔ʁ (1) ࣗ୐͔ΒͰ΋ࣗݾֶशͰ෮श͍ͤͯ͋͛ͨ͞ • Amplify ConsoleͰࢿྉΛWebͰެ։͢Ε͹OK • ύεϫʔυอޢ(Basicೝূ)΋Ͱ͖Δ •

    VPC౳ͷॳظઃఆ΋ɺCDKͰ࡞੒ͨ͠CloudFormationςϯϓ ϨʔτΛࢿྉαΠτ͔Βμ΢ϯϩʔυͯ͠࢖༻ͯ͠΋Β͑͹OK 27
  10. ͳͥAmplify ConsoleΛ࢖ͬͨͷ͔ʁ (2) σϓϩΠ·ͰͷखॱΛϥΫʹ͍ͨ͠ • ࠓ·ͰͷJAWS-UG৽ׁͰ΍ͬͯͨ͜ͱ • ฤू࣌: MarkdownͰॻ͘ →

    masterϒϥϯνʹϚʔδ → GitHubʹpush • Ϗϧυ&σϓϩΠ࣌: MarkdownΛHTMLʹม׵͢Δ → S3ʹઃஔ͢Δ • ࠓճ΍ͬͨ͜ͱ • ฤू࣌: MarkdownͰॻ͘ → masterϒϥϯνʹϚʔδ → GitHubʹpush • pushͨ͠ޙ͸ɺAmplify Console͕ࣗಈతʹϏϧυ & σϓϩΠͯ͘͠ΕΔ 28 ࢿྉ࡞Δͷ͸ࢲ1ਓ͚͔ͩͩΒɺ ༨ܭͳखॱΛ౿·ͳ͍Α͏ʹ͍ͨ͠
  11. υΩϡϝϯταΠτΛdocsifyͰ VueϕʔεͷυΩϡϝϯταΠτΛ͓खܰʹ • Single Page Application • Ϗϧυෆཁ • MarkdownϑΝΠϧͷ··ઃஔͰ͖Δ

    • JAWS-UG৽ׁͷϋϯζΦϯࢿྉ(Markdown)͕ͦͷ··࢖͑Δ • Ͱ΋ϚωδϝϯτίϯιʔϧͷUIมߋ͕݁ߏ͋ͬͨͷͰɺॻ͖௚͢෦෼͸ଟ͔ͬͨ • ֤छϗεςΟϯάαʔϏε΁ͷσϓϩΠखॱ͕υΩϡϝϯτʹ༻ҙ • Amplify Console΁͸ɺ͜ͷσϓϩΠखॱͷ௨Γʹ࣮ࢪ͠·ͨ͠ 30 IUUQTEPDTJGZKTPSH
  12. version: 0.1 frontend: phases: build: commands: - "sed -i -e

    \"s/routerMode: 'hash',/routerMode: 'history',/g\" ./docs/index.html" artifacts: baseDirectory: /docs files: - '**/*' cache: paths: [] docsifyͷυΩϡϝϯτʹ ै͑͹OKɻ • ϦϙδτϦϧʔτʹஔ͘ amplify.yml͸ӈͷΑ͏ ʹͯ͠ɺϏϧυ࣌ʹ routerModeΛ”history” ʹॻ͖׵͍͑ͯΔɻ Amplify Console΁ͷσϓϩΠઃఆ
  13. AWS Amplify Consoleͷ࢖༻ײ • Ϗϧυ & σϓϩΠͷख͕͔ؒͳΓল͚ͨ • ॳظઃఆ͸ҙ֎ͱ؆୯ͩͬͨ •

    (docsifyͷσϓϩΠखॱʹै͚ͬͨͩͰ͸͋Δ͕…) • Amplify SDK΍Amplify CLI࢖Θͳͯ͘΋ɺ·ͣ͸Amplify Consoleͩ ͚Ͱ΋ࢼͯ͠ΈΔՁ஋͸͋Δ 35
  14. ࢀߟ • ϋϯζΦϯͷϕʔε: • JAWS-UG ৽ׁ #2 - S3 ϋϯζΦϯ

    • https://jawsug-niigata.connpass.com/event/114694/ • JAWS-UG ৽ׁ #4 - EC2 / Lightsail ϋϯζΦϯ • https://jawsug-niigata.connpass.com/event/126558/ • JAWS-UG ৽ׁݝ ॳ৺ऀ޲͚ϋϯζΦϯ • https://nds.connpass.com/event/133878/ 39