Skip to content
Latchkey

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.

sam
Error: Unable to upload artifact ./dist/handler referenced by CodeUri parameter
of FunctionResource resource. ./dist/handler: no such file or directory

Common 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

  1. Run sam build so .aws-sam/build is populated.
  2. Deploy with the built template so artifacts exist.
  3. Confirm CodeUri matches the produced output path.
Terminal
sam build
sam deploy --no-confirm-changeset

Correct the CodeUri path

Point CodeUri at the directory that actually contains the handler, relative to the template.

template.yaml
Resources:
  FunctionResource:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: dist/handler/
      Handler: index.handler

How 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.

Frequently asked questions

What causes ""Unable to upload artifact""?
CodeUri points at a build directory (dist, .aws-sam/build) that the runner never produced because sam build or the compile step was skipped.
How do I fix "Unable to upload artifact"?
Build before deploying

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card