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

HIGOBASHI.AWS 第10回「サーバーレスとデータ分析 ~AWS Lambdaを活用...

HIGOBASHI.AWS 第10回「サーバーレスとデータ分析 ~AWS Lambdaを活用して効率化しよう~」

LambdaでNumpy,Sicpy, OpenCVを使う方法や、Lambda Layerの話をしました

yuji nishimura

April 17, 2019
Tweet

More Decks by yuji nishimura

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ   w੢ଜ༞ೋ   wαʔόʔϨε։ൃ෦ wݩ৘γε wೖࣾ೥ϲ݄ w"84ྺ೥ϲ݄

    w౦ژ͔Βେࡕʹ6λʔϯస৬ wલ৬͸*41ͷձࣾͰސ٬γεςϜอक
  2. ओཁͳ੍ݶ   Ϧιʔε ੍ݶ λΠϜΞ΢τ TFD ෼ σϓϩΠύοέʔ δ

    .# [JQѹॖࡁɺ௚઀Ξοϓϩʔυ  .# ίϯιʔϧΤσΟλ  .# ϨΠϠʔ ϝϞϦ .#͔Β.#·Ͱ UNQετϨʔδ .# https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/limits.html
  3. ؾΛ͚ͭΔϙΠϯτͦͷ̍   JNQPSU͢Δࡍͷύεʹ஫ҙ [JQΛ࡞Δલʹ ύοέʔδ௚ԼʹϥΠϒϥϦϑΝΠϧΛஔ͘ ͳͲͯ͠σϓϩΠޙͰ΋ϋϯυϥ͔Βɹɹɹ ϥΠϒϥϦΛݺͼग़ͤΔΑ͏ʹ޻෉͕ඞཁ pip install

    -r requirements.txt -t . ex) -t ͰϥΠϒϥϦͷΠϯετʔϧઌΛࢦఆ https://docs.aws.amazon.com/ja_jp/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html
  4. ؾΛ͚ͭΔϙΠϯτͦͷ   04ґଘ͕͋ΔϥΠϒϥϦ͸"NB[POɹ -JOVY؀ڥͰϏϧυͨ͠ϑΝΠϧΛ[JQʹ ؚΊΔ -BNCEBؔ਺ͷ࣮ߦ؀ڥͱ΄΅ಉ౳ͷ %PDLFSΠϝʔδΛ࢖ͬͯϏϧυ docker run

    --rm -v $(pwd):/var/task -w /var/task lambci/lambda:build-python3.6 \ pip install -r requirements.txt -t ${OUTPUT_DIR} ex) dockerΛ࢖ͬͯϏϧυ͢ΔεΫϦϓτྫͷൈਮ
  5. Ͳ͏΍ͬͯ࢖͏ͷ͔   TFSWFSMFTTZNMʹઃఆΛهࡌ͢Δ͚ͩ ίϚϯυҰͭͰύοέʔδͱσϓϩΠ·Ͱ࣮ࢪ custom: pythonRequirements: dockerizePip: non-linux slim:

    true zip: true plugins: - serverless-python-requirements $ sls deploy dockerͰϏϧυ ࠷దԽͯ͠༰ྔ࡟ݮ zipѹॖ཰ߴΊ༰ྔ࡟ݮ
  6. Ͳ͏΍ͬͯ࢖͏ͷ͔   ੍ݶ಺ͰOVNQZ TDJQZΛύοέʔδ Serverless: Uploading CloudFormation file to

    S3... Serverless: Uploading artifacts... Serverless: Uploading service .zip file to S3 (42.02 MB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... ......... https://dev.classmethod.jp/cloud/serverless-framework-lambda-numpy-scipy/ ৄࡉ͸ԼهϒϩάΛࢀর
  7. -BZFS༻ͷTFSWFSMFTTZNMʢશͯʣ   service: layer provider: name: aws runtime: python3.7

    deploymentBucket: name: layer-test-dev-serverless-demo package: exclude: - "**" custom: pythonRequirements: usePipenv: true dockerizePip: true layer: description: opencv plugins: - serverless-python-requirements ϥΠϒϥϦΛLayerͱͯ͠σϓϩΠ
  8. -BZFSΛར༻͢Δ-BNCEB   DGOͷ0VUQVUΛࢀর͢ΔػೳΛར༻ functions: hello: handler: handler.hello layers: -

    ${cf:layer-dev.PythonRequirementsLambdaLayerQualifiedArn} ex) serverless.ymlͷҰ෦ൈਮ Layer͕ඥ෇͍ͨঢ়ଶͰσϓϩΠ
  9. ߏ੒ਤ   AWS Lambda Amazon Simple Storage Service (S3)

    ᶃը૾Ξοϓϩʔυ ᶄτϦΨʔ࣮ߦ ᶅը૾ॲཧͨ͠ը૾อଘ