Repository navigation
fix(aws-python-flask-dynamodb-api): use python3.15, keep local environments out of the package and package arm64 wheels - #844
Merged
Conversation
…nts packaging Drop the virtual environment from Prerequisites: the built-in packaging runs python3.14 itself, and a venv in the service directory is packaged into the function. Create it in Run it locally instead, and leave it, the local DynamoDB files and __pycache__ out of the package with package.patterns.
…the package, use python3.15 Approved changes to this onboarding example: - serverless.yml excludes venv/, .dynamodb/ and __pycache__/ from the package, so a local virtual environment or local DynamoDB never reaches the deployed function; the README now points to that section instead of asking readers to add it. - Pin serverless-wsgi to 3.1.0. - Use the python3.15 runtime.
…explain the npm install-script warning
… machine The function runs on arm64, but pip installed wheels for the machine that packaged it, so a deploy from an x86_64 host bundled an x86_64 build of MarkupSafe's compiled module. Pass pip the Linux aarch64 platform tags, the runtime's Python version and --only-binary=:all: through custom.pythonRequirements.pipCmdExtraArgs, and explain the setting in the README.
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lesson
aws-python-flask-dynamodb-apiteaches a Flask API on Lambda that stores users in DynamoDB. Its dependencies are packaged by the Framework's built-in Python requirements packaging (custom.pythonRequirements), with noserverless-python-requirementsplugin.serverless.ymlandpackage.jsonalready made that switch onv4in #827; this pull request brings the README in line with it, keeps local environments out of the package, moves the example to thepython3.15runtime, packages Linux arm64 wheels on any machine, and adds the proof.Left out: everything the example didn't already teach.
requirements.txtandapp.pyare unchanged.Changes
Onboarding example. Files touched:
README.md,serverless.ymlandpackage.json.serverless.ymlhas a top-levelpackage.patternsthat leaves outvenv/,.dynamodb/(whatserverless dynamodb installdownloads) and__pycache__/, so a reader who follows Run it locally never deploys their local environment. With those directories present,serverless packagebuilt a 200-file, 2.3 MB (unzipped) package with none of them in it; without the patterns, the same steps had built a 165 MB zip.serverless.ymluses thepython3.15runtime (Framework CLI 4.47.0 accepts it without a configuration warning; it deployed and served requests).package.jsonpinsserverless-wsgito3.1.0.npm audit: 0 vulnerabilities.serverless.ymlpassescustom.pythonRequirements.pipCmdExtraArgs(--platform=manylinux2014_aarch64,--platform=manylinux_2_28_aarch64,--python-version=3.15,'--only-binary=:all:'), with a comment saying why, as Linux wheels without Docker describes. The function runs onarm64, and pip otherwise installs wheels for the machine that packages it: packaged on an x86_64 host, the zip heldmarkupsafe/_speedups.cpython-315-x86_64-linux-gnu.so, which the function can't load (MarkupSafe then uses its pure-Python code). The Framework adds--targetitself, and pip's--implementationdefaults to CPython, the interpreter that runs it, so neither is set.pipitself, and avenv/there used to be packaged into the function (a 65 MB package, of which 64 MB wasvenv/).pipCmdExtraArgsblock, and namedockerizePipfor a dependency that publishes no such wheel.python3.15and says that thepackagesection ofserverless.ymlkeeps it and.dynamodb/out of the package, linking to Keep local environments out of the package.Test plan
Framework CLI 4.47.0,
us-east-1.node scripts/check-examples.mjs aws-python-flask-dynamodb-apiclean;npm test323 passed;npm run validateclean;npm run docsandnpm run check-docsclean (after merging the currentv4).serverless package): before the change, the one compiled file wasmarkupsafe/_speedups.cpython-315-x86_64-linux-gnu.so. After it, the one compiled file ismarkupsafe/_speedups.cpython-315-aarch64-linux-gnu.so(file: ELF 64-bit LSB shared object, ARM aarch64), MarkupSafe's wheel tag iscp315-cp315-manylinux2014_aarch64, every other package ispy3-none-any, and no file name in the zip containsx86_64.serverless wsgi execimportedmarkupsafe._speedupsfrom/var/task/markupsafe/_speedups.cpython-315-aarch64-linux-gnu.sowithplatform.machine()=aarch64.exqs3ee456k;Using Python specified in "runtime": python3.15;created and read back user smoke-exqs3ee456k-…; package 660 kB)checkstep,FAIL zz-neg-flask 4.47.0 117s(stageexnn9bl6qe6).flkarm1125): Deploy printed the README's lines and the 660 kB package; both Try it requests returned{"name":"John","userId":"someUserId"}with status 200, and an unknown id answered 404 with the README's error. The function's configuration readsarm64,python3.15.users-table-devand served the same responses onlocalhost:5000.faeu842), ran both Try it requests and the unknown-id request, and removed it. It reported no step where it had to guess or look anything up. Deploy printed the README's lines and the 660 kB package (67 s); all three responses matched the README exactly;serverless removesucceeded anddescribe-stacksthen reported that the stack does not exist. The only extra output was a Node.jsDEP0169(url.parse()) deprecation warning on Node.js 26.aws cloudformation list-stacksshows noaws-python-flask-dynamodb-apistack outsideDELETE_COMPLETE,aws logs describe-log-groups --log-group-name-prefix /aws/lambda/aws-python-flask-dynamodb-apireturns 0 groups, and nousers-table-*table remains.Generated by Claude Code