Save 37% off PRO during our Black Friday Sale! »

AWS Lambda Swift Runtime

011714704c4a925e542d426d4cdaa4e3?s=47 giginet
December 15, 2018

AWS Lambda Swift Runtime

011714704c4a925e542d426d4cdaa4e3?s=128

giginet

December 15, 2018
Tweet

Transcript

  1. AWS Lambda Swi, Run0me @giginet

  2. @giginet • Cookpad Inc. ϞόΠϧج൫ • εϚϒϥͷ࣋ͪΩϟϥ • ϤογʔɺΞΠεΫϥΠϚʔɺσΟσΟʔίϯά

  3. re:Inventߦ͖ͬͯͨ

  4. re:Invent • Amazonओ࠵ͷAWS։ൃऀ޲͚ΧϯϑΝϨϯε • 11/26 ~ 11/30 @ Las Vegas

    • ࢀՃऀ50000ਓ • ڊେϗςϧ5ݸ͙Β͍࢖͏
  5. None
  6. None
  7. AWSͷओͳϞόΠϧ޲͚αʔϏε • Pinpoint: FCMΈ͍ͨͳ΍ͭ • Device Farm: Firebase TestLabΈ͍ͨͳ΍ͭ •

    AppSync • DynamoDBͱ͔LambdaͷGraphQLΠϯλʔϑΣΠεఏڙ͢Δ ΍ͭ • Mobile Hub: ͳΜ͔͍Ζ͍ΖͰ͖Δ΍ͭ
  8. ࠓ೥ൃද͞ΕͨϞόΠϧαʔϏε

  9. AWS Lambda • APIୟ͘ͱϫϯγϣοτͰεΫϦϓτ͕࣮ߦ • αʔόʔϨεΞϓϦέʔγϣϯ͕ߏஙͰ͖Δ • ཁ͸AWS൛Firebase CloudFunc6onΈ͍ͨͳ΍ͭ

  10. AWS Lambda Custom Run1me • ࠓ·ͰPython΍JavaScriptͳͲɺҰ෦ͷݴޠͷΈΛαϙʔτ͠ ͍ͯͨ • AWS LambdaͰ೚ҙͷݴޠͰॻ͍ͨίʔυΛ࣮ߦͰ͖ΔΑ͏ʹ

    ͳͬͨ
  11. COBOL͕ಈ͘

  12. AWS Lambda Run-me for Swi4 • COBOL͕ಈ͘ͳΒSwi)΋ಈͩ͘Ζ͏ͱࡶʹ࡞ͬͨ • h+ps:/ /github.com/giginet/aws-lambda-swi)-run?me

  13. AWS Lambda Run-meͷ࣮૷ • C++/RustͷϦϑΝϨϯε࣮૷͕͋ͬͨͷͰࢀߟʹͨ͠ • h*ps:/ /github.com/awslabs/aws-lambda-cpp • h*ps:/

    /github.com/awslabs/aws-lambda-rust-run;me
  14. Lambda Run*me࢓૊Έ • AWS Lambdaͷఏڙ͢ΔREST APIΛεΫϦϓτ͔Βpolling • ࣮ߦͰ͖Δஈ֊ʹͳͬͨΒPayloadͱ͔͕ฦͬͯ͘ΔͷͰϢʔ βʔͷॻ͍ͨϋϯυϥͰॲཧ •

    ੒ޭɺࣦഊ࣌ʹAPIୟ͍ͯLambdaଆʹ௨஌
  15. import Foundation import AWSLambdaRuntime struct User: Decodable { let firstName:

    String } enum GreetingError: String, LambdaError { var message: String { switch self { case .invalidPayload: return "Payload is invalid" } } case invalidPayload } run { context -> Result<GreetingError> in guard let data = context.payload, let user = try? JSONDecoder().decode(User.self, from: data) else { return .failure(error: .invalidPayload) } let payload = try! JSONSerialization.data(withJSONObject: ["message": "Hello \(user.firstName)"]) return .success(payload: payload, contentType: "application/json") }
  16. $ aws lambda invoke --function-name hello-swift --payload '{"username": "giginyan"}' output.txt

    Hello giginyan
  17. ࣮ߦόΠφϦͷ࡞੒ • Amazon Linux্Ͱಈ͘Swi/όΠφϦΛ࡞੒ͯ͠AWSʹΞοϓ ϩʔυ͢Δ • docker-swi/ͰUbuntu޲͚ʹϏϧυͨ͠όΠφϦͰ΋ಈ࡞ͨ͠ ͷͰDockerͰϏϧυ͢Δ

  18. • -static-stdlibͷίϯύΠϥϑϥάΛ౉͢͜ͱͰϫϯόΠφ ϦʹͰ͖Δ $ swift build --configuration release -Xswiftc -static-stdlib

  19. • libdispatch͕Sta-c LinkͰ͖ͳͯ͘ࢮ͵ Compile Swift Module 'Example' (1 sources) Linking

    ./.build/x86_64-unknown-linux/debug/Example /usr/bin/ld.gold: error: cannot find -ldispatch
  20. None
  21. None
  22. • docker-swi,Λforkͯ͠ɺ࠷৽ͷToolchainΛؚΜͩDockerίϯ ςφͰϏϧυ͢ΔΑ͏ʹͯ͠Έͨ • ͕ɺͦΕͰ΋͏·͘ߦ͔ͳͯ͘ϋϚͬͨʢ๨Εͨʣ $ swift build -c release

    -Xswiftc -static-stdlib $ /usr/bin/swift-build: error while loading shared libraries: libBlocksRuntime.so.0: cannot open shared object file: No such file or directory
  23. ݱঢ় • ࿦ཧͰ͖͍ͯΔ͕·ͩͰ͖͍ͯͳ͍ • 2ि͙ؒΒ͍લʹ੎͍Ͱ༗څΛऔͬͯ࡞͕ͬͨɺͦͷޙεϚ ϒϥ͕ग़ͯਐḿ͕ऴΘͬͨ

  24. ղܾࡦ 1. LinuxͰಈ͘ϫϯόΠφϦΛੜ੒Ͱ͖ΔΑ͏ʹapple/swi/ͰରԠ 2. AWS Lambda Layer࢖͏ • ඪ४ϥΠϒϥϦΛϨΠϠʔଆʹ࣋ͬͯDynamic LinkͰղܾ

  25. AWS Lambda Layer

  26. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠