Repository navigation
Description
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
scttfrdmn commentedon Aug 3, 2026
Reproduced, but the premise is confounded — measured against
v0.89.0before planning.The axis is not CFN vs. direct
create_function; it is inlineZipFilevs. anS3 source. Both paths report
0for an S3-sourced function:CodeSizecreate_function--zip-file fileb://create_functionS3Bucket/S3KeyAWS::Lambda::FunctionCode.S3Bucket/S3KeyAWS::Lambda::FunctionCode.ZipFile(inline)So there are two independent gaps, and this issue as filed describes only where they overlap:
deployLambdaFunctionnever forwardsCodeat all (emulator/cfn_deployer.go:2641-2705).The body it builds carries
FunctionName,Runtime,Role,Handler,Description,Timeout,MemorySize— and noCodekey. That is why the CFN inline-ZipFilerow isalso
0, which the report did not test: substrate has the bytes in the template anddiscards them.
CodeSha256is empty on this path for the same reason, andPackageType: Image/Code.ImageUriis dropped too.emulator/lambda_plugin.go:299,:385).createFunctioninitialisesCodeSize: 0and only sets it in theZipFilebranch(
:315);updateFunctionCode'sS3Bucketbranch (:385) logs "S3 source notfetched" and sets
ZipStored = falsewithout a size. Substrate can know the sizehere — 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
UpdateFunctionCodedrift undetectable. I'mkeeping the severity as filed for the reported symptom, and treating (1) as the substantive
fix.
fix(lambda): report the size and digest of the deployed package (#545) (