You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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 AWS::Serverless::MicrovmImage.CodeUri has no default and no local-file support, making a required-parameter bootstrap deploy impossible serverless-application-model#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.
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.
Describe your idea/feature/enhancement
I wish
sam build/sam deploywould accept a local directory path forAWS::Serverless::MicrovmImage.CodeUri, zip it, and upload it to SAM's managed S3 bucket automatically — the same local-file handlingsamalready provides forAWS::Serverless::Function.CodeUri.Today
MicrovmImage.CodeUrionly 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 usess3://...directly).sam buildpasses a local path straight through unchanged instead of zipping/uploading it — there's no equivalent of the local-file auto-upload SAM already does forFunction.Proposal
Extend the same local-file handling
sam build/sam package/sam deployalready use forFunction.CodeUrito also coverMicrovmImage.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.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:
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.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 AWS::Serverless::MicrovmImage.CodeUri has no default and no local-file support, making a required-parameter bootstrap deploy impossible serverless-application-model#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.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 aroundsam buildnot 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