Aws-toolkit-jetbrains: Lambda function in Gradle Project failed to Running locally

Created on 28 Mar 2019  Â·  9Comments  Â·  Source: aws/aws-toolkit-jetbrains

Describe the bug
Running Lambda function in Gradle Project fails with "SAM build command failed"

To reproduce

  1. Create a Gradle SAM application
  2. Find build.gradle and right click Import Gradle Project
  3. Open App.java and click Lambda icon on the left of the class definition.
  4. Select Run '[Local] App'
  5. Select my Credentials and Region, and Input Text(API Gateway AWS Proxy)
  6. Execute Run, but it fails with "SAM build command failed"

Build Output details is below.

/usr/local/bin/sam build --template /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template381.yaml --build-dir /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild1175
Build Failed
2019-03-28 21:41:51 Building resource 'Function'
Error: Unable to find a supported build workflow for runtime 'java8'. Reason: None of the supported manifests '['build.gradle', 'pom.xml']' were found in the following paths '['/Users/nomura.keichi/project/serverless/test/HelloWorldFunction/src/main', '/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T']'

Expected behavior
The expected behavior is same as "Running a function locally" on AWS Toolkit for IntelliJ – Now generally available \| AWS Developer Blog

Screenshots
スクリーンショット 2019-03-28 21 49 29
スクリーンショット 2019-03-28 21 27 57
スクリーンショット 2019-03-28 21 42 46
スクリーンショット 2019-03-28 21 43 03

Your Environment

  • OS: macOS Mojave 10.14.4
  • JetBrains' Product: IntelliJ IDEA
  • JetBrains' Product Version: IntelliJ IDEA 2018.3.4 (Ultimate Edition)
    Build #IU-183.5429.30, built on January 29, 2019
    JRE: 1.8.0_152-release-1343-b26 x86_64
    JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  • Toolkit Version: 1.2
  • SAM CLI Version: 0.14.2
  • JVM/Python Version: Java 1.8.0_144

Additional context

bug

Most helpful comment

This fix has been released in stable version 1.3. Feel free to reopen if you still see any issues.

All 9 comments

Can you please attach the contents of the temp file /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template381.yaml?

@K1-Style It seems the root cause is because you checked Create separate module per source set option when import the Gradle project. Try again without checking that option should fix the problem.

@zhangzhx
I tried again without "Create separate module per source set" checking, but it fails similarly.

Gradle Settings is below :
スクリーンショット 2019-03-29 9 41 05

@abrooksv
The result of running the above is below:

/usr/local/bin/sam build --template /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template.yaml --build-dir /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild
2019-03-29 09:51:53 Building resource 'Function'
Error: Unable to find a supported build workflow for runtime 'java8'. Reason: None of the supported manifests '['build.gradle', 'pom.xml']' were found in the following paths '['/Users/nomura.keichi/project/serverless/test/HelloWorldFunction/src/main', '/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T']'
Build Failed

/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/template.yaml

Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      Handler: helloworld.App
      CodeUri: /Users/nomura.keichi/project/serverless/test/HelloWorldFunction/src/main
      Runtime: java8
      Timeout: 900

Okay, I understand what is wrong.

You can also invoke a Lambda function through the existing template.yaml (That SAM generated in your project root). That should not suffer from the same incorrect CodeUri issue

@abrooksv Thank you for your answer.
I tried below, and confirmed that it successed.

  1. Open App.java and click Lambda icon on the left of the class definition.
  2. Select Run '[Local] App'
  3. Check From template: and Select this project's template.yaml
  4. Select my Credentials and Region, and Input Text(API Gateway AWS Proxy)
  5. Execute Run

スクリーンショット 2019-03-29 21 40 10

Build Output details is below.

/usr/local/bin/sam local invoke --template /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild/template.yaml --event "/private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/[Local] App-event.json" HelloWorldFunction
2019-03-29 21:40:51 Found credentials in environment variables.
2019-03-29 21:40:52 Invoking helloworld.App::handleRequest (java8)

Fetching lambci/lambda:java8 Docker container image......
2019-03-29 21:40:54 Mounting /private/var/folders/94/599b3s8j0tbgnn506tmtd17m0000gq/T/lambdaBuild/HelloWorldFunction as /var/task:ro inside runtime container
START RequestId: 90bdc51b-f4d2-401f-bccd-5c78a2cc18fb Version: $LATEST
END RequestId: 90bdc51b-f4d2-401f-bccd-5c78a2cc18fb

{"body":"{ \"message\": \"hello world\", \"location\": \"X.X.X.X\" }","headers":{"X-Custom-Header":"application/json","Content-Type":"application/json"},"statusCode":200}
REPORT RequestId: 90bdc51b-f4d2-401f-bccd-5c78a2cc18fb  Duration: 2236.87 ms    Billed Duration: 2300 ms    Memory Size: 128 MB Max Memory Used: 11 MB  

That is good to hear, you can also go through the template's gutter icon to auto fill in some of that information:

Screen Shot 2019-03-29 at 9 43 10 AM

Thanks, it also works.

This fix has been released in stable version 1.3. Feel free to reopen if you still see any issues.

Thanks! I'm grateful to your support.

Was this page helpful?
0 / 5 - 0 ratings