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

JavaMavenWorkflow fails Required target/classes directory was not produced from 'mvn package' #203

Open
francis-pang opened this issue Oct 18, 2020 · 3 comments

Comments

@francis-pang
Copy link

francis-pang commented Oct 18, 2020

Description:

Steps to reproduce

  1. Clone repository: [email protected]:francis-pang/expense-tally.git
  2. Check out branch feature/aws-sam
  3. Navigate to ./aws-lambda/get-expenses
  4. Build application via command sam build --use-container --template-file template.yaml

Observed result:

[INFO] Reactor Summary for expense-tally 49-SNAPSHOT:
[INFO] 
[INFO] expense-tally ...................................... SUCCESS [01:40 min]
[INFO] expense-tally-model ................................ SUCCESS [01:03 min]
[INFO] csv-parser ......................................... SUCCESS [  1.795 s]
[INFO] expense-manager .................................... SUCCESS [  9.474 s]
[INFO] expense-reconciliator .............................. SUCCESS [  2.932 s]
[INFO] expense-tally-cli .................................. SUCCESS [01:21 min]
[INFO] aws-lambda ......................................... SUCCESS [  3.556 s]
[INFO] aws-lambda-get-expenses ............................ SUCCESS [  0.373 s]
[INFO] aws-lambda-s3-db-file-update ....................... SUCCESS [01:10 min]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  05:34 min
[INFO] Finished at: 2020-10-18T06:37:37Z
[INFO] ------------------------------------------------------------------------
JavaMavenWorkflow:MavenBuild succeeded
Running JavaMavenWorkflow:MavenCopyDependency
JavaMavenWorkflow:MavenCopyDependency succeeded
Running JavaMavenWorkflow:MavenCopyArtifacts
JavaMavenWorkflow:MavenCopyArtifacts failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/java_maven/actions.py", line 69, in execute
    self._copy_artifacts()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/java_maven/actions.py", line 76, in _copy_artifacts
    raise ActionFailedError("Required target/classes directory was not produced from 'mvn package'")
aws_lambda_builders.actions.ActionFailedError: Required target/classes directory was not produced from 'mvn package'
Builder workflow failed
Traceback (most recent call last):
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflow.py", line 269, in run
    action.execute()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/java_maven/actions.py", line 69, in execute
    self._copy_artifacts()
  File "/usr/local/opt/sam-cli/lib64/python3.7/site-packages/aws_lambda_builders/workflows/java_maven/actions.py", line 76, in _copy_artifacts
    raise ActionFailedError("Required target/classes directory was not produced from 'mvn package'")
aws_lambda_builders.actions.ActionFailedError: Required target/classes directory was not produced from 'mvn package'

Expected result:
Build is successful after

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
Project directory is as below:
only showing the relevant one, full project directory is at aws-sam branch

.
├── LICENSE
├── README.md
├── aws-lambda
│   ├── get-expenses
│   │   ├── pom.xml
│   │   ├── src
│   │   │   └── main
│   │   │       └── java
│   │   │           └── expense_tally
│   │   │               └── views
│   │   │                   └── aws
│   │   │                       └── lambda
│   │   │                           └── HttpGetExpensesHandler.java
│   │   └── template.yaml
│   ├── pom.xml
│   └── s3-db-file-update
│       ├── pom.xml
│       └── src
│           └── main
│               └── java
│                   └── expense_tally
│                       └── views
│                           └── aws
│                               └── lambda
│                                   └── NewSqlDbFileS3Handler.java
├── docs
│   ├── expenses.yaml
│   └── use-case.txt
├── expense-tally.iml
├── pom.xml
└── sonar-project.properties

Contents of template.yaml:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
  expense-tally Get Discrepant Expenses Function
Globals:
  Function:
    Timeout: 15
    MemorySize: 256
    Runtime: java11

Resources:
  GetDiscrepantExpensesFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https:/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      Description: 'Retrieve all the mismatching transactions'
      CodeUri: ../../
      Handler: expense_tally.views.aws.lambda.HttpGetExpensesHandler::handleRequest
      Events:
        GetDiscrepantExpensesApi:
          Type: Api
          Properties:
            Path: '/getDiscrepantExpenses'
            Method: get

Outputs:
  GetDiscrepantExpensesFunction:
    Description: "Get Discrepant Expenses Function ARN"
    Value: !GetAtt GetDiscrepantExpensesFunction.Arn
  HelloWorldFunctionIamRole:
    Description: "Implicit IAM Role created for Get Discrepant Expenses Function function"
    Value: !GetAtt GetDiscrepantExpensesFunction.Arn
@alissonxavierosfglobal
Copy link

Hello. Is it resolved?

@francis-pang
Copy link
Author

Hi @alissonxavierosfglobal , as far as I understand, there is no work done on this yet.

@cboudereau
Copy link

cboudereau commented Sep 26, 2022

The problem is that the CodeUri referring the parent pom folder is also used as working directory in sam build. It would be useful to configure in the AWS Toolkit SAM options the base-dir options like in the CLI.

Here is my workaround in vscode:

In the template.yaml, set the CodeUri parameter to the local folder

CodeUri: .

Then, place the template.yaml close to the parent pom.xml (so that the parent and modules will be copied) and run the following command by replacing the module folder with one of the available one (the working directory to the aws lambda maven module so that sam could bind target classes and dependencies).

sam build -s ./module\ -t ./template.yaml

Prepare a event.json which contains the payload (body) of your lambda

run the sam package

sam local invoke -d 5870 -e ./event.json

In vscode, add a debug configuration (Java attach to process) and setup like this :

{
    "type": "java",
    "name": "Attach to Remote Program",
    "request": "attach",
    "hostName": "localhost",
    "port": "5870"
}

Go to debug and the the "Attach to Remote Program", now you can break anywhere in the java lambda code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants