Slide 1

Slide 1 text

Application development with AWS Lambda and Kotlin 2021.04.05 Kotlin Tech Talk #merpay_techtalk Hiroyuki Kusu ( @hkusu_ )

Slide 2

Slide 2 text

About me

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

"1*(BUFXBZ )551 ఆظ࣮ߦ -BNCEB+BWB,PUMJO ͷΤίγεςϜ *P5 4/4 4 %ZOBNP%# "84ϦιʔεΛར༻ )551 ೚ҙͷαʔϏεΛར༻ ʢ(JU)VC"1* 4MBDL"1* FUDʣ "84Ϧιʔε͔Βىಈ )551Ͱىಈ ͜ͷ͋ͨΓ͕͋Ε͹Ϙοτ΍ӡ༻πʔϧྨͷϗεςΟϯά؀ڥͱͯ͠͸े෼

Slide 10

Slide 10 text

IDE ͸ IntelliJ IDEA Λར༻ ( Community ൛ͳΒແঈ ) ͠ɺ Java ΍ Kotlin ͷϓϩδΣΫτςϯϓϨʔτΛ࢖͏ͱ࢝Ί΍͍͢

Slide 11

Slide 11 text

task buildZip(type: Zip) { from compileKotlin from processResources into('lib') { from configurations.compileClasspath } } build.dependsOn buildZip Kotlin ͷίʔυΛϏϧυ͢Δ Gradle λεΫ ./gradlew build Gradle ίϚϯυͰϏϧυ

Slide 12

Slide 12 text

※ SAM( Serverless Application Model ) ΍ CloudFormation ͰσϓϩΠͯ͠΋͍͍Ͱ͢ ؅ཧίϯιʔϧ ϏϧυͰੜ੒͞Εͨ zip ϑΝΠϧΛ AWS ͷ؅ཧίϯιʔϧ΁Ξοϓϩʔυ

Slide 13

Slide 13 text

// 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' ※ ਵ෼લʹ࡞ͬͨπʔϧͷίʔυ͔ΒҾ༻ͨ͠ͷͰ֤όʔδϣϯ͸ͪΐͬͱݹ͍Ͱ͢.. ೚ҙͷϥΠϒϥϦ͕ར༻Ͱ͖Δ

Slide 14

Slide 14 text

// 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' ※ ਵ෼લʹ࡞ͬͨπʔϧͷίʔυ͔ΒҾ༻ͨ͠ͷͰ֤όʔδϣϯ͸ͪΐͬͱݹ͍Ͱ͢.. ೚ҙͷϥΠϒϥϦ͕ར༻Ͱ͖Δ

Slide 15

Slide 15 text

package io.github.hkusu.githubrepositoryreport import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler class Handler : RequestHandler { 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)

Slide 16

Slide 16 text

package io.github.hkusu.githubrepositoryreport import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler class Handler : RequestHandler { 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)

Slide 17

Slide 17 text

package io.github.hkusu.githubrepositoryreport import com.amazonaws.services.lambda.runtime.Context import com.amazonaws.services.lambda.runtime.RequestHandler class Handler : RequestHandler { 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 = ""

Slide 18

Slide 18 text

https://github.com/hkusu/aws-lambda-templete-for-kotlin AWS Lambda x Kotlin ϓϩδΣΫτͷςϯϓϨʔτ

Slide 19

Slide 19 text

Thank you ! @hkusu_

Slide 20

Slide 20 text

෇࿥

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

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