| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
Based on https://ironpdf.com/get-started/aws/
import com.ironsoftware.ironpdf.Settings;
import java.nio.file.Paths;
// Setting IronPDF engine's working directory
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));Note: This setup is mandatory due to AWS enforced execution environment constraints.
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>ironpdf-engine-linux-x64</artifactId>
<version>2022.xx.x</version>
</dependency>Installation prerequisites:
For local testing purposes:
Project Creation: Navigate via File -> New -> Project....
<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>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;
// A function in AWS Lambda to create a PDF from a URL using IronPDF.
public class App {
public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent();
// Optionally enable debugging for IronPDF
Settings.setDebug(true);
// Define the required IronPDF engine working directory
Settings.setIronPdfEngineWorkingDirectory(Paths.get("/tmp/"));
try {
context.getLogger().log("START PDF RENDERING");
// Generate the PDF from a URL
PdfDocument pdf = PdfDocument.renderUrlAsPdf("https://www.google.com");
context.getLogger().log("PDF RENDERING COMPLETED");
// Save the PDF locally
pdf.saveAs("/tmp/my-first-pdf.pdf");
// Prepare HTTP response headers
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
headers.put("X-Custom-Header", "application/json");
// Sending the response with success status
return response
.withHeaders(headers)
.withStatusCode(200)
.withBody("PDF GENERATION SUCCESSFUL");
} catch (Exception e) {
// Handle exceptions by sending error response
return response
.withBody("ERROR: " + e.getMessage())
.withStatusCode(500);
}
}
}Globals:
Function:
Timeout: 400
MemorySize: 2048
EphemeralStorage:
Size: 1024
# Preserve other configuration as is
***Based on <https://ironpdf.com/get-started/aws/>***
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 necessary libraries and tools including pango, libXcomposite, etc (names have been shortened for brevity).
RUN chmod 777 /tmp/
COPY --from=build-image /task/target/classes /var/task/
COPY --from=build-image /task/target/dependency /var/task/lib
# This command can be modified according to requirements in the template.
***Based on <https://ironpdf.com/get-started/aws/>***
CMD ["helloworld.App::handleRequest"]sam build -usam deploy --guided| Back | FazBrowse Home | New Git URL |