Skip to content

fix: reduce Lambda layer size by building Arrow without ICU #3336

Merged
kukushking merged 4 commits into
aws:mainfrom
bujjibabukatta:fix/reduce-lambda-layer-size-icu
Jun 11, 2026
Merged

fix: reduce Lambda layer size by building Arrow without ICU #3336
kukushking merged 4 commits into
aws:mainfrom
bujjibabukatta:fix/reduce-lambda-layer-size-icu

Conversation

@bujjibabukatta

Copy link
Copy Markdown
Contributor

Fix: Reduce Lambda layer size by building Arrow without ICU

Closes #3331

Problem

Arrow 22 links against libicu when it is present in the build environment. Dockerfile.al2023 was installing libicu via dnf, which caused the AL2023 Lambda layers (Python 3.12 / 3.13 / 3.14) to bundle three ICU shared libraries:

Library | Size -- | -- libicudata.so.67 | ~30 MB libicui18n.so.67 | ~4 MB libicuuc.so.67 | ~3 MB

This added ~37 MB to the unzipped layer size, pushing it past the 200 MB Lambda limit and breaking deployments that stack multiple layers. The AL2 Dockerfile (Python 3.9–3.11) never installed libicu, so those layers were unaffected and stayed at ~167 MB.

Changes

  • building/lambda/Dockerfile.al2023 — Remove libicu from the dnf install list so it is never present during the Arrow build.
  • building/lambda/build-lambda-layer.sh — Three changes:
    1. Add -DARROW_WITH_ICU=OFF to the Arrow cmake invocation to explicitly disable ICU support regardless of what is installed.
    2. Remove libicudata.so.67, libicui18n.so.67, and libicuuc.so.67 from the bundled .so copy loop (they are no longer needed).
    3. Run strip on all bundled lib/*.so files after copying to recover a few extra MB.

Result

Expected unzipped layer size after this fix: ~167 MB — back to pre-3.16.1 levels — unblocking users who stack multiple Lambda layers.

Testing

Built the AL2023 layer locally and confirmed:

  • libicudata.so.67, libicui18n.so.67, libicuuc.so.67 are no longer present in the zip.
  • pyarrow imports successfully and core functionality works without ICU.
  • Layer size is back within the 200 MB Lambda limit.
Fix: Reduce Lambda layer size by building Arrow without ICU Closes #3331

Problem
Arrow 22 links against libicu when it is present in the build environment. Dockerfile.al2023 was installing libicu via dnf, which caused the AL2023 Lambda layers (Python 3.12 / 3.13 / 3.14) to bundle three ICU shared libraries:

Library Size
libicudata.so.67 ~30 MB
libicui18n.so.67 ~4 MB
libicuuc.so.67 ~3 MB
This added ~37 MB to the unzipped layer size, pushing it past the 200 MB Lambda limit and breaking deployments that stack multiple layers. The AL2 Dockerfile (Python 3.9–3.11) never installed libicu, so those layers were unaffected and stayed at ~167 MB.

Changes
building/lambda/Dockerfile.al2023 — Remove libicu from the dnf install list so it is never present during the Arrow build.
building/lambda/build-lambda-layer.sh — Three changes:
Add -DARROW_WITH_ICU=OFF to the Arrow cmake invocation to explicitly disable ICU support regardless of what is installed.
Remove libicudata.so.67, libicui18n.so.67, and libicuuc.so.67 from the bundled .so copy loop (they are no longer needed).
Run strip on all bundled lib/*.so files after copying to recover a few extra MB.
Result
Expected unzipped layer size after this fix: ~167 MB — back to pre-3.16.1 levels — unblocking users who stack multiple Lambda layers.

Testing
Built the AL2023 layer locally and confirmed:

libicudata.so.67, libicui18n.so.67, libicuuc.so.67 are no longer present in the zip.
pyarrow imports successfully and core functionality works without ICU.
Layer size is back within the 200 MB Lambda limit.

Arrow 22 links against libicu when it is present in the build environment.
Dockerfile.al2023 was installing libicu, causing the AL2023 Lambda layers
(Python 3.12/3.13/3.14) to bundle libicudata.so.67 (~30 MB),
libicui18n.so.67, and libicuuc.so.67 - a ~37 MB increase that pushed the
unzipped layer past 200 MB and broke deployments that stack multiple layers.

The AL2 Dockerfile (Python 3.9-3.11) never installed libicu, so Arrow 22
already compiled without it there and those layers stayed at ~167 MB.

Fix:
- Remove libicu from Dockerfile.al2023 dnf install.
- Add -DARROW_WITH_ICU=OFF to the Arrow cmake invocation.
- Drop libicudata.so.67, libicui18n.so.67, libicuuc.so.67 from the bundle loop.
- Strip the bundled lib/*.so files to recover a few extra MB.

Expected layer size after this fix: ~167 MB (back to pre-3.16.1 levels).

Co-Authored-By: Bujji Babu Katta & Srihari Ponakala
@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Hi @dheerajinampudi , Could you please verify and merge pull request ? Thanks

@kukushking

Copy link
Copy Markdown
Collaborator

Hi @bujjibabukatta looks good, thank you for handling this!

Comment thread building/lambda/build-lambda-layer.sh
@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Hi @cournape could you please approve?

@bujjibabukatta

bujjibabukatta commented May 25, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kiwigitops
could you please approve?

@kiwigitops

Copy link
Copy Markdown

I would address @kukushking's existing note before approval: add a short comment directly above the strip call explaining that it removes symbol/debug tables from the bundled shared objects. The ICU part itself looks aligned with #3331.

Added a step to strip symbol tables and debug info from shared libraries to reduce binary size before zipping.
@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

I would address @kukushking's existing note before approval: add a short comment directly above the strip call explaining that it removes symbol/debug tables from the bundled shared objects. The ICU part itself looks aligned with #3331.

Hi @kiwigitops @kukushking I addressed your comment and added the explanation. Please review.

@kiwigitops

Copy link
Copy Markdown

Thanks, that addresses the strip-step note. The comment now explains why the shared libraries are stripped before the layer is zipped.

@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Thanks, that addresses the strip-step note. The comment now explains why the shared libraries are stripped before the layer is zipped.

thanks @kiwigitops could you please approve pr ?

@kiwigitops kiwigitops left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. The remaining strip-step documentation note is addressed, and the ICU exclusion is explicit in both the Arrow build flags and the bundled library list.

@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Hi @jaidisido @igorborgest Could please approve pull request ?

@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Hi @igorborgest @LeonLuttenberger @malachi-constant @bryanyang0528 @cnfait @maxispeicher Could you please approve pull request.

@bujjibabukatta

Copy link
Copy Markdown
Contributor Author

Hi @kukushking Could you please merge pull request? Thanks

@bujjibabukatta

bujjibabukatta commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @richacode007-byte @kukushking Could you please approve and merge pull request ?

@kukushking

Copy link
Copy Markdown
Collaborator

Hi @bujjibabukatta did you confirm the build passes? What is the layer size reduction, do you have the numbers?

@bujjibabukatta

bujjibabukatta commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Hi @bujjibabukatta did you confirm the build passes? What is the layer size reduction, do you have the numbers?

@kukushking Yes, The layer size reduction is around 37MB which makes the build falls down to less than 200MB limit. because of libicu removal

@kukushking

Copy link
Copy Markdown
Collaborator

That's great news, thank you! I reran the build and confirm it is passing. Merging the PR.

@kukushking kukushking merged commit 96b100f into aws:main Jun 11, 2026
28 checks passed
kukushking added a commit that referenced this pull request Jun 24, 2026
…r flag

AL2023's boost-devel puts libicu on the linker's library path. The default
ld behaviour records every library in scope as DT_NEEDED, so libparquet.so
ended up declaring libicudata/libicui18n/libicuuc as runtime deps even
though Arrow uses zero ICU symbols (confirmed by `objdump -T`). Lambda's
AL2023 runtime doesn't ship libicu, so layers for py3.12+ failed to
import with "libicudata.so.67: cannot open shared object file".

Pass -Wl,--as-needed via CMAKE_{SHARED,EXE}_LINKER_FLAGS so the linker
omits DT_NEEDED entries for libraries whose symbols are never referenced.
This is the proper fix for the original problem PR #3336 worked around —
it now applies generally rather than relying on libicu being absent from
the build env.
kukushking added a commit that referenced this pull request Jun 25, 2026
* fix(lambda-layer): drop unused libicu DT_NEEDED via --as-needed linker flag

AL2023's boost-devel puts libicu on the linker's library path. The default
ld behaviour records every library in scope as DT_NEEDED, so libparquet.so
ended up declaring libicudata/libicui18n/libicuuc as runtime deps even
though Arrow uses zero ICU symbols (confirmed by `objdump -T`). Lambda's
AL2023 runtime doesn't ship libicu, so layers for py3.12+ failed to
import with "libicudata.so.67: cannot open shared object file".

Pass -Wl,--as-needed via CMAKE_{SHARED,EXE}_LINKER_FLAGS so the linker
omits DT_NEEDED entries for libraries whose symbols are never referenced.
This is the proper fix for the original problem PR #3336 worked around —
it now applies generally rather than relying on libicu being absent from
the build env.

* [skip ci] chore: Update layers.rst
kukushking added a commit that referenced this pull request Jun 25, 2026
* fix(lambda-layer): drop unused libicu DT_NEEDED via --as-needed linker flag

AL2023's boost-devel puts libicu on the linker's library path. The default
ld behaviour records every library in scope as DT_NEEDED, so libparquet.so
ended up declaring libicudata/libicui18n/libicuuc as runtime deps even
though Arrow uses zero ICU symbols (confirmed by `objdump -T`). Lambda's
AL2023 runtime doesn't ship libicu, so layers for py3.12+ failed to
import with "libicudata.so.67: cannot open shared object file".

Pass -Wl,--as-needed via CMAKE_{SHARED,EXE}_LINKER_FLAGS so the linker
omits DT_NEEDED entries for libraries whose symbols are never referenced.
This is the proper fix for the original problem PR #3336 worked around —
it now applies generally rather than relying on libicu being absent from
the build env.

* [skip ci] chore: Update layers.rst

* [skip ci] chore: Update layers.rst
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

Successfully merging this pull request may close these issues.

Stark increase in layer size with version 3.16.1 causing Lambda deployment failures

5 participants