Repository navigation
Closed
Description
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
Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Type
Projects
- StatusShow more project fieldsTriage
Activity
michaelbrewer commentedon Mar 30, 2021
@byron70 Otherwise, is there a feature missing in the data for S3 Object?
byron70 commentedon Mar 30, 2021
Best I can tell everything else seems to be in order.
heitorlessa commentedon Mar 30, 2021
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 commentedon Apr 9, 2021
hey @byron70 this is now out as part of the 1.14.0 release