Skip to content

A CloudFormation-deployed AWS::Lambda::Function reports CodeSize: 0 #545

Closed

Description

@scttfrdmn

Against ghcr.io/scttfrdmn/substrate:0.88.0, a Lambda function created through
CloudFormation
reports CodeSize: 0 from get_function, where the identical code
created by a direct create_function call reports the true byte count. The function
is otherwise fine — invoke returns 200 and runs the handler — so only the metadata
is wrong.

Real Lambda reports the deployment package size regardless of how the function was
created.

Reproducer

import io, json, zipfile, boto3

kw = dict(endpoint_url="http://localhost:4566", region_name="us-east-1",
          aws_access_key_id="test", aws_secret_access_key="test")
s3, cfn, lam, iam = (boto3.client(s, **kw) for s in ("s3", "cloudformation", "lambda", "iam"))

buf = io.BytesIO()
with zipfile.ZipFile(buf, "w") as z:
    z.writestr("index.py", "def handler(event, context):\n    return {'ok': True}\n")
payload = buf.getvalue()
print("real zip size:", len(payload))          # 149 here

s3.create_bucket(Bucket="codesize-probe")
s3.put_object(Bucket="codesize-probe", Key="fn.zip", Body=payload)

role = iam.create_role(
    RoleName="codesize-probe-role",
    AssumeRolePolicyDocument=json.dumps({
        "Version": "2012-10-17",
        "Statement": [{"Effect": "Allow",
                       "Principal": {"Service": "lambda.amazonaws.com"},
                       "Action": "sts:AssumeRole"}],
    }),
)["Role"]["Arn"]

# --- via CloudFormation ---
cfn.create_stack(
    StackName="codesize-probe",
    TemplateBody=json.dumps({
        "Resources": {
            "Fn": {
                "Type": "AWS::Lambda::Function",
                "Properties": {
                    "FunctionName": "codesize-cfn",
                    "Runtime": "python3.12",
                    "Handler": "index.handler",
                    "Role": role,
                    "Code": {"S3Bucket": "codesize-probe", "S3Key": "fn.zip"},
                },
            }
        }
    }),
)
cfn.get_waiter("stack_create_complete").wait(StackName="codesize-probe")
print("cfn CodeSize:   ", lam.get_function(FunctionName="codesize-cfn")["Configuration"]["CodeSize"])
print("cfn invoke HTTP:", lam.invoke(FunctionName="codesize-cfn")["StatusCode"])

# --- via create_function, same bytes ---
lam.create_function(
    FunctionName="codesize-direct", Runtime="python3.12", Handler="index.handler",
    Role=role, Code={"ZipFile": payload},
)
print("direct CodeSize:", lam.get_function(FunctionName="codesize-direct")["Configuration"]["CodeSize"])

Observed:

real zip size: 149
cfn CodeSize:    0
cfn invoke HTTP: 200
direct CodeSize: 149

So the Code.S3Bucket/S3Key path evidently fetches and stores the object — the
function runs — but does not carry the size onto the function configuration the way
the direct path does.

Context

Low severity, and no downstream workaround is needed: the affected assertion in
parsl-ephemeral-provider was
better off written another way regardless. It guards
#116, whose actual
symptom was an unparseable DescribeStacks parameter echo — a zip decoded as latin1
into 117 XML-illegal control codepoints — so the guard belongs on the parameter echo
round-tripping, not on a size. CodeSize: 0 merely ruled out the size check while
that was being decided.

Filing it because it is a wrong value returned with a success status, which is the
shape of thing worth knowing about before someone relies on it. Found while moving
that project's integration suite off moto (parsl-ephemeral-provider#183).

Activity

  1. added
    type: bug
    priority: low
    on Aug 3, 2026
  2. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Reproduced, but the premise is confounded — measured against v0.89.0 before planning.
    The axis is not CFN vs. direct create_function; it is inline ZipFile vs. an
    S3 source
    . Both paths report 0 for an S3-sourced function:

    path code source CodeSize
    direct create_function --zip-file fileb:// 156 (correct)
    direct create_function S3Bucket/S3Key 0
    CFN AWS::Lambda::Function Code.S3Bucket/S3Key 0
    CFN AWS::Lambda::Function Code.ZipFile (inline) 0

    So there are two independent gaps, and this issue as filed describes only where they overlap:

    1. deployLambdaFunction never forwards Code at all (emulator/cfn_deployer.go:2641-2705).
      The body it builds carries FunctionName, Runtime, Role, Handler, Description,
      Timeout, MemorySize — and no Code key. That is why the CFN inline-ZipFile row is
      also 0, which the report did not test: substrate has the bytes in the template and
      discards them. CodeSha256 is empty on this path for the same reason, and
      PackageType: Image / Code.ImageUri is dropped too.
    2. The S3-source branch records no size (emulator/lambda_plugin.go:299, :385).
      createFunction initialises CodeSize: 0 and only sets it in the ZipFile branch
      (:315); updateFunctionCode's S3Bucket branch (:385) logs "S3 source not
      fetched"
      and sets ZipStored = false without a size. Substrate can know the size
      here — the object is usually in its own S3 plugin, as it was in this reproducer — so a
      HeadObject-equivalent state read gives the true byte count.

    Both are worth fixing, and (1) is the larger one: it means a CFN-deployed function reports
    no code identity whatsoever, which also makes UpdateFunctionCode drift undetectable. I'm
    keeping the severity as filed for the reported symptom, and treating (1) as the substantive
    fix.

  3. added this to the v0.90.0 milestone on Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: lambdafidelitypriority: lowtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions