aws / aws/aws-lambda-base-images

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

Open
#229 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
777
Forks
118
PR merge metrics
No merged PRs in 30d

Description

### 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:
```Dockerfile
# 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:
```bash
docker build -t test . && docker run --rm test
```

Note the output:
```bash
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:
```bash
FROM public.ecr.aws/lambda/python:3.12.2025.01.24.11-x86_64
```
or
```bash
FROM public.ecr.aws/lambda/python:3.12.2025.01.24.11-arm64
```

Observe the error output stating the locale setting is unsupported.

```bash
Traceback (most recent call last):
File "", line 1, in
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:

```Dockerfile
# 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:
```bash
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❓

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.