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

The AWS CLI ignores attempts to use UTF-8 on Windows, #8312

Closed
Zaita opened this issue Nov 8, 2023 · 3 comments
Closed

The AWS CLI ignores attempts to use UTF-8 on Windows, #8312

Zaita opened this issue Nov 8, 2023 · 3 comments
Assignees
Labels
bug This issue is a bug. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@Zaita
Copy link

Zaita commented Nov 8, 2023

Describe the bug

The AWS CLI ignores attempts to use UTF-8 on Windows, this causes failures when interacting with the SecurityHub API as this is returning UTF characters that then fail encoding.

This has been discussed previously here:
https://stackoverflow.com/questions/39301253/can-i-force-aws-cli-v1-to-use-utf-encoding

And there are instructions regarding encoding here:
https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html

The issue is that because the AWS CLI is packaging and launching it's own Python interpreter, it won't recognise standard environment variables.

I am using latest AWS CLI, the following command is used from Windows Command Prompt:
aws securityhub get-findings --filters "{\"WorkflowStatus\": [{\"Value\":\"NEW\",\"Comparison\":\"EQUALS\"}], \"SeverityLabel\": [{\"Value\": \"HIGH\", \"Comparison\":\"EQUALS\"}], \"RecordState\": [{\"Value\":\"ACTIVE\", \"Comparison\":\"EQUALS\"}] }" --sort-criteria "{\"Field\":\"FirstObservedAt\", \"SortOrder\":\"desc\"}" --page-size=100 --profile=SecurityReadOnly --debug > high_findings.json

This is the error that I get.
image

I have previously raised a support case with AWS, the outcome was to log a GitHub issue after multiple back-n-forth attempts to fix it.

Expected Behavior

The AWS CLI can successfully call the SecurityHub endpoint without an encoding error when the user is specifying UTF-8 as the encoding scheme.

Current Behavior

If the AWS SecurityHub Get-Findings call returns a UTF-8 character, an encoding error occurs:
image

Reproduction Steps

aws securityhub get-findings --filters "{\"WorkflowStatus\": [{\"Value\":\"NEW\",\"Comparison\":\"EQUALS\"}], \"SeverityLabel\": [{\"Value\": \"HIGH\", \"Comparison\":\"EQUALS\"}], \"RecordState\": [{\"Value\":\"ACTIVE\", \"Comparison\":\"EQUALS\"}] }" --sort-criteria "{\"Field\":\"FirstObservedAt\", \"SortOrder\":\"desc\"}" --page-size=100 --profile=SecurityReadOnly --debug > high_findings.json

On an account with a security finding that includes a UTF-8 character.

Possible Solution

Add a command line parameter to allow for encoding selection.

Additional Information/Context

At the moment, the workaround is the decompress the packaged Python and alter the cp1252.py file to force UTF-8 then re-compress it and ensure the CLI is using it. This is a very hacky workaround.

Support Case: 12249326911 has a bunch of context for this.

CLI version used

aws-cli/2.13.32 Python/3.11.6 Windows/10 exe/AMD64 prompt/off

Environment details (OS name and version, etc.)

Windows 10, command prompt

@Zaita Zaita added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 8, 2023
@RyanFitzSimmonsAK RyanFitzSimmonsAK self-assigned this Nov 9, 2023
@RyanFitzSimmonsAK RyanFitzSimmonsAK added investigating This issue is being investigated and/or work is in progress to resolve the issue. p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 9, 2023
@RyanFitzSimmonsAK
Copy link
Contributor

RyanFitzSimmonsAK commented Nov 9, 2023

Hi @Zaita, thanks for reaching out. This issue has come up a couple times recently, and there are few things that might fix it. I will note that the AWS CLI uses the character encoding provided by your system.

  • Change your system locale (per this Stack Overflow thread)
  • Set the environment variable PYTHONUTF8=1
  • Set the environment variable PYTHONIOENCODING=UTF-8

Let me know if any of those work for you. Thanks!

@RyanFitzSimmonsAK RyanFitzSimmonsAK added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Nov 9, 2023
@Zaita Zaita changed the title (short issue description) The AWS CLI ignores attempts to use UTF-8 on Windows, Nov 19, 2023
@Zaita
Copy link
Author

Zaita commented Nov 20, 2023

Thanks. Can confirm using PYTHONUTF8=1 works.

@Zaita Zaita closed this as completed Nov 20, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p3 This is a minor priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants