aws / aws/chalice

on_sns_message results in error when triggered by CloudWatch Log Event

Open
#1,801 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
11.1k
Forks
1k
Avg merge
1d 22h
Merged PRs (30d)
2

Description

I have created an SNS topic that is subscribed to a lambda function and is triggered when another lambda function errors out (with [ERROR] filter). However, I am trying to test it after chalice is deployed and always receive an error.

```
[ERROR] KeyError: 'Records'
Traceback (most recent call last):
  File "/var/task/chalice/app.py", line 1564, in __call__
    event_obj = self.event_class(event, context)
  File "/var/task/chalice/app.py", line 1771, in __init__
    self._extract_attributes(event_dict)
  File "/var/task/chalice/app.py", line 1833, in _extract_attributes
    first_record = event_dict['Records'][0]
```

Which, as I understand, happens in decorator. My actual code doesn't even start:

```
@app.on_sns_message(topic='error_logger')
def cloudwatch_error(event):
print(event.subject)
print(event.message)
```

Not sure if I'm doing something wrong or not, but wanted to share this.

Contributor guide

Open the contributing guide

Research direction

Start with the traceback in chalice/app.py, especially SNS event handling around lines 1771 and 1833, and compare the event shape produced by the described CloudWatch-to-SNS trigger with what the handler receives. The report provides no test or expected behavior beyond avoiding the Records KeyError, so clarify the intended event format before deciding what done means.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
backend, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.