title: Spring Cloud Function deployed on AWS Lambda fails with NullPointerException at FunctionalSpringApplication.java:102
body: <p>I have a very simple Spring Cloud Functions with the AWS adapter to run it as an AWS Lambda. The source code is available on Github: <a href="https://github.com/codependent/spring-boot-authentication-function" rel="nofollow noreferrer">https://github.com/codependent/spring-boot-authentication-function</a></p>
  
  <pre><code>@SpringBootApplication
  class SpringBootAuthenticationFunctionApplication {
  
      @Bean
      fun kotlinSupplier(): (Credentials) -&gt; AuthenticationResponse {
  
          return {
              if (it.user == "jose" &amp;&amp; it.password == "MyPassword") {
                  //HMAC
                  val algorithm = Algorithm.HMAC256("secret")
                  val token = JWT.create()
                          .withIssuer("MicronautAwsAuthenticationFunction")
                          .withSubject(it.user)
                          .sign(algorithm)
                  AuthenticationResponse(token)
              } else {
                  AuthenticationResponse()
              }
          }
      }
  
  }
  
  fun main(args: Array&lt;String&gt;) {
      runApplication&lt;SpringBootAuthenticationFunctionApplication&gt;(*args)
  }
  </code></pre>
  
  <p>When I run this function on AWS Lambda it throws a NullPointerException. Any idea what's wrong?</p>
  
  <pre><code>{
    "errorMessage": "java.lang.NullPointerException",
    "errorType": "java.lang.NullPointerException",
    "stackTrace": [
      "org.springframework.cloud.function.context.FunctionalSpringApplication.postProcessApplicationContext(FunctionalSpringApplication.java:102)",
      "org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:372)",
      "org.springframework.boot.SpringApplication.run(SpringApplication.java:314)",
      "org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.initialize(SpringFunctionInitializer.java:86)",
      "org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:55)",
      "org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:64)",
      "sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
      "sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)",
      "sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)",
      "java.lang.reflect.Method.invoke(Method.java:498)"
    ]
  }
  </code></pre>
  
  <p>I have set <code>org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler</code> as the value of the handler class in the AWS Console.</p>
  
  <p><strong>Full CloudWatch logs:</strong></p>
  
  <pre><code>16:12:39.252 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifests: [jar:file:/var/runtime/lib/LambdaJavaRTEntry-1.0.jar!/META-INF/MANIFEST.MF, jar:file:/var/runtime/lib/aws-lambda-java-core-1.2.0.jar!/META-INF/MANIFEST.MF, file:/var/task/META-INF/MANIFEST.MF]
  16:12:39.258 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifest: jar:file:/var/runtime/lib/LambdaJavaRTEntry-1.0.jar!/META-INF/MANIFEST.MF
  16:12:39.259 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifest: jar:file:/var/runtime/lib/aws-lambda-java-core-1.2.0.jar!/META-INF/MANIFEST.MF
  16:12:39.260 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifest: file:/var/task/META-INF/MANIFEST.MF
  16:12:39.261 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Searching manifests: []
  16:12:39.261 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Main class: null
  START RequestId: 66460dc7-e90b-487c-a022-12c04ab72c7d Version: $LATEST
  16:12:39.272 [main] INFO org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer - Initializing: null
  
  . ____ _ __ _ _
  /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
  ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
  \\/ ___)| |_)| | | | | || (_| | ) ) ) )
  ' |____| .__|_| |_|_| |_\__, | / / / /
  =========|_|==============|___/=/_/_/_/
  :: Spring Boot ::
  
  2019-03-21 16:12:45.617 ERROR 1 --- [ main] o.s.boot.SpringApplication : Application run failed
  
  java.lang.NullPointerException: null
  at org.springframework.cloud.function.context.FunctionalSpringApplication.postProcessApplicationContext(FunctionalSpringApplication.java:102) ~[task/:na]
  at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:372) ~[task/:na]
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[task/:na]
  at org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.initialize(SpringFunctionInitializer.java:86) [task/:na]
  at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:55) [task/:na]
  at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:64) [task/:na]
  at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:888) [LambdaSandboxJava-1.0.jar:na]
  at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:293) [LambdaSandboxJava-1.0.jar:na]
  at lambdainternal.AWSLambda.&lt;clinit&gt;(AWSLambda.java:64) [LambdaSandboxJava-1.0.jar:na]
  at java.lang.Class.forName0(Native Method) [na:1.8.0_181]
  at java.lang.Class.forName(Class.java:348) [na:1.8.0_181]
  at lambdainternal.LambdaRTEntry.main(LambdaRTEntry.java:104) [LambdaJavaRTEntry-1.0.jar:na]
  java.lang.NullPointerException: java.lang.NullPointerException
  java.lang.NullPointerException
  at org.springframework.cloud.function.context.FunctionalSpringApplication.postProcessApplicationContext(FunctionalSpringApplication.java:102)
  at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:372)
  at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
  at org.springframework.cloud.function.adapter.aws.SpringFunctionInitializer.initialize(SpringFunctionInitializer.java:86)
  at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.initialize(SpringBootStreamHandler.java:55)
  at org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler.handleRequest(SpringBootStreamHandler.java:64)
  </code></pre>