Kotlin Lambda μ‚¬μš©ν•˜κΈ° 😏

김섀희·2024λ…„ 5μ›” 30일
0

Ops

λͺ©λ‘ 보기
7/7

JAR νŒŒμΌμ„ 도컀 μ΄λ―Έμ§€λ‘œ λ³€ν™˜ν›„ μ»¨ν…Œμ΄λ„ˆλ₯Ό ec2에 λ„μ› λŠ”λ° κ³ΌκΈˆλ˜μ–΄μ„œ λžŒλ‹€ μ„œλΉ„μŠ€λ‘œ λ§ˆμ΄κ·Έλ ˆμ΄μ…˜μ„ κ³ λ―Όν•˜κ²Œ λ˜μ—ˆλ‹€.

Lambda에 μ½”λ“œλ₯Ό μ˜¬λ¦¬λŠ” 3가지 방법이닀.

  1. 인라인 μ½”λ“œ (μš©λŸ‰ μ œν•œ : 3MB)
  2. zipνŒŒμΌμ„ μ—…λ‘œλ“œ (μš©λŸ‰ μ œν•œ : 50MB)
  3. μ•„λ§ˆμ‘΄ S3μ—μ„œ 파일 μ—…λ‘œλ“œ
  4. μ»¨ν…Œμ΄λ„ˆ 이미지 μ—…λ‘œλ“œ

JAR 파일 -> S3 μ—…λ‘œλ“œ -> lambda code

μš©λŸ‰μ— μ œν•œλ°›κ³  싢지 μ•Šμ•„μ„œ μœ„μ˜ μˆœμ„œλŒ€λ‘œ 해보겠닀!!

Lambda cold startλ₯Ό ν•΄κ²°ν•˜κΈ° μœ„ν•΄μ„œλŠ” λžŒλ‹€ μ»¨ν…Œμ΄λ„ˆ μ΄λ―Έμ§€λ‘œ μƒμ„±ν•˜λ©΄ μ•ˆ λœλ‹€. λ˜ν•œ JAVA λŸ°νƒ€μž„λ§Œμ„ μ§€μ›ν•œλ‹€.

μ½”λ“œ μˆ˜μ •

μ½”ν‹€λ¦°μœΌλ‘œ μ§œμ—¬μ§„ μ½”λ“œμ˜€κΈ° λ•Œλ¬Έμ— μžλ°” 기반의 κ³΅μ‹λ¬Έμ„œλ₯Ό μ°Έκ³ ν•œλ‹€.

https://docs.aws.amazon.com/lambda/latest/dg/java-package.html

dependencies {
    implementation 'com.amazonaws:aws-lambda-java-core:1.2.2'
    implementation 'com.amazonaws:aws-lambda-java-events:3.11.1'
    runtimeOnly 'com.amazonaws:aws-lambda-java-log4j2:1.5.1'
}

build.gradle νŒŒμΌμ—
μ˜μ‘΄μ„±μ— μ„Έ 개의 μ˜μ‘΄μ„±μ„ μΆ”κ°€ν•΄μ€€λ‹€

task buildZip(type: Zip) {
    into('lib') {
        from(jar)
        from(configurations.runtimeClasspath)
    }
}

μžλ°”, μŠ€ν”„λ§μ΄λΌλ©΄ κ·ΈλŒ€λ‘œ μ‚¬μš©ν•˜λ©΄ 되고 코틀린이라면 μ•„λž˜ μ½”λ“œλ‘œ λ°”κΏ”μ€€λ‹€

tasks.register<Zip>("buildZip") {
	from(tasks.getByName<JavaCompile>("compileJava"))
	from(tasks.getByName<ProcessResources>("processResources"))
	archiveFileName.set("lambda.zip")
	destinationDirectory.set(file("$buildDir/dist"))
	duplicatesStrategy = DuplicatesStrategy.WARN

	into("lib") {
		from(configurations.getByName("runtimeClasspath").files)
	}
}

코끼리λ₯Ό κΌ­ λŒλ €μ„œ μ μš©μ„ ν•΄μ•Όν•œλ‹€

Lambda ν•¨μˆ˜ 생성



ν•Έλ“€λŸ¬ μˆ˜μ •ν•˜κΈ° org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest

0개의 λŒ“κΈ€