aws / aws-lambda-builders

Python library to compile, build & package AWS Lambda functions for several runtimes & framework
Apache License 2.0
334 stars 139 forks source link

German Umlaut in Maven stdout causes SAM build to fail #548

Closed InsertPikachuFace closed 9 months ago

InsertPikachuFace commented 11 months ago

Description:

Because the log output from the Maven build is decoded with UTF-8 (see line), an "ü" in our unit-test logs causes the SAM local Lambda build to fail. If I add -DskipTests with a Makefile it completes as expected.

Steps to reproduce the issue:

  1. Set up Lambda project that logs out an Umlaut (äÄöÖüÜß) during maven package
  2. run sam build with default template configuration

Observed result:

 | JavaMavenWorkflow:CopySource succeeded
 | Running JavaMavenWorkflow:MavenBuild
 | 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 369, in run
    action.execute()
  File "C:\Program Files\Amazon\AWSSAMCLI\runtime\lib\site-packages\aws_lambda_builders\workflows\java_maven\actions.py", line 39, 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 0xfc in position 43840: invalid start byte

Expected result:

SAM build completes despite an encoding error in a debug-log or it logs out any Maven output correctly.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows 10
  2. SAM CLI version: 1.96.0
  3. AWS region: EU-CENTRAL-1
jfuss commented 11 months ago

Thanks for reporting. Going to mark this as a bug.

@InsertPikachuFace Is this something you would want to contribute a fix for? We understand if not, just will be some lead time before we can patch. We do prioritize bugs highly regardless just might be faster if you submitted a patch is all.

InsertPikachuFace commented 11 months ago

@jfuss I'm not too familiar/comfortable with Python or encoding in general and just disabling the unit-tests with a Makefile is a simple enough workaround, so I'd be fine with waiting for your team to get around to it. I just wanted to report it here in case anybody else runs into this error.

My Makefile (add Metadata: BuildMethod: makefile to the template.yaml):

build-LocalLambda:
    mvn clean package -DskipTests
    mkdir -p $(ARTIFACTS_DIR)\lib
    copy .\target\...*.jar $(ARTIFACTS_DIR)\lib\
jfuss commented 11 months ago

@InsertPikachuFace No worries at all. We appreciate you taking the time to report.

mildaniel commented 9 months ago

The fix has been released in Lambda Builders version 1.40.0 and in AWS SAM CLI version 1.99.0.