aws-sam-cli
aws-sam-cli copied to clipboard
sam build runs maven tests
Description
SAM build runs maven tests and fails with Credentials not found error.
Steps to reproduce
-
Run SAM build for a maven backed lambda like below.
/usr/local/bin/sam build --template /private/var/folders/70/307d2nds25b6pq7xthz1mfmw0000gp/T/template6.yaml --build-dir /private/var/folders/70/307d2nds25b6pq7xthz1mfmw0000gp/T/lambdaBuild11 --use-container --skip-pull-image
-
Tests run
-------------------------------------------------------
T E S T S
-------------------------------------------------------
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.mylambda.XTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.14 sec <<< FAILURE!
- Tests initialize SDK client in code and errors with
"Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), com.amazonaws.auth.profile.ProfileCredentialsProvider@4362d7df: profile file cannot be null, com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@21680803: Unable to load credentials from service endpoint]"
Observed result
[INFO] BUILD FAILURE\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 01:40 min\n[INFO] Finished at: 2019-04-08T20:09:05Z\n[INFO] ------------------------------------------------------------------------\n[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project project-name: There are test failures.\n[ERROR] \n[ERROR] Please refer to /tmp/samcli/scratch/target/surefire-reports for the individual test results.\n[ERROR] -> [Help 1]\n[ERROR] \n[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.\n[ERROR] Re-run Maven using the -X switch to enable full debug logging.\n[ERROR] \n[ERROR] For more information about the errors and possible solutions, please read the following articles:\n[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException", "code": 400}}
2019-04-08 14:09:06 http://localhost:None "GET /v1.35/containers/bea332c6a58fcf8040ce61bdaf31704d0224f8e511d629fbe963c015ad18feaf/json HTTP/1.1" 200 None
2019-04-08 14:09:06 http://localhost:None "DELETE /v1.35/containers/bea332c6a58fcf8040ce61bdaf31704d0224f8e511d629fbe963c015ad18feaf?v=False&link=False&force=True HTTP/1.1" 204 0
Build Failed
Error: JavaMavenWorkflow:MavenBuild - Maven Failed: [INFO] Scanning for projects...
Expected result
Either maven tests are not run or sam cli passes the credentials info to maven tests
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: macOs
-
sam --version
: SAM CLI, version 0.14.2
If --use-container
is removed then the build passes even though running Maven tests.
/usr/local/bin/sam build --template /private/var/folders/70/307d2nds25b6pq7xthz1mfmw0000gp/T/template6.yaml --build-dir /private/var/folders/70/307d2nds25b6pq7xthz1mfmw0000gp/T/lambdaBuild11 --skip-pull-image --debug
having an option like --skip-build-tests
or similar that would pass to the build tool (in this case maven -DskipTests
would be nice to speed up trial development and debugging for projects with lots of included tests.
From the build source here is the location that defines the "JavaMavenWorkflow:MavenBuild" step -> https://github.com/aws/aws-lambda-builders/blob/67f42dd936fd4f0c517c38acb8b6a170156549ec/aws_lambda_builders/workflows/java_maven/maven.py#L27-L34
I'm surprised no-one has yet suggested the following workaround:
MAVEN_OPTS="-DskipTests=true" sam build
You can pass all sorts of flags this way.
You will know it's working when you see the following in the --debug output
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ ... ---
[INFO] Tests are skipped.
Hi, lestephane,
does MAVEN_OPTS="-DskipTests=true" sam build work for you?
I tried it in command line and it does not work. Besides, the sam build can be triggered inside AWS toolkit plugin, where there is no way to set it before the sam build command
@gigi888 when you use the word 'that', what are you referring to? Please include commands and their outputs if you need me to follow up (and / or stand corrected). This will avoid further ping pong in comments.
If using it through the AWS Toolkit, you can still edit environment variables for launch configurations and add MAVEN_OPTS there, unless I missed something. Again, describe the sequence of steps you're going through if you still can't make it work there, and I may be able to followup.
As @lestephane recommended, tests can be skipped by providing MAVEN_OPTS="-DskipTests=true"
. You can also set that while running --use-container
option.
Building in process; MAVEN_OPTS="-DskipTests=true" sam build
Building inside container; sam build --use-container --container-env-var MAVEN_OPTS="-DskipTests=true"
If you want to execute a different maven goal/target, you can customize your workflow by using Makefile
builds, you can read more about it here; https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-custom-runtimes.html
⚠️COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
If you don't have test in you app, just add one test with assertTrue(true).