Skip to content
Latchkey

AWS SAM "Unable to upload artifact ... referenced by CodeUri" in CI

sam package uploads each function's code to S3 and rewrites CodeUri to the S3 location. The upload failed: the local artifact path does not exist, the bucket is missing, or the principal cannot write to it.

What this error means

sam deploy or sam package fails with "Unable to upload artifact <path> referenced by CodeUri parameter of <Function> resource." plus an S3 or filesystem error.

sam
Error: Unable to upload artifact .aws-sam/build/MyFunction referenced by CodeUri
parameter of MyFunction resource.
An error occurred (NoSuchBucket) when calling the PutObject operation: The specified
bucket does not exist

Common causes

sam build did not run before deploy

Deploy expects .aws-sam/build/...; without a prior sam build, the referenced artifact path does not exist.

The deployment S3 bucket is missing or inaccessible

A deleted or wrong --s3-bucket, or a principal without s3:PutObject, makes the upload fail.

How to fix it

Build before deploying

  1. Run sam build so artifacts exist under .aws-sam/build.
  2. Deploy with managed staging (--resolve-s3) or a valid bucket.
  3. Re-run; CodeUri now resolves to an uploadable path.
Terminal
sam build
sam deploy --resolve-s3 --no-confirm-changeset

Use managed deployment staging

Let sam create and manage the deployment bucket so a missing bucket cannot block the upload.

Terminal
sam deploy --resolve-s3 --stack-name my-app --capabilities CAPABILITY_IAM

How to prevent it

  • Always sam build before sam deploy in CI.
  • Prefer --resolve-s3 or sam deploy --guided managed buckets.
  • Grant the deploy principal write access to the staging bucket.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →