aws / serverless-java-container

A Java wrapper to run Spring, Spring Boot, Jersey, and other apps inside AWS Lambda.
https://aws.amazon.com/serverless/
Apache License 2.0
1.5k stars 560 forks source link

Support Cloudwatch Events Requests #296

Closed ssindelar closed 4 years ago

ssindelar commented 5 years ago

Scenario

I want to reduce cold starts of my lambda. For this I set up a Cloudwatch Event rule with regulary triggers the lambda.

Expected behavior

Call from Cloudwatch Events gets ignored or logged.

Actual behavior

Because it isn't a Call from API Gateway or a Application Load Balancer an exception thrown and logged.

Steps to reproduce

  1. Open Cloudwatch -> Rules
  2. Add a new Rule that calls the Lambda regulary
  3. See Cloudwatch Logs of the lambda

Full log output

[2019-10-18 09:49:03.626] b3829e2a-ed43-4662-aaa3-035f17f2100a ERROR c.a.s.p.i.LambdaContainerHandler - Error while handling request
com.amazonaws.serverless.exceptions.InvalidRequestEventException: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:46)
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:29)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:201)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:246)
at de.facecheck.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:24)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293)
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:114)
[2019-10-18 09:49:03.627] b3829e2a-ed43-4662-aaa3-035f17f2100a ERROR c.a.s.p.AwsProxyExceptionHandler - Called exception handler for:
com.amazonaws.serverless.exceptions.InvalidRequestEventException: The incoming event is not a valid request from Amazon API Gateway or an Application Load Balancer
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:46)
at com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader.readRequest(AwsProxyHttpServletRequestReader.java:29)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxy(LambdaContainerHandler.java:201)
at com.amazonaws.serverless.proxy.internal.LambdaContainerHandler.proxyStream(LambdaContainerHandler.java:246)
at de.facecheck.StreamLambdaHandler.handleRequest(StreamLambdaHandler.java:24)
at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at lambdainternal.EventHandlerLoader$StreamMethodRequestHandler.handleRequest(EventHandlerLoader.java:350)
at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888)
at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293)
at lambdainternal.AWSLambda.<clinit>(AWSLambda.java:64)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:114)
sapessi commented 5 years ago

We have documented the process of supporting custom event types in our wiki docs. You have two options: Either create full support for the custom event type or intercept the CloudWatch event types in the handler, before it is passed to the library, and replace it with a simple request type constructed with the AwsProxyRequestBuilder.

sapessi commented 4 years ago

Can we close this @ssindelar?

sapessi commented 4 years ago

Closing this since Provisioned Concurrency is available for Lambda now.