Skip to content

feat(event_handler): add VPCLatticeResolver #2601

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

Merged

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #2577

Summary

Changes

Amazon VPC Lattice is a fully managed application networking service that you use to connect, secure, and monitor the services for your application across multiple accounts and virtual private clouds (VPC). You can register your Lambda functions as targets with a VPC Lattice target group, and configure a listener rule to forward requests to the target group for your Lambda function.

In this PR we create a new resolver to support VPC Lattice.

User experience

Customers can use this new resolver to get the benefits of using the Event Handler utility.

import requests
from requests import Response

from aws_lambda_powertools.event_handler import VPCLatticeResolver
from aws_lambda_powertools.utilities.typing import LambdaContext

app = VPCLatticeResolver()

@app.get("/get")
def get_todo():
    todos: Response = requests.get("https://jsonplaceholder.typicode.com/todos")
    todos.raise_for_status()

    # for brevity, we'll limit to the first 10 only
    return {"todos": todos.json()[:10]}

def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

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.

@leandrodamascena leandrodamascena requested a review from a team June 27, 2023 17:49
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation event_handlers logger tests labels Jun 27, 2023
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 27, 2023
@leandrodamascena leandrodamascena changed the title feature: adding vpc lattice support feat(event_handler): add VpcLattice resolver Jun 27, 2023
@github-actions github-actions bot added the feature New feature or functionality label Jun 27, 2023
@leandrodamascena leandrodamascena changed the title feat(event_handler): add VpcLattice resolver feat(event_handler): add VPCLatticeResolver Jun 27, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2023

Codecov Report

Patch coverage: 94.44% and project coverage change: -0.06 ⚠️

Comparison is base (e6a999e) 97.22% compared to head (1ac1504) 97.16%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2601      +/-   ##
===========================================
- Coverage    97.22%   97.16%   -0.06%     
===========================================
  Files          160      161       +1     
  Lines         7394     7416      +22     
  Branches       537      525      -12     
===========================================
+ Hits          7189     7206      +17     
- Misses         158      161       +3     
- Partials        47       49       +2     
Impacted Files Coverage Δ
...lambda_powertools/utilities/data_classes/common.py 99.21% <66.66%> (-0.79%) ⬇️
aws_lambda_powertools/event_handler/__init__.py 100.00% <100.00%> (ø)
aws_lambda_powertools/event_handler/api_gateway.py 100.00% <100.00%> (ø)
aws_lambda_powertools/event_handler/vpc_lattice.py 100.00% <100.00%> (ø)
aws_lambda_powertools/logging/correlation_paths.py 100.00% <100.00%> (ø)
aws_lambda_powertools/utilities/batch/types.py 80.00% <100.00%> (-1.25%) ⬇️
...a_powertools/utilities/data_classes/vpc_lattice.py 92.50% <100.00%> (+0.60%) ⬆️
...ools/utilities/idempotency/persistence/dynamodb.py 98.80% <100.00%> (ø)
...s_lambda_powertools/utilities/parser/models/sns.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@rubenfonseca rubenfonseca linked an issue Jun 28, 2023 that may be closed by this pull request
2 tasks
@rubenfonseca
Copy link
Contributor

Looking at this now

@rubenfonseca rubenfonseca changed the title feat(event_handler): add VPCLatticeResolver feat(event_handler): add VpcLatticeResolver Jun 28, 2023
@rubenfonseca rubenfonseca changed the title feat(event_handler): add VpcLatticeResolver feat(event_handler): add VPCLatticeResolver Jun 28, 2023
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 @leandrodamascena ! Super nice work!

It would be nice to have some E2E tests for this, but as I understand correctly, it's still hard to get this on CDK, right?

@leandrodamascena
Copy link
Contributor Author

Thank you @leandrodamascena ! Super nice work!

It would be nice to have some E2E tests for this, but as I understand correctly, it's still hard to get this on CDK, right?

Yes Rubens! We need to create a VPC + VPC Lattice Network + Listener + Association + A Lambda inside this VPC and we can't invoke the VPC Lattice endpoint outside the vpc because it's not a public endpoint.

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.

Looks awesome, thank you @leandrodamascena !

@rubenfonseca rubenfonseca merged commit 1905e4c into aws-powertools:develop Jun 28, 2023
rafaelgsr pushed a commit to rafaelgsr/aws-lambda-powertools-python that referenced this pull request Jun 30, 2023
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 event_handlers feature New feature or functionality logger 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.

Feature request: Add Event handler for Amazon VPC Lattice
3 participants