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/ ) の資料

Hiroyuki Kusu

April 05, 2021
Tweet

More Decks by Hiroyuki Kusu

Other Decks in Programming

Transcript

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

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

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

    "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ
  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. IDE ͸ IntelliJ IDEA Λར༻ ( Community ൛ͳΒແঈ ) ͠ɺ

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

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

    ϏϧυͰੜ੒͞Εͨ zip ϑΝΠϧΛ AWS ͷ؅ཧίϯιʔϧ΁Ξοϓϩʔυ
  11. // 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' ※ ਵ෼લʹ࡞ͬͨπʔϧͷίʔυ͔ΒҾ༻ͨ͠ͷͰ֤όʔδϣϯ͸ͪΐͬͱݹ͍Ͱ͢.. ೚ҙͷϥΠϒϥϦ͕ར༻Ͱ͖Δ
  12. // 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' ※ ਵ෼લʹ࡞ͬͨπʔϧͷίʔυ͔ΒҾ༻ͨ͠ͷͰ֤όʔδϣϯ͸ͪΐͬͱݹ͍Ͱ͢.. ೚ҙͷϥΠϒϥϦ͕ར༻Ͱ͖Δ
  13. 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)
  14. 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)
  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) Input().body = "<JSONจࣈྻ>"