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

AWS SAM を CircleCI でデプロイさせよう #circlecijp #デプロイしNight

AWS SAM を CircleCI でデプロイさせよう #circlecijp #デプロイしNight

デプロイしNight in 福岡 での発表資料です。 #circlecijp #デプロイしNight

808ce3d41280c085f8bdc27dce7ea8fb?s=128

Takaaki Tanaka

August 05, 2019
Tweet

Transcript

  1. "844".Λ $JSDMF$*ͰσϓϩΠͤ͞Α͏  ݄  σϓϩΠ͠Night in ෱Ԭ

  2. ࣗݾ঺հ   wΫϥεϝιουגࣜձࣾ w෱ԬΦϑΟεॴଐ w$9ࣄۀຊ෦ wϞόΠϧΞϓϦΤϯδχΞ wαʔόʔαΠυΞϓϦΤϯδχΞ ాத޹໌ @kongmingtrap

  3. ࠓճͷٞ୊   • αʔόʔϨεΞϓϦέʔγϣϯ • AWS SAM ͱαʔόʔϨεΞϓϦέʔγϣϯ •

    AWS SAM ͱ CircleCI ͷ૊Έ߹Θͤ
  4. αʔόʔϨεΞϓϦέʔγϣϯ

  5. αʔόʔϨεͷϝϦοτ   • αʔόʔͷ؅ཧ͕ෆཁ • ॊೈੑͷ͋ΔεέʔϦϯά • Ձ஋ʹର͢Δࢧ෷͍ •

    ߴՄ༻ੑͷࣗಈԽ https://aws.amazon.com/jp/serverless/
  6. αʔόʔϨεΞϓϦέʔγϣϯΛߏ੒͢ΔͨΊͷαʔϏεʢҰ෦ʣ   • AWS Lambda • Amazon API Gateway

    • Amazon Kinesis • Amazon CloudWatch • Amazon S3 • Amazon DynamoDB • AWS Step Functions • Amazon Simple Queue Service • Amazon Athena • AWS Glue …etc
  7. AWS Lambda   • αʔόʔͷϓϩϏδϣχϯάɺεέʔϦϯά΍ ؅ཧ͕ෆཁ • ։ൃऀ͸αʔόʔ΍ϥϯλΠϜͷ؅ཧɺૢ࡞ʹ ൥Θ͞Εͣɺίʔυʹूத͢Δ͜ͱ͕Ͱ͖Δ

    • ར༻Ͱ͖Δݴޠ͕๛෋ • Ruby / Node.js / Python / Java / Go / C# / PowerShell • Custom RuntimesΛར༻͢Ε͹ɺ೚ҙͷݴޠΛ ಈ࡞ͤ͞Δ͜ͱ͕Մೳ https://aws.amazon.com/jp/lambda/
  8. Amazon API Gateway   • ಠࣗͷ REST ͓Αͼ WebSocket

    API Λ࡞੒ɺ ެ։ɺอकɺϞχλϦϯάɺอޢͰ͖Δ • ಠࣗͷΫϥΠΞϯτΞϓϦέʔγϣϯ (ΞϓϦ) Ͱ࢖༻͢ΔͨΊͷ API Λ࡞੒Ͱ͖Δ https://aws.amazon.com/jp/api-gateway/
  9. Amazon Kinesis   • ͋ΒΏΔن໛ͷετϦʔϛϯάσʔλΛίετ ޮ཰ྑ͘ॲཧ͢ΔͨΊͷओཁػೳΛఏڙ • ετϦʔϛϯάσʔλΛϦΞϧλΠϜͰऔಘɺ όοϑΝɺॲཧ͢ΔͨΊɺ௨ৗ͸਺͔࣌ؒΒ਺

    ೔͔͔ΔΠϯαΠτͷੜ੒Λ਺ඵ͔Β਺෼Ͱ׬ ྃ • ΠϯϑϥετϥΫνϟΛ؅ཧ͢Δඞཁͳ͘ɺε τϦʔϛϯάΞϓϦέʔγϣϯΛ࣮ߦͰ͖Δ https://aws.amazon.com/jp/kinesis/
  10. Amazon CloudWatch   • ओཁͳϝτϦΫεͱϩάͷϞχλϦϯάɺΞϓ Ϧέʔγϣϯ͓ΑͼΠϯϑϥετϥΫνϟελο ΫͷՄࢹԽɺΞϥʔϜͷ࡞੒ɺ͓ΑͼϝτϦΫ εͱϩάͷؔ࿈෇͚ʹΑͬͯɺύϑΥʔϚϯε ͷ໰୊ͷࠜຊతݪҼΛ೺Ѳ

    • ΞϥʔϜͷઃఆ΍ࣗಈԽ͞ΕͨΞΫγϣϯΛى ͜͢ • ϩάΛ͢͹΍͘ൃݟɺ෼ੳɺࢹ֮Խ͢Δ͜ͱͰ ӡ༻্ͷ໰୊ʹରॲ͠΍͘͢͢Δ https://aws.amazon.com/jp/cloudwatch/
  11. αʔϏεΛ૊Έ߹ΘͤͯΞϓϦέʔγϣϯΛߏங   https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/events/ WhatIsCloudWatchEvents.html • લड़ͨ͠αʔϏεΛ૊ΈΘͤͯɺػೳΛ࣮૷͍ͯ͘͠ AM 2:00 ʹ࣮ߦ

  12. ͱ͋ΔҊ݅   • σόΠεʹରͯ͠ɺ֎෦API͔Βঢ়ଶΛมԽͤ͞Δ • ଟ਺ͷσόΠεͷঢ়ଶ͔Βɺঢ়ଶ͕มԽͨ͠΋ͷʹରͯ͠ಛ ఆͷΞΫγϣϯΛى͜͢ • σόΠεͷঢ়ଶΛมԽΛऔಘ͠ଓ͚Δ

    • ͦͷ೔ͷऴྃޙͷσόΠεͷঢ়ଶΛදͨ͠σʔλΛՃ޻͠ɺ ՄࢹԽ͢Δ
  13. AWS IoT   • Πϯλʔωοτʹ઀ଓͨ͠σόΠεͱAWSͷ αʔϏεΛηΩϡΞʹ௨৴ͤ͞Δ࢓૊ΈΛఏڙ • σόΠε΁ͷࢦྩɺσόΠε͔ΒͷσʔλΛड ͚औΓɺAWSͷαʔϏε΁ڮ౉͠Λߦ͏

    • ؔ࿈͢ΔαʔϏε • AWS IoT Core • AWS IoT Device Defender • AWS IoT Analytics https://docs.aws.amazon.com/ja_jp/iot/latest/developerguide/what-is-aws-iot.html
  14. AWS IoT ϧʔϧ  

  15. AWS IoT ϧʔϧ   SELECT * FROM '$aws/things/+/shadow/update' WHERE

    state.reported.power = True
  16. AWS IoT ϧʔϧ   \ TUBUF\ SFQPSUFE\ QPXFSl0/ ^

    ^ ^ SELECT * FROM '$aws/things/+/shadow/update' WHERE state.reported.power = True ࢦఆͨ͠τϐοΫ΁ σʔλΛૹ৴
  17. AWS IoT ϧʔϧ   \ TUBUF\ SFQPSUFE\ QPXFSl0/ ^

    ^ ^ SELECT * FROM '$aws/things/+/shadow/update' WHERE state.reported.power = True ϧʔϧʹϚον
  18. AWS IoT ϧʔϧ   \ TUBUF\ SFQPSUFE\ QPXFSl0/ ^

    ^ ^ SELECT * FROM '$aws/things/+/shadow/update' WHERE state.reported.power = True ϧʔϧʹઃఆ͞Εͨ ΞΫγϣϯΛ࣮ߦ͢Δ
  19. AWS IoT ϧʔϧ   SELECT * FROM '$aws/things/+/shadow/update/documents'

  20. AWS IoT ϧʔϧ   SELECT * FROM '$aws/things/+/shadow/update/documents'

  21. AWS IoT ϧʔϧ   SELECT * FROM '$aws/things/+/shadow/update/documents' σʔλΛ֨ೲ͢ΔΞΫγϣ

    ϯΛඥ͚ͮͨผͷϧʔϧ
  22. AWS IoT ϧʔϧ   SELECT * FROM '$aws/things/+/shadow/update/documents' σʔλΛ֨ೲ͢ΔΞΫγϣ

    ϯΛඥ͚ͮͨผͷϧʔϧ ෳ਺ͷτϐοΫͱϧʔϧΛ૊Έ߹Θ ͤͯɺΞΫγϣϯΛઃఆ͍ͯ͘͠
  23. AWS SAMͱ αʔόʔϨεΞϓϦέʔγϣϯ

  24. ։ൃͱӡ༻ͷฒߦ   • ػೳ։ൃͱӡ༻͸։ൃऀ͕ฒߦͯ͠ߦ͏৔߹͕ଟ͍ • ܞΘ͍ͬͯΔҊ݅͸։ൃνʔϜɾӡ༻νʔϜͳͲͷ໾ׂ෼୲ Λ͍ͯ͠ͳ͍ • εύΠΫΞΫηεͷରԠͳͲɺϚωʔδυαʔϏεʹد͍ͤͯ

    Δ෦෼ͷରԠ͸ෆཁ͕ͩɺͦͷ݁ՌΛ౿·͑ͯػೳΛߟྀ͢ Δ৔߹͸͋Δ • ϚΠΫϩαʔϏεΛ૊Έ߹ΘͤΔ্Ͱͷ։ൃɾӡ༻ͷઃܭ͕؊ ཁ
  25. AWS αʔόʔϨεΞϓϦέʔγϣϯϞσϧ (AWS SAM) ͷ࢖༻   • αʔόʔϨεΞϓϦέʔγϣϯʹదͨ͠ॻࣜͰ AWS

    CloudFromation ͷ Stack Λग़ྗͯ͘͠ΕΔ • SwaggerͷఆٛΛݩʹ Amazon API Gateway ͷઃఆ͕ߦ͑Δ • API࢓༷ͱ࣮૷ͷဃ཭Λ๷͙ • AWS CloudFormation ςϯϓϨʔτͱಉ༷Ͱɺ૊ΈࠐΈؔ਺ ͳͲ͕࢖͑Δ • ผͷϦʔδϣϯ΍ผͷAWSΞΧ΢ϯτʹΞϓϦέʔγϣϯͷ σϓϩΠΛߦ͑ΔΑ͏ʹ͢Δ https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/serverless_app.html
  26. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC

  27. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC AWSΞΧ΢ϯτB΁ ίϚϯυ࣮ߦ

  28. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC CloudFormationͷ Stackʹม׵

  29. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC AWSͷϦιʔεΛల։

  30. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC AWSΞΧ΢ϯτA ΁ίϚϯυ࣮ߦ

  31. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC CloudFormationͷ Stackʹม׵

  32. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC

  33. AWS SAM   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC

  34. AWS SAM ͷه๏ͷྫ   • Amazon CloudWatch Events +

    AWS Lambdaͷྫ AM 2:00 ʹ࣮ߦ
  35. AWS SAM ͷه๏ͷྫ   • Amazon CloudWatch Events +

    AWS Lambdaͷྫ AM 2:00 ʹ࣮ߦ TimerEventFunction: Type: AWS::Serverless::Function Properties: FunctionName: timer-event-function CodeUri: src/handlers/timer_event Handler: index.handler Runtime: python3.7 Policies: - arn:aws:iam::aws:policy/AmazonS3FullAccess Events: Schedule: Type: Schedule Properties: Schedule: cron(0 17 * * ? *) sam.yml
  36. AWS SAM ͷه๏ͷྫ   • Amazon CloudWatch Events +

    AWS Lambdaͷྫ AM 2:00 ʹ࣮ߦ TimerEventFunction: Type: AWS::Serverless::Function Properties: FunctionName: timer-event-function CodeUri: src/handlers/timer_event Handler: index.handler Runtime: python3.7 Policies: - arn:aws:iam::aws:policy/AmazonS3FullAccess Events: Schedule: Type: Schedule Properties: Schedule: cron(0 17 * * ? *) sam.yml AWS LambdaΛඥ͚ͮΔ Πϕϯτͷઃఆ
  37. AWS SAM ͷه๏ͷྫ   • Amazon CloudWatch Events +

    AWS Lambdaͷྫ AM 2:00 ʹ࣮ߦ TimerEventFunction: Type: AWS::Serverless::Function Properties: FunctionName: timer-event-function CodeUri: src/handlers/timer_event Handler: index.handler Runtime: python3.7 Policies: - arn:aws:iam::aws:policy/AmazonS3FullAccess Events: Schedule: Type: Schedule Properties: Schedule: cron(0 17 * * ? *) sam.yml
  38. ʢຊ୊ʣ AWS SAM ͱ CricleCI ͷ૊Έ߹Θͤ

  39. CircleCIͱͷ૊Έ߹Θͤ   • AWS SAM ͱ CircleCI Λ૊Έ߹ΘͤͯɺϢχοτςετɹˠ σϓϩΠ

    → e2eςετ ·ͰΛҰ؏ͯ͠ߦ͏ • Approval ͳͲͷػೳΛར༻͠ɺຊ൪؀ڥద༻ͳͲΛҰ࿈ͷ ϫʔΫϑϩʔͰߦ͑ΔΑ͏ʹ͢Δ sam.yml
  40. δϣϒ ͱ ϫʔΫϑϩʔ   IUUQTDJSDMFDJDPNEPDTXPSLqPXT • Ϣχοτςετɺ σϓϩΠɺ e2eςετ

    ͳͲΛ δϣϒ ͱ͍ ͏୯ҐͰ࡞੒Ͱ͖Δ • ϫʔΫϑϩʔ ͸ δϣϒ ͷॲཧͷෳࡶͳखॱʢ௚ྻɾฒߦ࣮ ߦͳͲʣΛ౿ΉΑ͏ͳϑϩʔΛදݱͰ͖Δ
  41. αϯϓϧίʔυ   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFS

  42. .circleci/config.yml ʹ δϣϒ Λఆٛ   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM--

  43. .circleci/config.yml ʹ δϣϒ Λఆٛ   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM--

  44. Makefile ͳͲʹ AWS SAM ίϚϯυ Λఆٛ   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFS.BLFpMF--

  45. δϣϒ͔Β Makefile ͷίϚϯυΛݺͿΑ͏ʹ͢Δ   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM-

  46. ϫʔΫϑϩʔͷ࡞੒   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM- • ࡞੒ͨ͠ δϣϒ ΛݺͿॱ൪Λ ϫʔΫϑϩʔ ͱͯ͠࡞੒͢Δ

  47. ϫʔΫϑϩʔͷ࡞੒   • ࡞੒ͨ͠ δϣϒ ΛݺͿॱ൪Λ ϫʔΫϑϩʔ ͱͯ͠࡞੒͢Δ IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM--

  48. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ • ϫʔΫϑϩʔͷྫ

  49. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ Ϣχοτςετ Λߦ͏ • ϫʔΫϑϩʔͷྫ

  50. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ Ϣχοτςετ Λߦ͏ • ϫʔΫϑϩʔͷྫ

  51. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ Ϣχοτςετ Λߦ͏ ։ൃ؀ڥ΁ͷσϓ ϩΠͱe2eςετ • ϫʔΫϑϩʔͷྫ

  52. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ Ϣχοτςετ Λߦ͏ ։ൃ؀ڥ΁ͷσϓ ϩΠͱe2eςετ ຊ൪؀ڥ΁ͷద༻ Λߦ͏

    • ϫʔΫϑϩʔͷྫ
  53. Approval Ͱຊ൪ద༻ͷ δϣϒ Λ଴ͨͤΔ   IUUQTDJSDMFDJDPNEPDTXPSLqPXT • ࣍ͷ δϣϒ

    ʹਐΉલʹɺ δϣϒ ͷ खಈঝೝ Λ଴ͭΑ͏ʹ ϫʔΫϑϩʔ Λߏ੒Ͱ͖Δ • ϦϙδτϦ΁ͷϓογϡΞΫηεݖΛ͍࣋ͬͯΔਓͳΒ୭Ͱ ΋ ঝೝϘλϯ ΛΫϦοΫͯ͠ ϫʔΫϑϩʔ Λଓ͚Δ͜ͱ͕ Ͱ͖Δ
  54. Approval Ͱຊ൪ద༻ͷ δϣϒ Λ଴ͨͤΔ   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM-

  55. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ ຊ൪ద༻ͷ࣮ߦ͸ ApprovalͰ଴ͨͤΔ • ϫʔΫϑϩʔͷྫ

  56. CircleCIͱͷ૊Έ߹Θͤ   https://circleci.com/docs/2.0/workflows/ • ϫʔΫϑϩʔͷྫ

  57. ঝೝૢ࡞ʹΑΔຊ൪ద༻   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC

  58. ঝೝૢ࡞ʹΑΔຊ൪ద༻   sam.yml AWSΞΧ΢ϯτB AWSΞΧ΢ϯτA AWSΞΧ΢ϯτC

  59. ࣍ੈ୅ߏ૝

  60. AWS CDK ͷ׆༻   IUUQTHJUIVCDPNLPOHNJOHTUSBQ4MBDL/PUJpFS4BNQMFSCMPCNBTUFSDJSDMFDJDPOpHZNM- • AWS CDK (Cloud

    Development Kit) • AWS ϦιʔεΛ ߏ੒ཁૉ(construct) ͱͯ͠ϓϩάϥϜͰॻ ͖ɺͦΕΒΛ૊Έ߹Θ࣮ͤͯߦ͢ΔͱσϓϩΠͰ͖Δͱ͍͏ πʔϧΩοτɻ • AWSͷΠϯϑϥΛ TypeScript ͳͲͷϓϩάϥϛϯάݴޠΛ ࢖ͬͯఆٛɾσϓϩΠ͢Δɻ • CDKϓϩάϥϜΛ࣮ߦ͢Δ͜ͱͰ CloudFormation ςϯϓ ϨʔτΛੜ੒ɺͦͷςϯϓϨʔτΛ࢖ͬͯσϓϩΠ͢Δɻ
  61. ·ͱΊ

  62. ·ͱΊ   • CircleCI ͷ δϣϒ ͱ ϫʔΫϑϩʔ Λ૊Έ߹ΘͤͯαʔόʔϨ

    εΞϓϦέʔγϣϯͷ Ϣχοτςετ → σϓϩΠ → e2eς ετ ΛҰ؏ͯ͠ߦ͑Δ • ຊ൪ద༻ͳͲͷঝೝ͕ඞཁͳϑϩʔʹ͍ͭͯ΋ Approval ͱఆ ٛ͢Δ͜ͱͰՄೳͱͳΔ • ΑΓΠϯϑϥΛίʔυͰ؅ཧ͠΍͘͢ͳΔ
  63. None