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

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

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

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

Takaaki Tanaka

August 05, 2019
Tweet

More Decks by Takaaki Tanaka

Other Decks in Technology

Transcript

  1. αʔόʔϨεΞϓϦέʔγϣϯΛߏ੒͢ΔͨΊͷαʔϏεʢҰ෦ʣ   • 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
  2. AWS Lambda   • αʔόʔͷϓϩϏδϣχϯάɺεέʔϦϯά΍ ؅ཧ͕ෆཁ • ։ൃऀ͸αʔόʔ΍ϥϯλΠϜͷ؅ཧɺૢ࡞ʹ ൥Θ͞Εͣɺίʔυʹूத͢Δ͜ͱ͕Ͱ͖Δ

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

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

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

    • ΞϥʔϜͷઃఆ΍ࣗಈԽ͞ΕͨΞΫγϣϯΛى ͜͢ • ϩάΛ͢͹΍͘ൃݟɺ෼ੳɺࢹ֮Խ͢Δ͜ͱͰ ӡ༻্ͷ໰୊ʹରॲ͠΍͘͢͢Δ https://aws.amazon.com/jp/cloudwatch/
  6. 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
  7. AWS IoT ϧʔϧ   \ TUBUF\ SFQPSUFE\ QPXFSl0/ ^

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

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

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

    ϯΛඥ͚ͮͨผͷϧʔϧ ෳ਺ͷτϐοΫͱϧʔϧΛ૊Έ߹Θ ͤͯɺΞΫγϣϯΛઃఆ͍ͯ͘͠
  11. ։ൃͱӡ༻ͷฒߦ   • ػೳ։ൃͱӡ༻͸։ൃऀ͕ฒߦͯ͠ߦ͏৔߹͕ଟ͍ • ܞΘ͍ͬͯΔҊ݅͸։ൃνʔϜɾӡ༻νʔϜͳͲͷ໾ׂ෼୲ Λ͍ͯ͠ͳ͍ • εύΠΫΞΫηεͷରԠͳͲɺϚωʔδυαʔϏεʹد͍ͤͯ

    Δ෦෼ͷରԠ͸ෆཁ͕ͩɺͦͷ݁ՌΛ౿·͑ͯػೳΛߟྀ͢ Δ৔߹͸͋Δ • ϚΠΫϩαʔϏεΛ૊Έ߹ΘͤΔ্Ͱͷ։ൃɾӡ༻ͷઃܭ͕؊ ཁ
  12. 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
  13. 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
  14. 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Λඥ͚ͮΔ Πϕϯτͷઃఆ
  15. 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
  16. CircleCIͱͷ૊Έ߹Θͤ   • AWS SAM ͱ CircleCI Λ૊Έ߹ΘͤͯɺϢχοτςετɹˠ σϓϩΠ

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

    ͳͲΛ δϣϒ ͱ͍ ͏୯ҐͰ࡞੒Ͱ͖Δ • ϫʔΫϑϩʔ ͸ δϣϒ ͷॲཧͷෳࡶͳखॱʢ௚ྻɾฒߦ࣮ ߦͳͲʣΛ౿ΉΑ͏ͳϑϩʔΛදݱͰ͖Δ
  18. Approval Ͱຊ൪ద༻ͷ δϣϒ Λ଴ͨͤΔ   IUUQTDJSDMFDJDPNEPDTXPSLqPXT • ࣍ͷ δϣϒ

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

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

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