Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda function in Gradle Project failed to Running locally #857

Closed
K1-Style opened this issue Mar 28, 2019 · 9 comments
Closed

Lambda function in Gradle Project failed to Running locally #857

K1-Style opened this issue Mar 28, 2019 · 9 comments
Labels
bug We can reproduce the issue and confirmed it is a bug.
Milestone

Comments

@K1-Style
Copy link

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

@abrooksv
Copy link
Contributor

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

@abrooksv abrooksv added the bug We can reproduce the issue and confirmed it is a bug. label Mar 28, 2019
@zhangzhx
Copy link
Contributor

@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.

@K1-Style
Copy link
Author

@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

@abrooksv
Copy link
Contributor

abrooksv commented Mar 29, 2019

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

@K1-Style
Copy link
Author

@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	

@abrooksv
Copy link
Contributor

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

@K1-Style
Copy link
Author

Thanks, it also works.

@zhangzhx
Copy link
Contributor

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

@K1-Style
Copy link
Author

Thanks! I'm grateful to your support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug We can reproduce the issue and confirmed it is a bug.
Projects
None yet
Development

No branches or pull requests

3 participants