Skip to content

parser.models.S3Object should allow size of >= 0 #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
byron70 opened this issue Mar 29, 2021 · 4 comments
Closed

parser.models.S3Object should allow size of >= 0 #372

byron70 opened this issue Mar 29, 2021 · 4 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@byron70
Copy link

byron70 commented Mar 29, 2021

Attempting to parse a S3 PUT event in an AWS Lambda where the S3 object size is 0 bytes, yields a pydantic.error_wrappers.ValidationError indicating size must be greater than 0.

Expected Behavior

Since 0 byte objects in S3 are allowed, it is expected these types of S3 events would be validated without issue when parsing the Lambda event.

Current Behavior

Receiving the following error attempting to parse a 0 byte S3 PUT event.

parse(event=event, model=models.S3Model, envelope=envelopes.SnsSqsEnvelope)

pydantic.error_wrappers.ValidationError: 1 validation error for S3Model
Records -> 0 -> s3 -> object -> size
  ensure this value is greater than 0 (type=value_error.number.not_gt; limit_value=0)

Possible Solution

Change S3Object to the following:

class S3Object(BaseModel):
    key: str
    size: NonNegativeInt
    eTag: str
    sequencer: str
    versionId: Optional[str]

Steps to Reproduce (for bugs)

from aws_lambda_powertools.utilities.parser import parse, models, envelopes

event = {
    "Records": [
        {
            "eventVersion": "2.1",
            "eventSource": "aws:s3",
            "awsRegion": "us-east-2",
            "eventTime": "2021-03-25T22:41:47.873Z",
            "eventName": "ObjectCreated:Put",
            "userIdentity": {"principalId": "AWS:ARODJFUCGRB5ZBMY74FY:foo.bar"},
            "requestParameters": {"sourceIPAddress": "127.0.0.1"},
            "responseElements": {
                "x-amz-request-id": "foo",
                "x-amz-id-2": "foo",
            },
            "s3": {
                "s3SchemaVersion": "1.0",
                "configurationId": "tf-s3-topic-cur",
                "bucket": {
                    "name": "bucket",
                    "ownerIdentity": {"principalId": "ME"},
                    "arn": "arn:aws:s3:::bucket",
                },
                "object": {
                    "key": "reports/test/test.json",
                    "size": 0,
                    "eTag": "foo",
                    "versionId": "foo",
                    "sequencer": "foo",
                },
            },
        }
    ]
}
parse(event=event, model=models.S3Model)

Environment

aws-lambda-powertools==1.13.0
python 3.8

@byron70 byron70 added bug Something isn't working triage Pending triage from maintainers labels Mar 29, 2021
@michaelbrewer
Copy link
Contributor

@byron70
Copy link
Author

byron70 commented Mar 30, 2021

@byron70 Otherwise, is there a feature missing in the data for S3 Object?

Best I can tell everything else seems to be in order.

@heitorlessa heitorlessa added this to the 1.14.0 milestone Mar 30, 2021
@heitorlessa
Copy link
Contributor

Fix is in - @byron70 could you double check in case I've missed anything obvious? Had to upgrade Pydantic to 1.8 as this new type was introduced too.

#375

Once merged, this will make to the next release hopefully mid next week

@heitorlessa heitorlessa self-assigned this Mar 30, 2021
@heitorlessa heitorlessa removed the triage Pending triage from maintainers label Mar 30, 2021
@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Apr 7, 2021
@heitorlessa
Copy link
Contributor

hey @byron70 this is now out as part of the 1.14.0 release

@heitorlessa heitorlessa removed the pending-release Fix or implementation already in dev waiting to be released label Jul 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

No branches or pull requests

3 participants