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

Bug: sam build - UnicodeEncodeError #7714

Open
ChrysoZalo opened this issue Nov 20, 2024 · 1 comment
Open

Bug: sam build - UnicodeEncodeError #7714

ChrysoZalo opened this issue Nov 20, 2024 · 1 comment
Labels

Comments

@ChrysoZalo
Copy link

Description:

Just trying to follow the tutorial from here: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.html and having issue when trying to run sam build

Steps to reproduce:

sam init

You can preselect a particular runtime or package type when using the sam init experience.
Call sam init --help to learn more.

Which template source would you like to use?
1 - AWS Quick Start Templates
2 - Custom Template Location
Choice: 1

Choose an AWS Quick Start application template
1 - Hello World Example
2 - Data processing
3 - Hello World Example with Powertools for AWS Lambda
4 - Multi-step workflow
5 - Scheduled task
6 - Standalone function
7 - Serverless API
8 - Infrastructure event management
9 - Lambda Response Streaming
10 - Serverless Connector Hello World Example
11 - Multi-step workflow with Connectors
12 - GraphQLApi Hello World Example
13 - Full Stack
14 - Lambda EFS example
15 - DynamoDB Example
16 - Machine Learning
Template: 1

Use the most popular runtime and package type? (python3.13 and zip) [y/N]: n

Which runtime would you like to use?
1 - dotnet8
2 - dotnet6
3 - go (provided.al2)
4 - go (provided.al2023)
5 - graalvm.java11 (provided.al2)
6 - graalvm.java17 (provided.al2)
7 - java21
8 - java17
9 - java11
10 - java8.al2
11 - nodejs20.x
12 - nodejs18.x
13 - nodejs16.x
14 - python3.9
15 - python3.8
16 - python3.13
17 - python3.12
18 - python3.11
19 - python3.10
20 - ruby3.3
21 - ruby3.2
22 - rust (provided.al2)
23 - rust (provided.al2023)
Runtime: 11

What package type would you like to use?
1 - Zip
2 - Image
Package type: 1

Based on your selections, the only dependency manager available is npm.
We will proceed copying the template using npm.

Select your starter template
1 - Hello World Example
2 - Hello World Example TypeScript
Template: 1

Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: y
X-Ray will incur an additional cost. View https://aws.amazon.com/xray/pricing/ for more details

Would you like to enable monitoring using CloudWatch Application Insights?
For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]:

-----------------------
Generating application:
-----------------------
Name: sam-app
Runtime: nodejs20.x
Architectures: x86_64
Dependency Manager: npm
Application Template: hello-world
Output Directory: .
Configuration file: sam-app\samconfig.toml

Next steps can be found in the README file at sam-app\README.md

cd sam-app
sam build

Observed result:

2024-11-20 22:27:33,156 | Config file location: C:\ΕΓΩ\LEARNING\serverless\sam-app\samconfig.toml
2024-11-20 22:27:33,161 | Loading configuration values from [default.['build'].parameters] (env.command_name.section) in config file at 'C:\ΕΓΩ\LEARNING\serverless\sam-app\samconfig.toml'...
2024-11-20 22:27:33,163 | Configuration values successfully loaded.
2024-11-20 22:27:33,166 | Configuration values are: {'stack_name': 'sam-app', 'cached': True, 'parallel': True}
2024-11-20 22:27:33,171 | Using SAM Template at C:\ΕΓΩ\LEARNING\serverless\sam-app\template.yaml
2024-11-20 22:27:33,201 | Using config file: samconfig.toml, config environment: default
2024-11-20 22:27:33,202 | Expand command line arguments to:
2024-11-20 22:27:33,203 | --template_file=C:\ΕΓΩ\LEARNING\serverless\sam-app\template.yaml --parallel --mount_with=READ --build_dir=.aws-sam\build --cache_dir=.aws-sam\cache --cached
2024-11-20 22:27:33,458 | 'build' command is called
2024-11-20 22:27:33,458 | Starting Build use cache
2024-11-20 22:27:33,468 | No Parameters detected in the template
2024-11-20 22:27:33,502 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2024-11-20 22:27:33,504 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2024-11-20 22:27:33,507 | 0 stacks found in the template
2024-11-20 22:27:33,507 | No Parameters detected in the template
2024-11-20 22:27:33,535 | There is no customer defined id or cdk path defined for resource HelloWorldFunction, so we will use the resource logical id as the resource id
2024-11-20 22:27:33,537 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the resource logical id as the resource id
2024-11-20 22:27:33,538 | 2 resources found in the stack
2024-11-20 22:27:33,540 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello-world/'
2024-11-20 22:27:33,541 | --base-dir is not presented, adjusting uri hello-world/ relative to C:\ΕΓΩ\LEARNING\serverless\sam-app\template.yaml
2024-11-20 22:27:33,550 | 2 resources found in the stack
2024-11-20 22:27:33,551 | Found Serverless function with name='HelloWorldFunction' and CodeUri='hello-world/'
2024-11-20 22:27:33,554 | Instantiating build definitions
2024-11-20 22:27:33,558 | Unique function build definition found, adding as new (Function Build Definition: BuildDefinition(nodejs20.x, C:\ΕΓΩ\LEARNING\serverless\sam-app\hello-world, Zip, , d2b1f92f-0ac3-4fff-ba50-4039516d8ea1, {}, {},
x86_64, []), Function: Function({'function_id': 'HelloWorldFunction', 'name': 'HelloWorldFunction', 'functionname': 'HelloWorldFunction', 'runtime': 'nodejs20.x', 'memory': None, 'timeout': 3, 'handler': 'app.lambdaHandler', 'imageuri': None,'packagetype': 'Zip', 'imageconfig': None, 'codeuri': 'C:\ΕΓΩ\LEARNING\serverless\sam-app\hello-world', 'environment': None, 'rolearn': None, 'layers': [], 'events': {'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello',
'Method': 'get', 'RestApiId': 'ServerlessRestApi'}}}, 'metadata': {'SamResourceId': 'HelloWorldFunction'}, 'inlinecode': None, 'codesign_config_arn': None, 'architectures': ['x86_64'], 'function_url_config': None, 'function_build_info':
<FunctionBuildInfo.BuildableZip: ('BuildableZip', 'Regular ZIP function which can be build with SAM CLI')>, 'stack_path': '', 'runtime_management_config': None, 'logging_config': None}))
2024-11-20 22:27:33,573 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-11-20 22:27:33,772 | Telemetry endpoint configured to be https://aws-serverless-tools-telemetry.us-west-2.amazonaws.com/metrics
2024-11-20 22:27:33,772 | Sending Telemetry: {'metrics': [{'commandRun': {'requestId': 'f3d0b9f5-a286-438d-8d65-2181d50e7772', 'installationId': '9d33b273-90c5-48da-9d3a-c1fc45358ec7', 'sessionId': '31a6e489-2362-4a2e-9c3b-150b71efa9bb',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.6', 'samcliVersion': '1.129.0', 'awsProfileProvided': False, 'debugFlagProvided': True, 'region': '', 'commandName': 'sam build', 'metricSpecificAttributes': {'projectType':
'CFN', 'gitOrigin': None, 'projectName': '593ab2ca51e925b9f6c2f258bc55ed5926cf6d2c78239a685d65907e4ec7edd3', 'initialCommit': None}, 'duration': 372, 'exitReason': 'UnicodeEncodeError', 'exitCode': 255}}]}
2024-11-20 22:27:33,773 | Unable to find Click Context for getting session_id.
2024-11-20 22:27:33,779 | Sending Telemetry: {'metrics': [{'events': {'requestId': 'bcabcca8-57f5-425c-8879-858db3c8d121', 'installationId': '9d33b273-90c5-48da-9d3a-c1fc45358ec7', 'sessionId': '31a6e489-2362-4a2e-9c3b-150b71efa9bb',
'executionEnvironment': 'CLI', 'ci': False, 'pyversion': '3.12.6', 'samcliVersion': '1.129.0', 'commandName': 'sam build', 'metricSpecificAttributes': {'events': [{'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id':
'ee76ac32e5ba43879cf9b22f7e36e274', 'time_stamp': '2024-11-20 20:27:33.156', 'exception_name': None}, {'event_name': 'SamConfigFileExtension', 'event_value': '.toml', 'thread_id': '90d00a4dea3148a3a1d54327d53eccee', 'time_stamp': '2024-11-20
20:27:33.200', 'exception_name': None}, {'event_name': 'BuildFunctionRuntime', 'event_value': 'nodejs20.x', 'thread_id': 'e590787be8654384a2ea222afc9db613', 'time_stamp': '2024-11-20 20:27:33.554', 'exception_name': None}]}}}]}
2024-11-20 22:27:34,479 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)
2024-11-20 22:27:34,481 | HTTPSConnectionPool(host='aws-serverless-tools-telemetry.us-west-2.amazonaws.com', port=443): Read timed out. (read timeout=0.1)

Error: 'charmap' codec can't encode characters in position 140-142: character maps to
Traceback:
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1078, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1688, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 1434, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\cli\cli_config_file.py", line 347, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\decorators.py", line 92, in new_func
return ctx.invoke(f, obj, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\click\core.py", line 783, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\telemetry\metric.py", line 185, in wrapped
raise exception # pylint: disable=raising-bad-type
^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\telemetry\metric.py", line 150, in wrapped
return_value = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\utils\version_checker.py", line 43, in wrapped
actual_result = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\cli\main.py", line 95, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\command.py", line 169, in cli
do_cli(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\command.py", line 258, in do_cli
ctx.run()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\commands\build\build_context.py", line 284, in run
self._build_result = builder.build()
^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\build\app_builder.py", line 192, in build
build_graph = self._get_build_graph(self._container_env_var, self._container_env_var_file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\build\app_builder.py", line 276, in _get_build_graph
build_graph.clean_redundant_definitions_and_update(not self._is_building_specific_resource)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\build\build_graph.py", line 324, in clean_redundant_definitions_and_update
self._atomic_write()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\build\build_graph.py", line 482, in _atomic_write
self._write()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\samcli\lib\build\build_graph.py", line 473, in _write
self._filepath.write_text(tomlkit.dumps(document))
File "pathlib.py", line 1048, in write_text
File "encodings\cp1252.py", line 19, in encode

Expected result:

$ sam build
Starting Build use cache
Manifest file is changed (new hash: 3298f1304...d4d421) or dependency folder (.aws-sam/deps/4d3dfad6-a267-47a6-a6cd-e07d6fae318c) is missing for (HelloWorldFunction), downloading dependencies and copying/building source
Building codeuri: /Users/.../Demo/sam-tutorial1/sam-app/hello_world runtime: python3.9 metadata: {} architecture: x86_64 functions: HelloWorldFunction
Running PythonPipBuilder:CleanUp
Running PythonPipBuilder:ResolveDependencies
Running PythonPipBuilder:CopySource
Running PythonPipBuilder:CopySource

Build Succeeded

Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml

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

  1. OS: Windows 10
  2. sam --version: 1.129.0
  3. aws cli --version: 2.22.2
  4. AWS region: not provided yet
# Paste the output of `sam --info` here
{
  "version": "1.129.0",
  "system": {
    "python": "3.12.6",
    "os": "Windows-10-10.0.19045-SP0"
  },
  "additional_dependencies": {
    "docker_engine": "Not available",
    "aws_cdk": "Not available",
    "terraform": "1.9.8"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Add --debug flag to command you are running

@ChrysoZalo ChrysoZalo added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label Nov 20, 2024
@dkphm
Copy link
Contributor

dkphm commented Nov 20, 2024

Thanks for reporting the issue. I was able to reproduce and we will fix in upcoming releases.

@dkphm dkphm added type/bug and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants