SAM "Unable to upload artifact ... no such file" in CI
sam package zips and uploads the code referenced by a CodeUri or content path. When that path does not exist on the runner (because the build step was skipped or the path is wrong), the upload fails with "no such file or directory".
What this error means
sam deploy or sam package fails with "Unable to upload artifact <path> referenced by CodeUri parameter ... no such file or directory" before reaching CloudFormation.
Error: Unable to upload artifact ./dist/handler referenced by CodeUri parameter
of FunctionResource resource. ./dist/handler: no such file or directoryCommon causes
The build output path does not exist
CodeUri points at a build directory (dist, .aws-sam/build) that the runner never produced because sam build or the compile step was skipped.
A wrong or relative CodeUri
The CodeUri is mistyped or relative to a different working directory than where the deploy runs, so the path resolves to nothing.
How to fix it
Build before deploying
- Run sam build so .aws-sam/build is populated.
- Deploy with the built template so artifacts exist.
- Confirm CodeUri matches the produced output path.
sam build
sam deploy --no-confirm-changesetCorrect the CodeUri path
Point CodeUri at the directory that actually contains the handler, relative to the template.
Resources:
FunctionResource:
Type: AWS::Serverless::Function
Properties:
CodeUri: dist/handler/
Handler: index.handlerHow to prevent it
- Always run sam build before sam deploy in CI.
- Keep CodeUri paths relative to the template, not the shell cwd.
- Verify the build output directory exists before packaging.