Binary file corrupted when uploaded into Lambda console code editor
- Dominant language
- TypeScript
- Stars
- 2k
- Forks
- 807
- Avg merge
- 10h 12m
- Merged PRs (30d)
- 7
Description
## Problem
When I click-and-drag an image file into the code editor in the AWS Lambda console page, the file is corrupted, and made larger.
## Where to report?
Is this the right place to report this issue?
I'm talking about this editor:
## Steps to reproduce the issue
1. Find a png file. Here's mine (just a random screenshot.)
3. On your laptop, run the following Python script to check the size of the file.
```
PATH="image.png"
def lambda_handler(event, context):
with open(PATH, "rb") as f:
data_length = len(f.read())
print(f"{PATH} is {data_length} bytes")
return data_length
if __name__ == "__main__":
lambda_handler(None, None)
```
Also run `ls -l` to see how many bytes the OS thinks the file is.
3. In the AWS console, create a new lambda. (Python 3.14, x86, "Author from scratch")
4. In the console's page for that function, in the code editor copy-paste the same script as `lambda_function.py`
5. In the code editor, click and drag your image from your laptop's file browser, into the file list in the code editor.
6. Deploy the function
7. Invoke the function (any event payload will do, because the event isn't used by the script.
## Expected behavior
The Lambda reports that the image file size is the same as when the same script is run
## Actual Behavior
When run locally, the script says the file is 32707 bytes, as does `ls`.
```
matthew@zenbook:~/Downloads/binary-corrupt$ python3 check-file.py
image.png is 32707 bytes
matthew@zenbook:~/Downloads/binary-corrupt$ ls -l
total 36
-rw-rw-r-- 1 matthew matthew 248 févr. 27 20:33 check-file.py
-rw-rw-r-- 1 matthew matthew 32707 févr. 27 20:30 image.png
```
But the Lambda says the image is 59252 bytes long.
Lambda: 59252 bytes
Correct: 32707
Somehow the file has been corrupted when uploaded into the lambda.
I first noticed this when playing around with a Lambda Function URL, wondering why the image returned could not be displayed in a browser. It took me a long time to realise that it's not related to the Function URL at all. If I reproduce these steps with SAM, it returns 32707, the same as the true value. I'm just using file size as a quick fingerprint to show that the file has been modified. You could do a SHA256. Note that when I did `tail` and `head` of the byte array returned by the Lambda via a Function URL, they looked the same, which is odd. So it's not like something has gone wrong with forgetting to base64 decode, gzip/gunzip etc.
Note also that the code editor is unable to display the image. Given the error message's phrasing, I expect that it should be able to display a valid image, which also demonstrates that the image file is no longer valid.
## System details (run `AWS: About` and/or `Amazon Q: About`)
I'm running Firefox 174.0.4 on
- OS: Ubuntu 24.04.4
- Visual Studio Code version: I don't have Visual Studio Code installed on my laptop. This is whatever is in the Lambda console, which used to be Cloud9, but now appears to be some web version of Visual Studio code.
- AWS Toolkit version: Not applicable
- Amazon Q version: Not applicable
Contributor guide
Research direction
The report names no files, tests, or repository entry points; first confirm whether the AWS Lambda console editor is implemented in this repository and reproduce the drag-and-drop upload with the provided PNG and Python size check. Done means the issue is routed to the owning project or the editor preserves the uploaded binary bytes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws
- Domain
- cloud
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100