AWS Lambda에서 Java용 IronPDF 실행하는 방법
중요: 필수 설정
- IronPDF 런타임에 바이너리 실행이 필요하므로 ZIP 배포는 지원되지 않습니다.
- IronPDF for Java는 Docker 배포만을 지원하므로
PackageType를Image로 설정해야 합니다. AmazonLinux2Docker 이미지를 사용해야 합니다.- IronPDFEngineWorkingDirectory를 다음과 같이 설정해야 합니다.
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
// Setting the working directory for IronPDF engine
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
// Setting the working directory for IronPDF engine
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
참고: 이는 AWS에서 실행 환경에 허용하는 유일한 경로이므로 필수 사항입니다.
/tmp크기를 늘리십시오. 기본 값은 512 MB입니다. 최소 1024MB로 설정해 주세요.- 프로젝트에
ironpdf-engine-linux-x64의존성을 포함하십시오:
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2022.xx.x</version>
</dependency>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2022.xx.x</version>
</dependency>
- 시작 속도가 느리므로 Lambda 타임아웃을 330초로 설정하세요.
- Lambda 메모리 크기를 최소 1024MB로 설정하십시오.
IntelliJ IDEA용 AWS 툴킷(AWS SAM) 빠른 시작
-
도구 설치:
- IntelliJ IDEA - IntelliJ IDEA 다운로드
- AWS 툴킷 - JetBrains용 AWS 툴킷 설정
- SAM CLI - 서버리스 애플리케이션용 SAM CLI를 설치하세요
- Docker - Docker Community Edition 설치
(선택 사항, 로컬 테스트용):
- Java 8 - Java SE 개발 키트 8을 다운로드하세요
- Maven - Maven 설치 가이드라인
- 프로젝트 생성: (
File->New->Project...)

- 구성:
- 패키지 유형:
Image - 런타임:
java8또는java11 - SAM 템플릿:
Maven
- 패키지 유형:

- 다음 의존성을
pom.xml에 추가하십시오:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2022.11.1</version>
</dependency>
<dependency>
<groupId>io.perfmark</groupId>
<artifactId>perfmark-api</artifactId>
<version>0.26.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.50.2</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.50.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2022.11.1</version>
</dependency>
<dependency>
<groupId>io.perfmark</groupId>
<artifactId>perfmark-api</artifactId>
<version>0.26.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-okhttp</artifactId>
<version>1.50.2</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.50.2</version>
</dependency>
App.java에서handleRequest함수 코드를 변경하십시오:
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
// AWS Lambda function to generate a PDF from a URL using IronPDF.
public class App {
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
// Enable debugging for IronPDF (optional)
Settings.setDebug(true);
// Set the working directory for the IronPDF engine (required)
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
try {
context.getLogger().log("RENDER PDF");
// Render the PDF from a URL
PdfDocument pdf = PdfDocument.renderUrlAsPdf("https://www.google.com");
context.getLogger().log("RENDER PDF SUCCESS");
// Save the generated PDF to a file
pdf.saveAs("/tmp/my-first-pdf.pdf");
// Set HTTP response headers
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("X-Custom-Header", "application/json");
// Return the successful response
return response
.withHeaders(headers)
.withStatusCode(200)
.withBody("ENJOY IRON-PDF!");
} catch (Exception e) {
// Return the error response
return response
.withBody("{" + e.getMessage() + "}")
.withStatusCode(500);
}
}
}
import com.amazonaws.services.lambda.runtime.Context;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
import com.ironsoftware.ironpdf.PdfDocument;
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
// AWS Lambda function to generate a PDF from a URL using IronPDF.
public class App {
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
// Enable debugging for IronPDF (optional)
Settings.setDebug(true);
// Set the working directory for the IronPDF engine (required)
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
try {
context.getLogger().log("RENDER PDF");
// Render the PDF from a URL
PdfDocument pdf = PdfDocument.renderUrlAsPdf("https://www.google.com");
context.getLogger().log("RENDER PDF SUCCESS");
// Save the generated PDF to a file
pdf.saveAs("/tmp/my-first-pdf.pdf");
// Set HTTP response headers
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("X-Custom-Header", "application/json");
// Return the successful response
return response
.withHeaders(headers)
.withStatusCode(200)
.withBody("ENJOY IRON-PDF!");
} catch (Exception e) {
// Return the error response
return response
.withBody("{" + e.getMessage() + "}")
.withStatusCode(500);
}
}
}
template.yaml에서 Lambda 구성을 설정하십시오:
Globals:
Function:
Timeout: 400
MemorySize: 2048
EphemeralStorage:
Size: 1024
# Do not modify other configurations
Globals:
Function:
Timeout: 400
MemorySize: 2048
EphemeralStorage:
Size: 1024
# Do not modify other configurations
- Dockerfile 업데이트:
- 주의: Java 8의 경우
java8.al2이미지를 사용하십시오. 그들은AmazonLinux2를 사용하지만java8는 예전AmazonLinux를 사용합니다.
- 주의: Java 8의 경우
FROM public.ecr.aws/sam/build-java8.al2:latest as build-image
WORKDIR "/task"
COPY src/ src/
COPY pom.xml ./
RUN mvn -q clean install
RUN mvn dependency:copy-dependencies -DincludeScope=compile
FROM public.ecr.aws/lambda/java:8.al2
RUN yum update -y
RUN yum install -y pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 \
libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 \
cups-libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 \
alsa-lib.x86_64 atk.x86_64 gtk3.x86_64 ipa-gothic-fonts \
xorg-x11-fonts-100dpi xorg-x11-fonts-75dpi xorg-x11-utils \
xorg-x11-fonts-cyrillic xorg-x11-fonts-Type1 xorg-x11-fonts-misc \
glibc-devel.x86_64 at-spi2-atk.x86_64 mesa-libgbm.x86_64 libxkbcommon \
amazon-linux-extras
RUN amazon-linux-extras install epel -y
RUN yum install -y libgdiplus
RUN chmod 777 /tmp/
COPY --from=build-image /task/target/classes /var/task/
COPY --from=build-image /task/target/dependency /var/task/lib
# Command can be overridden by providing a different command in the template directly.
CMD ["helloworld.App::handleRequest"]
- 프로젝트를 빌드하세요:
sam build -u
sam build -u
- 프로젝트를 배포합니다.
sam deploy --guided
sam deploy --guided
- AWS Lambda에서 IronPDF 사용해 보세요! 이제 함수가 활성화되었습니다. AWS Lambda 콘솔에 접속하세요.
자주 묻는 질문
AWS Lambda에서 Java를 사용하여 PDF를 생성하고 편집하는 방법은 무엇인가요?
'AmazonLinux2' Docker 이미지를 사용하여 환경을 설정하고 /tmp 디렉터리 크기 증가 및 Lambda 시간 초과 설정과 같은 필요한 설정을 구성하면 AWS Lambda에서 IronPDF for Java를 사용할 수 있습니다.
AWS Lambda에서 PDF 처리를 위해 Zip Deployment를 사용할 수 없는 이유는 무엇인가요?
AWS Lambda에서 IronPDF는 런타임 시 바이너리 실행이 필요하므로 Zip 배포를 지원하지 않습니다. Docker 배포를 위해서는 'PackageType'을 'Image'로 설정해야 합니다.
AWS Lambda에서 IronPDF의 작업 디렉터리에 필요한 구성은 무엇입니까?
IronPDF 엔진의 작업 디렉토리를 '/tmp/'로 설정하고 PDF 처리를 효율적으로 수행할 수 있도록 디렉토리 크기를 최소 1024MB로 늘리십시오.
AWS Lambda에서 Maven 프로젝트를 사용하여 PDF를 생성하려면 어떤 종속성을 포함해야 합니까?
PDF 생성 및 편집을 활성화하려면 Maven 프로젝트의 pom.xml 파일에 'ironpdf-engine-linux-x64' 종속성을 비롯한 필요한 라이브러리를 추가하십시오.
AWS Lambda에서 Java를 사용하여 URL로부터 PDF를 렌더링하려면 어떻게 해야 합니까?
IronPDF의 PdfDocument.renderUrlAsPdf 메서드를 사용하여 URL을 PDF 문서로 변환하고, pdf.saveAs 메서드를 사용하여 저장하십시오.
PDF 처리를 위한 Lambda 타임아웃 및 메모리 설정 권장 사항은 무엇입니까?
AWS Lambda에서 IronPDF의 처리 요구 사항을 충족하려면 Lambda 타임아웃을 330초로 설정하고 최소 1024MB의 메모리를 할당하십시오.
AWS Lambda에서 Java를 사용하여 PDF 작업을 실행하는 데 사용할 수 있는 런타임 환경은 무엇입니까?
IronPDF는 AWS Lambda에서 PDF 처리 작업을 실행하기 위해 'java8' 및 'java11' 런타임 환경을 지원합니다.
Java를 사용하여 IntelliJ IDEA용 AWS Toolkit으로 PDF 처리를 빠르게 시작하려면 어떻게 해야 하나요?
IntelliJ IDEA, AWS Toolkit, SAM CLI 및 Docker를 설치하세요. 선택적으로 로컬 테스트를 위해 Java 8 및 Maven을 설정한 다음 빠른 시작 가이드를 따라 프로젝트를 생성하고 구성하세요.
SAM CLI를 사용하여 AWS Lambda에 Java PDF 처리 프로젝트를 배포하는 과정은 무엇입니까?
먼저 sam build -u 명령어를 사용하여 프로젝트를 빌드한 다음, sam deploy --guided 를 사용하여 배포하면 AWS Lambda에서 PDF 처리를 효율적으로 설정할 수 있습니다.

