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

Unsupported Locale Error with upgrading to Python 3.12 image from Python 3.10/11 #229

Open
agosmou opened this issue Feb 7, 2025 · 1 comment

Comments

@agosmou
Copy link

agosmou commented Feb 7, 2025

Description:

Bug/missing-packages with locale configuration in the AWS Lambda Python 3.12 runtime Docker images

Steps to reproduce:

✅ Working Condition:

Use a Python 3.10 image, then build and run your dockerfile as below:

# any of these 3.10 images work
FROM public.ecr.aws/lambda/python:3.10.2025.01.15.17-x86_64
# FROM public.ecr.aws/lambda/python:3.10.2025.01.15.17-arm64

ENTRYPOINT ["python", "-c", "\
import locale; \
print('Before setting locales:', locale.getlocale()); \
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8'); \
print('After setting to en_US.UTF-8:', locale.getlocale()); \
locale.setlocale(locale.LC_ALL, 'es_ES.UTF-8'); \
print('After setting to es_ES.UTF-8:', locale.getlocale())"]

Run in your terminal:

docker build -t test . && docker run --rm test

Note the output:

Before setting locales: ('en_US', 'UTF-8')
After setting to en_US.UTF-8: ('en_US', 'UTF-8')
After setting to es_ES.UTF-8: ('es_ES', 'UTF-8')

❌ Broken Condition:

Replicate the above but use a Python 3.12 image.
Either:

FROM public.ecr.aws/lambda/python:3.12.2025.01.24.11-x86_64

or

FROM public.ecr.aws/lambda/python:3.12.2025.01.24.11-arm64

Observe the error output stating the locale setting is unsupported.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/var/lang/lib/python3.12/locale.py", line 615, in setlocale
    return _setlocale(category, locale)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
locale.Error: unsupported locale setting
Before setting locales: ('C', 'UTF-8')

🩹 This can be addressed by modifying the Dockerfile so that your final Dockerfile looks like:

# these 3.12 images only work if I include the RUN and ENV lines below
FROM public.ecr.aws/lambda/python:3.12.2025.01.24.11-x86_64
# FROM public.ecr.aws/lambda/python:3.12.2025.01.24.11-arm64

RUN dnf install -y glibc-langpack-en glibc-langpack-es && dnf clean all

ENTRYPOINT ["python", "-c", "\
import locale; \
print('Before setting locales:', locale.getlocale()); \
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8'); \
print('After setting to en_US.UTF-8:', locale.getlocale()); \
locale.setlocale(locale.LC_ALL, 'es_ES.UTF-8'); \
print('After setting to es_ES.UTF-8:', locale.getlocale())"]

satisfactory output:

Before setting locales: ('en_US', 'UTF-8')
After setting to en_US.UTF-8: ('en_US', 'UTF-8')
After setting to es_ES.UTF-8: ('es_ES', 'UTF-8')

⚠️ Is there a known issue with locale configuration in the AWS Lambda Python 3.12 runtime images❓

@agosmou
Copy link
Author

agosmou commented Feb 7, 2025

probably also applied to 3.13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant