SAM build runs maven tests and fails with Credentials not found error.
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!
"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]"[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...
Either maven tests are not run or sam cli passes the credentials info to maven tests
sam --version: SAM CLI, version 0.14.2If --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
Most helpful comment
having an option like
--skip-build-testsor similar that would pass to the build tool (in this case maven-DskipTestswould 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