Feature request: sam build/deploy should zip and upload local CodeUri for AWS::Serverless::MicrovmImage, like it does for Function
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 buildzips the local directory (respecting.samignore/exclude patterns like Function build does).sam package/sam deployuploads the zip to the resolved S3 bucket (via--resolve-s3or an explicit--s3-bucket) and rewritesCodeUrito 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
MicrovmImagehas 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:
- 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, onlysam build/sam packageneed to recognize a local path for this resource type and handle it the way they already do for Function. - This directly unblocks a related bootstrap problem: today, any template where
MicrovmImage.CodeUrineeds 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/invalidCodeUri) 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. - Precedent: #6909 requested similar local-file handling for
Function.ImageUri(container images) — this request is the equivalent gap forMicrovmImage.CodeUrispecifically.
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
Source: aws/aws-sam-cli