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

拡張して使うServerless&Amplify/use-with-extending-ser...

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

MURAKAMI Masahiko

November 20, 2019
Tweet

More Decks by MURAKAMI Masahiko

Other Decks in Programming

Transcript

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

    ܦݧ๛෋ͳΞδϟΠϧʗΫϥ΢υٕज़ऀʹΑΔ։ൃࢧԉαʔϏεɻίʔνϯά΋ՄೳͰ͢ɻ • POC͔Β঎༻αʔϏεͷ։ൃ·Ͱɺ෯޿͍ٕज़ྖҬʹରԠ͠·͢ɻ • ϦϞʔτ։ൃͳΒͰ͸ͷޮ཰ੑͱಁ໌ੑΛ௥ٻɻ͓٬༷ͱϫϯνʔϜͰϏδωεΛ੒௕ͤ͞·͢ɻ Point Agile Studio Fukuiɿ DX࣌୅ʹରԠͨ͠ڞ૑։ൃͱڞҭڌ఺ɻ ΞδϟΠϧ/Ϋϥ΢υΛ ಘҙͱ͢ΔΤϯδχΞνʔϜ
  2. KANAZAWA Name: ञҪ ٛਔ Age: 0x20୅ Home: ژ౎෎Ӊ࣏ࢢ • େࡕͷখ͍͞ձࣾͰϝʔΧʔ͔Βͷडୗ։ൃ

    • ओʹܞଳ୺຤ͷ૊ΈࠐΈιϑτ • ಛʹܞଳి࿩ʢFOMAॳ߸ػʙAndroid4.4ʣ • 2014೥10݄ΑΓݱ৬ • C/C++/Java/Objective-C/C#/JavaScript/TypeScript/etc
  3. KANAZAWA ϋΠϒϦουͰʂ • Cordova • Xamarin • React Native •

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

    TypeScript + Jest ɹ὎ ར༻͢Δٕज़Λڞ௨Խ͢Δ͜ͱ͕Ͱ͖ͨ
  5. 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
  6. KANAZAWA $ yarn install $ sls config credentials -p aws

    -k [AWS AccessKey] -s [AWS SecretKey] $ sls deploy
  7. 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
  8. KANAZAWA Error —————————————————————— The CloudFormation template is invalid: Template format

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

    • AWS::ApiGateway::Method APIʹΑͬͯ͸AWS::ApiGateway::Model͕ෳ਺ɺ͞Βʹڞ௨ͷϦιʔε ɹ὎ ࣮͸ݶք௿͍
  10. 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
  11. 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 ར༻தͷϓϥάΠϯ
  12. Amplify CLIͷΧςΰϦ Authentication (Cognito) Storage (S3, DynamoDB) API (API Gateway,

    AppSync) Function (Lambda) KANAZAWA Analytics (Pinpoint, Kinesis) Interactions (Lex)
  13. 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
  14. 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
  15. Amplify CLIϓϥάΠϯͷߏ੒ ࠷খߏ੒ͷྫ |_my-amplify-plugin/ |_commands/ | |_ help.js | |_

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

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