Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<zookeeper.version>3.4.10</zookeeper.version>
<scala.version>2.12.2</scala.version>
<aws-lambda-java.version>1.1.0</aws-lambda-java.version>
<aws-lambda-java-events.version>2.2.5</aws-lambda-java-events.version>
<kotlin.version>1.3.21</kotlin.version>
<camel.version>3.0.0-M2</camel.version>
<ap4k.version>0.3.1</ap4k.version>
Expand Down Expand Up @@ -1620,6 +1621,11 @@
<artifactId>aws-lambda-java-core</artifactId>
<version>${aws-lambda-java.version}</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>${aws-lambda-java-events.version}</version>
</dependency>

<dependency>
<groupId>org.apache.maven.shared</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.concurrent.locks.LockSupport;

import org.graalvm.nativeimage.ImageInfo;
import org.jboss.logging.Logger;
import org.jboss.threads.Locks;
import org.wildfly.common.Assert;

Expand All @@ -34,6 +35,8 @@
*/
@SuppressWarnings("restriction")
public abstract class Application {
private static final Logger LOG = Logger.getLogger(Application.class);

private static final int ST_INITIAL = 0;
private static final int ST_STARTING = 1;
private static final int ST_STARTED = 2;
Expand Down Expand Up @@ -177,7 +180,8 @@ public final void stop() {
*/
public final void run(String[] args) {
try {
if (ImageInfo.inImageRuntimeCode()) {
final String property = "DISABLE_SIGNAL_HANDLERS";
if (ImageInfo.inImageRuntimeCode() && System.getenv(property) == null) {
final SignalHandler handler = new SignalHandler() {
@Override
public void handle(final Signal signal) {
Expand All @@ -193,6 +197,8 @@ public void handle(final Signal signal) {
DiagnosticPrinter.printDiagnostics(System.out);
}
});
} else {
LOG.warn("Installation of signal handlers disabled by the presence of the environment variable: " + property);
}
final ShutdownHookThread shutdownHookThread = new ShutdownHookThread(Thread.currentThread());
Runtime.getRuntime().addShutdownHook(shutdownHookThread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@
public final class AmazonLambdaBuildItem extends MultiBuildItem {

private final String className;
private final String path;

public AmazonLambdaBuildItem(String className, String path) {
public AmazonLambdaBuildItem(String className) {
this.className = className;
this.path = path;
}

public String getClassName() {
return className;
}

public String getPath() {
return path;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package io.quarkus.amazon.lambda.deployment;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -22,6 +26,7 @@
import io.quarkus.deployment.recording.RecorderContext;
import io.quarkus.undertow.deployment.ServletBuildItem;

@SuppressWarnings("unchecked")
public final class AmazonLambdaProcessor {
private static final DotName REQUEST_HANDLER = DotName.createSimple(RequestHandler.class.getName());

Expand All @@ -34,8 +39,7 @@ List<AmazonLambdaBuildItem> discover(CombinedIndexBuildItem combinedIndexBuildIt
final DotName name = info.name();

final String lambda = name.toString();
final String mapping = name.local();
ret.add(new AmazonLambdaBuildItem(lambda, mapping));
ret.add(new AmazonLambdaBuildItem(lambda));

ClassInfo current = info;
boolean done = false;
Expand Down Expand Up @@ -72,14 +76,26 @@ public void servlets(List<AmazonLambdaBuildItem> lambdas,
AmazonLambdaTemplate template,
RecorderContext context) {

for (AmazonLambdaBuildItem info : lambdas) {
servletProducer.produce(ServletBuildItem.builder(info.getClassName(), AmazonLambdaServlet.class.getName())
for (AmazonLambdaBuildItem lambda : lambdas) {
servletProducer.produce(ServletBuildItem.builder(lambda.getClassName(), AmazonLambdaServlet.class.getName())
.setLoadOnStartup(1)
.setInstanceFactory(template.lambdaServletInstanceFactory(
(Class<? extends RequestHandler>) context.classProxy(info.getClassName()),
(Class<? extends RequestHandler>) context.classProxy(lambda.getClassName()),
beanContainerBuildItem.getValue()))
.addMapping("/" + info.getPath())
.addMapping("/__lambda")
.build());
}
final File bootstrap = new File("target/bootstrap");
bootstrap.getParentFile().mkdirs();
try (final InputStream stream = getClass().getResourceAsStream("/bootstrap");
final FileOutputStream outputStream = new FileOutputStream(bootstrap)) {
byte[] bytes = new byte[4096];
int read;
while ((read = stream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
21 changes: 21 additions & 0 deletions extensions/amazon-lambda/deployment/src/main/resources/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

RUNNER=$( find . -maxdepth 1 -name '*-runner' )
if [[ ! -z "$RUNNER" ]]
then
export DISABLE_SIGNAL_HANDLERS=true
$RUNNER &
else
java -jar *-runner.jar &
fi

while true
do
export HEADERS="$(mktemp)"
export EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next")
export REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)

RESPONSE=$( curl -sS -X POST "http://localhost:8080/__lambda" -d "$EVENT_DATA" )

curl -sS -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE"
done
12 changes: 12 additions & 0 deletions extensions/amazon-lambda/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
Expand All @@ -31,6 +35,14 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.amazon.lambda.runtime;

import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;

@Path("/2018-06-01/runtime")
public interface AmazonLambdaAPIClient {

@Path("/invocation/next")
@GET
Response next();

@Path("/invocation/{requestId}/response")
@POST
void respond(@PathParam("requestId") String requestId, APIGatewayProxyResponseEvent event);

@Path("/invocation/{requestId}/error")
@POST
void error(@PathParam("requestId") String requestId, String body);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public InstanceFactory<AmazonLambdaServlet> lambdaServletInstanceFactory(Class<?
Objects.requireNonNull(paramType, "Unable to discover parameter type");
return new InstanceFactory<AmazonLambdaServlet>() {
@Override
public InstanceHandle<AmazonLambdaServlet> createInstance() throws InstantiationException {
public InstanceHandle<AmazonLambdaServlet> createInstance() {
BeanContainer.Instance<? extends RequestHandler> instance = factory.create();
AmazonLambdaServlet servlet = new AmazonLambdaServlet(instance, paramType);
return new InstanceHandle<AmazonLambdaServlet>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class LambdaTestCase {
@Test
public void testHelloLambda() {
RestAssured.with().body("{\"firstName\":\"Stuart\",\"lastName\":\"Douglas\"}")
.when().post("/HelloLambda")
.when().post("/__lambda")
.then()
.body(is("\"Hello Stuart Douglas.\""));
}
Expand Down