Pro Yearly is on sale from $80 to $50! »

拡張して使うServerless&Amplify/use-with-extending-serverless-and-amplify

 拡張して使うServerless&Amplify/use-with-extending-serverless-and-amplify

38de416c9984b22bff1d2b049c7d51a8?s=128

MURAKAMI Masahiko

November 20, 2019
Tweet

Transcript

  1. KANAZAWA ֦ுͯ͠࢖͏ Serverless & Amplify גࣜձࣾӬ࿨γεςϜϚωδϝϯτɹञҪٛਔɾଜ্խ඙ | 2019/11/20

  2. ˕ • • ຊࣾʗ෱Ҫࢢ໰԰ ౦ژࢧࣾʗਆా ԭೄࣄ຿ॴʗಹ೼ࢢ ׆ಈڌ఺

  3. None
  4. Copyright©2016 Poppendieck.LLC 2017

  5. 2018

  6. εΫϥϜϚελʔ ʢେن໛޲͚ʣ ΤϯδχΞʗ εΫϥϜϚελʔ Ϋϥ΢υΞʔΩςΫτ Ϋϥ΢υΞʔΩςΫτ ʗεΫϥϜϚελʔ ΤϯδχΞ εΫϥϜϚελʔ •

    ܦݧ๛෋ͳΞδϟΠϧʗΫϥ΢υٕज़ऀʹΑΔ։ൃࢧԉαʔϏεɻίʔνϯά΋ՄೳͰ͢ɻ • POC͔Β঎༻αʔϏεͷ։ൃ·Ͱɺ෯޿͍ٕज़ྖҬʹରԠ͠·͢ɻ • ϦϞʔτ։ൃͳΒͰ͸ͷޮ཰ੑͱಁ໌ੑΛ௥ٻɻ͓٬༷ͱϫϯνʔϜͰϏδωεΛ੒௕ͤ͞·͢ɻ Point Agile Studio Fukuiɿ DX࣌୅ʹରԠͨ͠ڞ૑։ൃͱڞҭڌ఺ɻ ΞδϟΠϧ/Ϋϥ΢υΛ ಘҙͱ͢ΔΤϯδχΞνʔϜ
  7. None
  8. ServerlessͰ࡞ΔॳΊͯͷαʔόϨε

  9. KANAZAWA Name: ञҪ ٛਔ Age: 0x20୅ Home: ژ౎෎Ӊ࣏ࢢ • େࡕͷখ͍͞ձࣾͰϝʔΧʔ͔Βͷडୗ։ൃ

    • ओʹܞଳ୺຤ͷ૊ΈࠐΈιϑτ • ಛʹܞଳి࿩ʢFOMAॳ߸ػʙAndroid4.4ʣ • 2014೥10݄ΑΓݱ৬ • C/C++/Java/Objective-C/C#/JavaScript/TypeScript/etc
  10. KANAZAWA εϚϗΞϓϦʴόοΫΤϯυͷ։ൃґཔ • 20೥͙Β͍΍ͬͯΔαʔϏε • ͍Ζ͍Ζ͋ͬͯϦχϡʔΞϧ͍ͨ͠ • ։ൃձࣾʹෆຬʢεϐʔυײͦͷଞʣ

  11. KANAZAWA ελʔτ࣌఺ͷঢ়گ • ϦχϡʔΞϧ಺༰͸ݻ·͍ͬͯͳ͍ • ݱߦΞϓϦͷجຊػೳ͸ඞਢ • εϚϗΞϓϦ͸iOS/Android྆ํ ɹ὎ αʔό΋ΞϓϦ΋ɺಈ͘΋ͷΛૣ͘࡞Δඞཁ͕

  12. KANAZAWA ௨ৗͷαʔόߏ੒ AWS DC

  13. KANAZAWA ௨ৗͷαʔόߏ੒ • ϓϩϏδϣχϯά • εέʔϦϯά • ӡ༻ɾอक ɹ὎ ΞϓϦຊདྷͷػೳҎ֎ʹɺͦΕͳΓͷ࣌ؒͱ࿑ྗ

  14. KANAZAWA αʔόϨεͰʂ • ϓϩϏδϣχϯά • εέʔϦϯά • ӡ༻ɾอक ɹ὎ ΞϓϦຊདྷͷػೳʹ஫ྗ

  15. KANAZAWA εϚϗΞϓϦଆ • ݱߦΞϓϦ͸iOS=Objective-CˍAndroid=Java • ܦݧऀෆ଍ ɹ὎ ࡞Γ௚͍͕ͨ͠ωΠςΟϒΞϓϦͦΕͧΕΛ࡞Δ࣌ؒ͸ͳ͍

  16. KANAZAWA ϋΠϒϦουͰʂ • Cordova • Xamarin • React Native •

    Native Script • Flutter
  17. KANAZAWA ϋΠϒϦουͰʂ • Cordova • Xamarin • React Native •

    Native Script • Flutter αʔόϨεͷ࿩Ͱ͸ͳ͍ͷͰׂѪ
  18. KANAZAWA REST APIɿNode.js + TypeScript + Jest εϚϗΞϓϦɿReact Native +

    TypeScript + Jest ɹ὎ ར༻͢Δٕज़Λڞ௨Խ͢Δ͜ͱ͕Ͱ͖ͨ
  19. KANAZAWA αʔόϨεͳAPIߏ੒ AWS DC

  20. KANAZAWA αʔόϨεͳAPIߏ੒ AWS DC Amazon API Gateway APIͷఆٛɾσϓϩΠɾอकΛߦ͏ͨΊͷϑϧϚωʔδυαʔϏε

  21. KANAZAWA αʔόϨεͳAPIߏ੒ AWS DC AWS Lambda ೚ҙͷίʔυΛ࣮ߦ͢ΔͨΊͷϑϧϚωʔδυαʔϏε

  22. KANAZAWA αʔόϨεͳAPIߏ੒ AWS DC Amazon DynamoDB ແݶʹεέʔϧ͢ΔNoSQLσʔλϕʔε

  23. KANAZAWA αʔόϨεͳAPIߏ੒ AWS DC Amazon Cognito γϯϓϧʹϢʔβʔΛ؅ཧ͢ΔϑϧϚωʔδυαʔϏε

  24. KANAZAWA αʔόϨεͳAPIߏ੒ AWS DC AWS Amplify

  25. KANAZAWA αʔόϨεར༻ͷݒ೦ • Ϋϥ΢υʹ͔͠ͳ͍ ϩʔΧϧͰ࣮ߦͰ͖ͳ͍ʹςετͰ͖ͳ͍ʹ։ൃ͠ʹ͍͘ • ߏங͕໘౗ͦ͏ Ϛωδϝϯτίϯιʔϧʢखಈʣ͸࠶ݱੑͷ໰୊ CLIΛεΫϦϓτͰୟ͘ͷ΋อक͕೉͘͠ͳΔ

  26. KANAZAWA https://serverless.com

  27. KANAZAWA Serverless FrameworkͳΒ • Ϋϥ΢υʹ͔͠ͳ͍ ϩʔΧϧͰ࣮ߦͰ͖Δ • ߏங͕໘౗ͦ͏ YAMLϑΝΠϧʴίϚϯυͰҰൃσϓϩΠ

  28. KANAZAWA $ yarn global add serverless $ sls create -t

    aws-nodejs-typescript -p example-project Serverless: Generating boilerplate... Serverless: Generating boilerplate in "/Users/sakai-y/work/example-project" _______ __ | _ .-----.----.--.--.-----.----| .-----.-----.-----. | |___| -__| _| | | -__| _| | -__|__ --|__ --| |____ |_____|__| \___/|_____|__| |__|_____|_____|_____| | | | The Serverless Application Framework | | serverless.com, v1.55.1 -------' Serverless: Successfully generated boilerplate for template: “aws-nodejs-typescript" $ cd example-project
  29. KANAZAWA

  30. KANAZAWA $ yarn install $ sls config credentials -p aws

    -k [AWS AccessKey] -s [AWS SecretKey] $ sls deploy
  31. KANAZAWA ex) API GatewayͷΞΫηεϩάΛ༗ޮʹ͍ͨ͠

  32. KANAZAWA

  33. KANAZAWA ϩʔΧϧͰͷ࣮ߦ͸ʁ

  34. KANAZAWA https://github.com/serverless/plugins

  35. KANAZAWA https://github.com/dherault/serverless-offline serverless-offline

  36. KANAZAWA ͜ΕͰΞϓϦέʔγϣϯͷ࣮૷ʹूதͰ͖Δ

  37. KANAZAWA ՝୊ɿΦϯϓϨαʔό΁ͷ઀ଓʹݻఆIP͕ඞཁ AWS DC

  38. KANAZAWA LambdaΛVPCʹೖΕͯΞϨίϨ͢Δඞཁ͕ DC VPC Private subnet Public subnet

  39. KANAZAWA https://github.com/smoketurner/serverless-vpc-plugin serverless-vpc-plugin

  40. KANAZAWA $ yarn add -D serverless-vpc-plugin ϓϥάΠϯͷΠϯετʔϧ serverless.ymlʹઃఆ௥Ճ plugins: -

    serverless-webpack - serverless-vpc-plugin custom: vpcConfig: cidrBlock: '10.0.0.0/16' zones: - ap-northeast-1a - ap-northeast-1c
  41. KANAZAWA ͜Ε͚ͩ

  42. KANAZAWA Error —————————————————————— The CloudFormation template is invalid: Template format

    error: Number of resources, 201, is greater than maximum allowed, 200 ՝୊ɿ͋Δ೔σϓϩΠ͕ࣦഊͨ͠
  43. KANAZAWA 1APIʹ͖ͭෳ਺ͷCloudFormationϦιʔε͕࡞ΒΕΔ • AWS::Lambda::Function • AWS::Lambda::Permission • AWS::Logs::LogGroup • AWS::ApiGateway::Resource

    • AWS::ApiGateway::Method APIʹΑͬͯ͸AWS::ApiGateway::Model͕ෳ਺ɺ͞Βʹڞ௨ͷϦιʔε ɹ὎ ࣮͸ݶք௿͍
  44. KANAZAWA https://github.com/dougmoscrop/serverless-plugin-split-stacks serverless-plugin-split-stacks

  45. KANAZAWA ՝୊ɿ΍Ήͳ͘σϓϩΠΛյ͢ඞཁ͕͋ͬͨ ɹɹɹEIP͕มΘΔˠΦϯϓϨͷઃఆมߋ͕ඞཁˠݏͳإΛ͞ΕΔ

  46. KANAZAWA https://github.com/SC5/serverless-plugin-additional-stacks serverless-plugin-additional-stacks

  47. KANAZAWA ՝୊ɿVPCʹೖΕͨLambda͸ىಈʢίʔϧυελʔτʣ͕஗͍ ɹɹɹඇVPCͩͱ2ʙ3ඵ ɹɹɹVPCͩͱ9ʙ10ඵ

  48. KANAZAWA https://github.com/FidelLimited/serverless-plugin-warmup serverless-plugin-warmup

  49. KANAZAWA ՝୊ɿ։ൃ؀ڥ͚ͩඞཁͳϦιʔε

  50. KANAZAWA https://github.com/anantab/serverless-plugin-ifelse serverless-plugin-ifelse

  51. KANAZAWA custom: serverlessIfElse: - If: '"${self:custom.currentStage}" == “dev"' Exclude: -

    provider.role - provider.environment.ENV1 - functions.func3 - functions.func1.events.http.0.authorizer Set: provider.timeout: 90 provider.profile: dev ElseExclude: - provider.environment.ENV2 ElseSet: provider.timeout: 120 https://github.com/anantab/serverless-plugin-ifelse/blob/master/README.md
  52. KANAZAWA serverless-merge-config serverless-webpack serverless-jest-plugin serverless-dynamodb-local serverless-offline serverless-aws-documentation serverless-iam-roles-per-function serverless-plugin-api-gateway-auth serverless-plugin-stage-variables

    serverless-plugin-split-stacks serverless-plugin-warmup serverless-scriptable-plugin serverless-plugin-additional-stacks serverless-es-logs serverless-plugin-ifelse serverless-kms-secrets serverless-plugin-package-json serverless-plugin-git-variables ར༻தͷϓϥάΠϯ
  53. KANAZAWA Serverlessͷ·ͱΊ • Serverless FrameworkͰAPI࡞੒͸ૉૣ͘Ͱ͖Δ • ࠔͬͨ࣌͸ϓϥάΠϯΛ୳͢ • ࠷ऴखஈ͸CloudFormationςϯϓϨʔτ

  54. AWS Amplify ͷ֦ுੑ

  55. ଜ্խ඙ a.k.a @fossamgna

  56. AWS Amplifyͱ͸

  57. AWS Amplify ͱ͸ “εέʔϧ͢ΔϞόΠϧΞϓϦ͓Αͼ΢Σϒ ΞϓϦΛ࠷଎Ͱߏங͢Δํ๏” KANAZAWA

  58. AWS Amplify ͷߏ੒ CLIɿAmplifyͰΞϓϦΛߏங͢ΔͨΊͷπʔϧνΣʔϯ Cloud ServicesɿΞϓϦͷόοΫΤϯυ FrameworkɿϞόΠϧɺWeb޲͚ͷ֤SDK Developer ToolsɿCI/CD, ϗεςΟϯάɺϞόΠϧσόΠε

    ͷςετ؀ڥ KANAZAWA
  59. Amplify CLIͱόοΫΤϯυ

  60. Amplify CLIͷجຊίϚϯυ $ amplify init $ amplify <category> add/remove/update $

    amplify push KANAZAWA
  61. Amplify CLIͷΧςΰϦ Authentication (Cognito) Storage (S3, DynamoDB) API (API Gateway,

    AppSync) Function (Lambda) KANAZAWA Analytics (Pinpoint, Kinesis) Interactions (Lex)
  62. Amplify ͷΧελϚΠζ

  63. Amplify ͷΧελϚΠζํ๏ •طଘΧςΰϦʔͷςϯϓϨʔτฤू •ΧελϜCloudFormationελοΫͷ௥Ճ •ϓϥάΠϯ KANAZAWA

  64. Amplify ΧελϚΠζͷࣄྫ • S3ʹΞοϓϩʔυ͞ΕͨϑΝΠϧʹରͯ͠ CloudFrontͷॺ໊෇͖URLΛൃߦ • S3όέοτɺLambda͸CLIͰੜ੒ͨ͠Ϧιʔ εΛར༻ KANAZAWA

  65. ΧελϜCloudFormationελοΫͷ௥Ճ 1. CloudFormationςϯϓϨʔτϑΝΠϧͷ௥Ճ͢Δ 2. amplify/backend/backend-config.jsonͷฤू͢Δ 3. CLIʹ௥Ճͨ͠ϦιʔεΛೝࣝͤ͞Δ KANAZAWA

  66. CloudFormationςϯϓϨʔτϑΝΠϧͷ௥Ճ amplify/backend/<category>/<resource-name>/<cloudformation-template.json/yml>ͱͯ͠഑ஔ͢Δ { "AWSTemplateFormatVersion": "2010-09-09", "Description": "Private content resource stack

    creation using Amplify CLI", "Parameters": { "storageMediaContentBucketName": { "Type": "String", "Default": "storageMediaContentBucketName" }, }, "Resources": { "PrivteContentCloudFrontDistribution": { "Type" : "AWS::CloudFront::Distribution", "DependsOn" : [ "OriginAccessIdentity" ], …. } } KANAZAWA
  67. amplify/backend/backend-config.jsonͷฤू { "privatecontent": { "usercontent": { "service": "CloudFront", "providerPlugin": "awscloudformation",

    "dependsOn": [ { "category": "storage", "resourceName": "MediaContent", "attributes": [ "BucketName" ] } ] } }, "storage": { "MediaContent": { "service": "S3", "providerPlugin": “awscloudformation" } } KANAZAWA
  68. CLIʹ௥Ճͨ͠ϦιʔεΛೝࣝͤ͞Δ amplify env checkout <current-env-name> Λ࣮ߦͯ͠௥Ճ͠ ͨϦιʔεΛCLIʹೝࣝͤ͞Δ KANAZAWA

  69. Amplify CLIϓϥάΠϯ • Amplify CLI͸ϓϥάΠϯͱͯ͠ߏ੒͞Ε͍ͯΔ • ϓϥάΠϯʹ͸4ͭͷλΠϓ͕͋Δ • category •

    provider • frontend • util KANAZAWA
  70. Amplify CLIϓϥάΠϯͷ࡞੒ • ϓϥάΠϯͷ਽ܗΛੜ੒͢ΔίϚϯυ͕༻ҙ͞ΕͯΔ • amplify plugin init • ϓϥάΠϯͷ໊લ΍λΠϓͳͲ͍͔ͭ͘ͷ࣭໰ʹ౴͑Δ

    ͱ਽ܗίʔυ͕ੜ੒͞ΕΔ KANAZAWA
  71. Amplify CLIϓϥάΠϯͷߏ੒ ࠷খߏ੒ͷྫ |_my-amplify-plugin/ |_commands/ | |_ help.js | |_

    version.js | |_amplify-plugin.json |_index.js |_package.json KANAZAWA
  72. ࣄྫͷAmplify CLIϓϥάΠϯ • CloudFrontΛߏ੒͢ΔͨΊͷϓϥάΠϯ • λΠϓ͸category • ΧελϜCloudFormationελοΫͷςϯϓ Ϩʔτ࡞੒ɺbackend-config.jsonͷฤू͕ ϓϥάΠϯͷ࢓ࣄ

    KANAZAWA
  73. Amplify CLIϓϥάΠϯͷ࣮૷ • ϓϥάΠϯ࣮૷΋ؔ͢Δ৘ใ͸·ͩ·ͩগͳ͍ • https://github.com/aws-amplify/amplify-cliͷιʔε͕࣮૷ͷࢀߟʹͳΔ • amplify-cli/packages/amplify-cli/src/extensions/amplify-helpers ഑Լʹ͸ ϓϥάΠϯΛ࣮૷͢Δͷʹ༗༻ͳϝιου͕ͦΖ͍ͬͯΔ

    KANAZAWA
  74. Amplify CLIͷΧελϚΠζͷ·ͱΊ • ΧελϜCloudFormationελοΫ • ྑ͍఺ɿຊདྷɺ௥Ճ͍ͨ͠ελοΫͱbackend-config.jsonͷฤूͷΈͰΧε λϚΠζͰ͖Δ • ΠϚΠνͳ఺ɿLambdaͷΑ͏ʹෳ਺ͷϦιʔεΛ௥Ճ͢ΔΑ͏ͳ৔߹͸࡞ ۀ͕൥ࡶ

    • ϓϥάΠϯ • ྑ͍఺ɿෳ਺ͷϦιʔεΛ௥Ճ͢ΔΑ͏ͳ৔߹͸࡞ۀָ͕Ͱؒҧ͍Λى͜͠ ʹ͍͘ɻ൚༻తͳΒଞϓϩδΣΫτͰ΋࢖͑ΔʢOSSʹͨ͠Γ΋Ͱ͖Δʣ • ΠϚΠνͳ఺ɿϓϩάϥϜΛॻ͘ඞཁ͕͋Δʢ࣮૷ίετ͕͔͔Δʣ KANAZAWA
  75. KANAZAWA Ҏ্