question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: S3Model not compatible with ObjectRemoved events

See original GitHub issue

Expected Behaviour

After deleting an object from S3, if a Lambda catches this event, they should be able to parse it. This event name from S3 is ObjectDeleted:*.

Current Behaviour

A ValidationError is thrown because of the missing size and eTag attributes.

Records -> 0 -> s3 -> object -> size
  field required (type=value_error.missing)
Records -> 0 -> s3 -> object -> eTag
  field required (type=value_error.missing)

The ObjectDeleted event does not include those attributes.

Code snippet

parse(model=S3Model, event=json.loads(s3_message))

Payload Example: https://github.com/awslabs/aws-lambda-powertools-python/issues/1637#issuecomment-1288170059

Possible Solution

Update S3Object so that both size and eTag are optional:

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

Steps to Reproduce

  1. Create a Lambda function and an S3 bucket
  2. Trigger the Lambda function through S3 events, and enable the ObjectDeleted type
  3. Delete an object from S3
  4. S3Model will raise a ValidationError

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.8

Packaging format used

PyPi

Debugging logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:20 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
barreeeiroocommented, Oct 23, 2022

@heitorlessa done, the PR should be available now: PR#1638. I couldn’t really test the change right now, but if strictly needed I can fully test it tomorrow.

1reaction
ran-isenbergcommented, Oct 23, 2022

@barreeeiroo yeah that makes sense! nice one. I’ll open a PR with tests in a few min.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve “Configuration is ambiguously defined” error ... - AWS
I'm trying to create an Amazon Simple Storage Service (Amazon S3) bucket event notification to trigger my AWS Lambda function.
Read more >
[S3] Support Multiple S3 Object Notification Event Types for a ...
I need to have an SQS Queue or SNS Topic which receives both Object Created events as well as Object Deleted Events.
Read more >
Event notification types and destinations - 亚马逊云科技
Amazon S3 supports several event notification types and destinations where the notifications can be published. You can specify the event type and destination ......
Read more >
Terraform s3 event notification error - Stack Overflow
If you haven't done it already, you need to specify a policy on the topic that grants the SNS:Publish permission to S3 (only...
Read more >
AWS S3 Bucket: Event Notifications | by Priyam Chauhan
Supported Events : Notifications could be published for following events: Object Creation ... s3:ObjectRemoved:* (All object removal events).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found