Skip to content

Bug: S3Object.closed is False after close() for gzip, and makes S3 calls for zip #8564

Closed

Description

@ArfiArfath21

Expected Behaviour

After S3Object.close(), S3Object.closed is True. Checking closed does not do any work against S3.

Current Behaviour

S3Object.closed is implemented as self.transformed_stream.closed, and transformed_stream is created lazily. That has two side effects:

  1. For an object that was never read, close() only closes the raw stream. A later .closed then builds the transformed stream on top of the already closed raw stream. With is_gzip=True it returns False for an object that was just closed.
  2. With a transformation that reads on creation, checking .closed issues S3 requests. ZipTransform reads the archive's central directory, so .closed calls HeadObject and GetObject.

Code snippet

import boto3
from aws_lambda_powertools.utilities.streaming import S3Object

client = boto3.client("s3", region_name="us-east-1", aws_access_key_id="x", aws_secret_access_key="x")

obj = S3Object("bucket", "key", boto3_client=client, is_gzip=True)
obj.close()
print(obj.closed)  # False, expected True

For the zip case, use a botocore Stubber with no queued responses: obj.transform(ZipTransform(), in_place=True); obj.closed raises UnStubbedResponseError for HeadObject.

Possible Solution

When the transformed stream has not been created yet, answer from the raw stream (self.raw_stream.closed) instead of creating it. I have a small fix with tests ready.

Steps to Reproduce

Run the snippet above.

Powertools for AWS Lambda (Python) version

develop (1d4f145, 3.36.0)

AWS Lambda function runtime

3.12

Packaging format used

PyPi


Disclosure: I found this while reviewing the streaming utility with the help of an AI assistant (Claude Code). I ran the snippets above myself against develop.

Activity

  1. boring-cyborg commented on Oct 16, 2026

    @boring-cyborg

    Thanks for opening your first issue here! We'll come back to you as soon as we can.
    In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

  2. powertools-for-aws-oss-automation commented on Oct 16, 2026

    @powertools-for-aws-oss-automation

    Warning

    This issue is now closed. Please be mindful that future comments are hard for our team to see.
    If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  3. github-actions commented on Oct 22, 2026

    @github-actions
    Contributor

    This is now released under 3.37.0 version!

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

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions