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 existCommon 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
- Run
sam buildso artifacts exist under.aws-sam/build. - Deploy with managed staging (
--resolve-s3) or a valid bucket. - Re-run; CodeUri now resolves to an uploadable path.
Terminal
sam build
sam deploy --resolve-s3 --no-confirm-changesetUse 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_IAMHow to prevent it
- Always
sam buildbeforesam deployin CI. - Prefer
--resolve-s3orsam deploy --guidedmanaged buckets. - Grant the deploy principal write access to the staging bucket.
Related guides
AWS SAM "Build Failed" from sam build in CIFix AWS SAM "Build Failed" from sam build in CI - a function build (a runtime build image, a dependency insta…
AWS SAM "Requires capabilities : [CAPABILITY_IAM]" in CIFix AWS SAM "Requires capabilities : [CAPABILITY_IAM]" (or CAPABILITY_NAMED_IAM/CAPABILITY_AUTO_EXPAND) in CI…
AWS SAM "is in ROLLBACK_COMPLETE state ... cannot be updated" in CIFix AWS SAM deploys that fail because the stack "is in ROLLBACK_COMPLETE state and cannot be updated" in CI -…