Reputation: 89
I am working with an aws serverless architecture with spring boot application. When I some time build the project using sam build in intellij, I am getting the following error.
Building codeuri: . runtime: java11 metadata: {} functions: ['MedisproutApiFunction']
Running JavaMavenWorkflow:CopySource
Running JavaMavenWorkflow:MavenBuild
Build Failed
Error: JavaMavenWorkflow:MavenBuild - 'utf-8' codec can't decode byte 0xbb in position 150889: invalid start byte
It is not showing any other error details. If I remove the newly made code changes (even though it does not had any encoding code) this error will not come. Please help me to fix this.
Already checked this link, but no answer found.
Updating Lambda to AWS through intellij plugin
Upvotes: 4
Views: 3408
Reputation: 385
If you don't have test in you app, just add one test with assertTrue(true).
Upvotes: 0
Reputation: 15239
I encountered the same problem today when trying to do a sam build
on my machine for a Java 11 project built with Maven.
I believe the problem is this:
I found some hits in Google where other SAM users encountered a similar problem. Unfortunately, the workaround involves messing with Python source code that was installed as part of the SAM CLI. I prefer not to do this, but I found no cleaner solution as of today.
WORKAROUND STEPS:
Execute your SAM build in debug mode with this command:
sam build --debug
You will see more details of what SAM is doing before the error is displayed.
When the build fails, take note of the Python file and line number where the error occurred. For me, it looked like this:
2021-11-19 09:41:30,430 | JavaMavenWorkflow:MavenBuild raised unhandled exception
Traceback (most recent call last):
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflow.py", line 278, in run
action.execute()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\actions.py", line 36, in execute
self.subprocess_maven.build(self.scratch_dir)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\maven.py", line 31, in build
LOG.debug("Maven logs: %s", stdout.decode("utf8").strip())
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 3795: invalid start byte
Find the offending Python file and open it in a text editor. For me, that file is:
C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\maven.py
NOTE: On Windows, you need to do this step as an Administrator if the SAM CLI is installed under "Program Files".
For me, this was the Python function that was the source of the error:
def build(self, scratch_dir):
args = ["clean", "install"]
ret_code, stdout, _ = self._run(args, scratch_dir)
LOG.debug("Maven logs: %s", stdout.decode("utf8").strip())
if ret_code != 0:
raise MavenExecutionError(message=stdout.decode("utf8").strip())
Edit the code and change the "utf8" to a different character set code. This one worked for me:
def build(self, scratch_dir):
args = ["clean", "install"]
ret_code, stdout, _ = self._run(args, scratch_dir)
LOG.debug("Maven logs: %s", stdout.decode("iso8859_2").strip())
if ret_code != 0:
raise MavenExecutionError(message=stdout.decode("iso8859_2").strip())
Here is the official list of Python encodings, in case you need to try a different one on your own machine:
https://docs.python.org/3/library/codecs.html#standard-encodings
I saved my edits to the Python file, then ran the sam build
again. This time I get normal output from Maven displayed.
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] DataFileEntryTest.unmarshallJsonSampleFileWithUnknownProperties:57 Unexpected exception type thrown ==> expected: <com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException> but was: <java.io.FileNotFoundException>
[ERROR] Errors:
[ERROR] DataFileEntryTest.unmarshallJsonSampleFileWithMissingProperties:49 ť FileNotFound
[ERROR] DataFileEntryTest.unmarshallValidJsonSampleFile:33 ť FileNotFound ..\test-data...
[INFO]
[ERROR] Tests run: 4, Failures: 1, Errors: 2, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.979 s
[INFO] Finished at: 2021-11-19T09:48:55-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project hello-sam: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\jtough\AppData\Local\Temp\tmpi8or6ls5\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Upvotes: 6