Skip to content
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

feat(event_sources): add CloudWatch dashboard custom widget event #1474

Conversation

sthuber90
Copy link
Contributor

@sthuber90 sthuber90 commented Aug 24, 2022

Issue number: #1461

Summary

Changes

Please provide a summary of what's being changed

Added event mapping class for custom widget in CloudWatch dashboard

User experience

Please share what the user experience looks like before and after this change

With the new CloudWatchDashboardCustomWidgetEvent data class users have typed access to the event. The event will have custom parameters provided by the user in event.params["name"], event.raw_event["name"] and event["name"]. If the Lambda function is invoked with the describe parameter, the function should return its documentation. The describe parameter can be provided alone without the widgetContext being part of the event or as a custom param by the invoking user.

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.


View rendered docs/utilities/data_classes.md

@sthuber90 sthuber90 requested a review from a team as a code owner August 24, 2022 09:59
@sthuber90 sthuber90 requested review from mploski and removed request for a team August 24, 2022 09:59
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Aug 24, 2022
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 24, 2022
@github-actions github-actions bot added the feature New feature or functionality label Aug 24, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 24, 2022

Codecov Report

Merging #1474 (41f8df5) into develop (a45a792) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop    #1474   +/-   ##
========================================
  Coverage    99.89%   99.89%           
========================================
  Files          123      124    +1     
  Lines         5498     5585   +87     
  Branches       629      634    +5     
========================================
+ Hits          5492     5579   +87     
  Misses           2        2           
  Partials         4        4           
Impacted Files Coverage Δ
...mbda_powertools/utilities/data_classes/__init__.py 100.00% <100.00%> (ø)
...es/data_classes/cloud_watch_custom_widget_event.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@rubenfonseca rubenfonseca changed the title feat(data_classes): add CloudWatch dashboard custom widget event feat(event_sources): add CloudWatch dashboard custom widget event Aug 24, 2022
Copy link
Contributor

@rubenfonseca rubenfonseca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much! Looks pretty good! Just left a small comment to improve the docs, let me know what you think :)

docs/utilities/data_classes.md Outdated Show resolved Hide resolved
Co-authored-by: Ruben Fonseca <fonseka@gmail.com>
@leandrodamascena
Copy link
Contributor

leandrodamascena commented Aug 24, 2022

Hello @sthuber90! This is an awesome PR, thanks a lot for taking the time to help improve the project!

I think it's missing a field domain in event source schema.. Using aws examples we can see the field domain in event source.

Could you please add this field?

image

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the domain field.

@sthuber90
Copy link
Contributor Author

@leandrodamascena I looked at the link you posted and in the cloudwatch-custom-widgets-samples repo but didn't find any domain (https://github.com/aws-samples/cloudwatch-custom-widgets-samples/search?q=domain). Furthermore, it's not mentioned in the official docs

Every call by a custom widget to Lambda includes a widgetContext element with the following contents, to provide the Lambda function developer with useful context information.

{
    "widgetContext": {
        "dashboardName": "Name-of-current-dashboard",
        "widgetId": "widget-16",
        "accountId": "012345678901",
        "locale": "en",
        "timezone": {
            "label": "UTC",
            "offsetISO": "+00:00",
            "offsetInMinutes": 0
        },
        "period": 300,
        "isAutoPeriod": true,
        "timeRange": {
            "mode": "relative",
            "start": 1627236199729,
            "end": 1627322599729,
            "relativeStart": 86400012,
            "zoom": {
                "start": 1627276030434,
                "end": 1627282956521
             }
        },
        "theme": "light",
        "linkCharts": true,
        "title": "Tweets for Amazon website problem",
        "forms": {
            "all": {}
        },
        "params": {
            "original": "param-to-widget"
        },
        "width": 588,
        "height": 369
    }
}

Can you please provide a link where the domain field is shown? And if we really want to add it, I think the AWS docs need to be updated as well.

@leandrodamascena
Copy link
Contributor

leandrodamascena commented Aug 25, 2022

Hi @sthuber90 - Answering your comments and questions:

Can you please provide a link where the domain is shown?

There isn't. I've notified the documentation team to include it.

I looked at the link you posted and in the cloudwatch-custom-widgets-samples repo but didn't find any domain

I should've been more explicit in what examples contained the domain field - I've found them after deploying the "Echo", "Hello world" and "Simple SVG pie chart" examples.

As we've encountered this issue before (missing schema and docs accuracy), I've deployed all of those examples to confirm whether domain field was present - it was.


Steps to reproduce:

1 - I chose the "Echo", "Hello World" and "SVG Pie Chart Example" examples here.

2 - As all the examples are cloudformation templates, I just clicked on the link and deployed it to my account.

3 - When the stack was complete I went to Lambda Function and added a print to the event variable inside the handler function.
image

4 - I used the dashboard created earlier just to generate logs a few times. After that I could see in the Cloudwatch Lambda Log Groups the domain field in the event.
image

@sthuber90
Copy link
Contributor Author

Thank you for the clarification. I will add the field in the next days 👍

@sthuber90
Copy link
Contributor Author

@leandrodamascena added domain field

@leandrodamascena
Copy link
Contributor

@leandrodamascena added domain field

Hi @sthuber90!. I only removed a line in the example code and now it's ok to merge.

Thank you again.

@leandrodamascena leandrodamascena merged commit 6f8769d into aws-powertools:develop Aug 29, 2022
rubenfonseca added a commit that referenced this pull request Sep 13, 2022
)

Co-authored-by: Ruben Fonseca <fonseka@gmail.com>
Co-authored-by: Leandro Damascena <leandro.damascena@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants