Feature request: sam build/deploy should zip and upload local CodeUri for AWS::Serverless::MicrovmImage, like it does for Function

Author: singledigitCreated Sep 21, 2026Updated Sep 21, 2026

Describe your idea/feature/enhancement

I wish sam build/sam deploy would accept a local directory path for AWS::Serverless::MicrovmImage.CodeUri, zip it, and upload it to SAM's managed S3 bucket automatically — the same local-file handling sam already provides for AWS::Serverless::Function.CodeUri.

Today MicrovmImage.CodeUri only accepts an S3 URI (per the SAM Spec docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-microvmimage.html — Required: Yes, described as "The Amazon S3 URI of the zip artifact", every example uses s3://... directly). sam build passes a local path straight through unchanged instead of zipping/uploading it — there's no equivalent of the local-file auto-upload SAM already does for Function.

Proposal

Extend the same local-file handling sam build/sam package/sam deploy already use for Function.CodeUri to also cover MicrovmImage.CodeUri:

  • sam build zips the local directory (respecting .samignore/exclude patterns like Function build does).
  • sam package/sam deploy uploads the zip to the resolved S3 bucket (via --resolve-s3 or an explicit --s3-bucket) and rewrites CodeUri to the resulting S3 URI in the transformed template, exactly like it does today for Functions.
  • Ideally, content-hash the uploaded key the same way Function artifacts are hashed, so CloudFormation reliably detects real code changes (right now, anyone hand-rolling their own S3 upload for MicrovmImage has to replicate this themselves to avoid uploading to a fixed key that never changes — CloudFormation only diffs property values, so a stable key silently no-ops rebuilds on a real code change unless the key itself changes).

Things to consider:

  1. Will this require any updates to the SAM Spec (https://github.com/aws/serverless-application-model)? Likely not much beyond documentation — CodeUri's type/shape doesn't need to change, only sam build/sam package need to recognize a local path for this resource type and handle it the way they already do for Function.
  2. This directly unblocks a related bootstrap problem: today, any template where MicrovmImage.CodeUri needs a value from the same stack's own outputs (e.g. the artifact needs an id baked in from a resource this stack creates) can't be deployed at all on a fresh account — there's no existing S3 object to reference on a first-ever deploy, and CloudFormation validates the changeset (rejecting the missing/invalid CodeUri) before creating anything, including any bucket. I filed the underlying resource-behavior side of that as https://github.com/aws/serverless-application-model/issues/3995 — this CLI-side local-file support would make that whole class of problem go away for most users, the same way it already doesn't come up for Function.
  3. Precedent: #6909 requested similar local-file handling for Function.ImageUri (container images) — this request is the equivalent gap for MicrovmImage.CodeUri specifically.

Additional Details

Hit this building a public sample project (https://github.com/singledigit/microvm-dev-environment) that uses AWS::Serverless::MicrovmImage. We ended up hand-rolling exactly the zip+hash+upload logic this request describes inside our own deploy script, purely to work around sam build not doing it for us. Happy to share that script as a reference for the expected behavior if useful.

sam --version: SAM CLI, version 1.161.0