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

Application development with AWS Lambda and Kotlin

Application development with AWS Lambda and Kotlin

Kotlin Tech Talk ( https://mercari.connpass.com/event/206751/ ) の資料

D8281434c0409ba2051cd3f7590e4c2f?s=128

Hiroyuki Kusu

April 05, 2021
Tweet

Transcript

  1. Application development with AWS Lambda and Kotlin 2021.04.05 Kotlin Tech

    Talk #merpay_techtalk Hiroyuki Kusu ( @hkusu_ )
  2. About me

  3. https://aws.amazon.com/jp/lambda/ ݱ࣌఺Ͱ͸ Java ͸ Java 8 ͱ Java 11 ͕࢖͑Δ

  4. "1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB +BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%#

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ
  5. "1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB +BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%#

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ
  6. "1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB +BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%#

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ
  7. "1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB +BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%#

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ
  8. "1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB +BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%#

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ
  9. "1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB +BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%#

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ ͜ͷ͋ͨΓ͕͋Ε͹Ϙοτ΍ӡ༻πʔϧྨͷϗεςΟϯά؀ڥͱͯ͠͸े෼
  10. IDE ͸ IntelliJ IDEA Λར༻ ( Community ൛ͳΒແঈ ) ͠ɺ

    Java ΍ Kotlin ͷϓϩδΣΫτςϯϓϨʔτΛ࢖͏ͱ࢝Ί΍͍͢
  11. task buildZip(type: Zip) { from compileKotlin from processResources into('lib') {

    from configurations.compileClasspath } } build.dependsOn buildZip Kotlin ͷίʔυΛϏϧυ͢Δ Gradle λεΫ ./gradlew build Gradle ίϚϯυͰϏϧυ
  12. ※ SAM( Serverless Application Model ) ΍ CloudFormation ͰσϓϩΠͯ͠΋͍͍Ͱ͢ ؅ཧίϯιʔϧ

    ϏϧυͰੜ੒͞Εͨ zip ϑΝΠϧΛ AWS ͷ؅ཧίϯιʔϧ΁Ξοϓϩʔυ
  13. // Kotlin implementation “org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72” implementation “org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3” // Network implementation "com.squareup.retrofit2:retrofit:2.7.1"

    implementation "com.squareup.retrofit2:converter-moshi:2.6.0" implementation "com.squareup.moshi:moshi:1.8.0" implementation "com.squareup.moshi:moshi-kotlin:1.8.0" implementation “com.squareup.okhttp3:okhttp:4.3.1” implementation “com.squareup.okhttp3:logging-interceptor:4.3.1” // AWS implementation 'com.amazonaws:aws-lambda-java-core:1.1.0' ※ ਵ෼લʹ࡞ͬͨπʔϧͷίʔυ͔ΒҾ༻ͨ͠ͷͰ֤όʔδϣϯ͸ͪΐͬͱݹ͍Ͱ͢.. ೚ҙͷϥΠϒϥϦ͕ར༻Ͱ͖Δ
  14. // Kotlin implementation “org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72” implementation “org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3” // Network implementation "com.squareup.retrofit2:retrofit:2.7.1"

    implementation "com.squareup.retrofit2:converter-moshi:2.6.0" implementation "com.squareup.moshi:moshi:1.8.0" implementation "com.squareup.moshi:moshi-kotlin:1.8.0" implementation “com.squareup.okhttp3:okhttp:4.3.1” implementation “com.squareup.okhttp3:logging-interceptor:4.3.1” // AWS implementation 'com.amazonaws:aws-lambda-java-core:1.1.0' ※ ਵ෼લʹ࡞ͬͨπʔϧͷίʔυ͔ΒҾ༻ͨ͠ͷͰ֤όʔδϣϯ͸ͪΐͬͱݹ͍Ͱ͢.. ೚ҙͷϥΠϒϥϦ͕ར༻Ͱ͖Δ
  15. package io.github.hkusu.githubrepositoryreport import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler class Handler : RequestHandler<Input,

    Output> { override fun handleRequest(input: Input, context: Context): Output { // do something ... return Output(statusCode = 200, body = "OK") } } // API Gateway ͷ Lambda ϓϩΩγ౷߹ͷ৔߹ data class Input(var body: String? = null) // varͰσϑΥϧτ஋͕ඞཁ data class Output(val statusCode: Int, val body: String)
  16. package io.github.hkusu.githubrepositoryreport import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler class Handler : RequestHandler<Input,

    Output> { override fun handleRequest(input: Input, context: Context): Output { // do something ... return Output(statusCode = 200, body = "OK") } } // API Gateway ͷ Lambda ϓϩΩγ౷߹ͷ৔߹ data class Input(var body: String? = null) // varͰσϑΥϧτ஋͕ඞཁ data class Output(val statusCode: Int, val body: String)
  17. package io.github.hkusu.githubrepositoryreport import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler class Handler : RequestHandler<Input,

    Output> { override fun handleRequest(input: Input, context: Context): Output { // do something ... return Output(statusCode = 200, body = "OK") } } // API Gateway ͷ Lambda ϓϩΩγ౷߹ͷ৔߹ data class Input(var body: String? = null) // varͰσϑΥϧτ஋͕ඞཁ data class Output(val statusCode: Int, val body: String) Input().body = "<JSONจࣈྻ>"
  18. https://github.com/hkusu/aws-lambda-templete-for-kotlin AWS Lambda x Kotlin ϓϩδΣΫτͷςϯϓϨʔτ

  19. Thank you ! @hkusu_

  20. ෇࿥

  21. API Gateway Λ࢖͏৔߹͸ Lambda ϓϩΩγ౷߹ʹ͓ͯ͘͠ͱ Lambda ͷೖग़ྗ͕ѻ͍΍͘͢ͳΔ

  22. Lambda ͷϋϯυϥͷઃఆྫ ( ΫϥεͷϑϧύεΛࢦఆ͢Δ )

  23. γʔΫϨοτͳ΋ͷ͸؀ڥม਺΁ઃఆ