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

refactor(parameters): increase default max_age (cache) to 5 minutes #4279

Merged
merged 2 commits into from
May 6, 2024

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #4193

Summary

Changes

When using the Parameters utility, customers can leverage caching to minimize API calls. The default cache TTL is 5 seconds, after which Powertools expires the cache and if the parameter value is required inside the Lambda handler, a new API call may be triggered.

User experience

Customers don't need to change their code, unless they want to keep the TTL for 5 seconds and they can use max_age parameter.

Example

from typing import Any

import requests

from aws_lambda_powertools.utilities import parameters
from aws_lambda_powertools.utilities.typing import LambdaContext


def lambda_handler(event: dict, context: LambdaContext):
    try:
        # Retrieve a single parameter with 20s cache
        endpoint_comments: Any = parameters.get_parameter("/lambda-powertools/endpoint_comments", max_age=20)

        # the value of this parameter is https://jsonplaceholder.typicode.com/comments/
        comments: requests.Response = requests.get(endpoint_comments)

        return {"comments": comments.json()[:10], "statusCode": 200}
    except parameters.exceptions.GetParameterError as error:
        return {"comments": None, "message": str(error), "statusCode": 400}

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 May 6, 2024 10:16
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels May 6, 2024
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 6, 2024
@github-actions github-actions bot added enhancement and removed documentation Improvements or additions to documentation labels May 6, 2024
Copy link

sonarqubecloud bot commented May 6, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@leandrodamascena leandrodamascena added the v3 Features that will be included in Powertools v3. label May 6, 2024
@codecov-commenter
Copy link

codecov-commenter commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (v3@91c8584). Click here to learn what that means.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@          Coverage Diff          @@
##             v3    #4279   +/-   ##
=====================================
  Coverage      ?   95.90%           
=====================================
  Files         ?      218           
  Lines         ?    10462           
  Branches      ?     1936           
=====================================
  Hits          ?    10034           
  Misses        ?      308           
  Partials      ?      120           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@heitorlessa heitorlessa changed the title refactor(parameters): Change the default TTL (cache) to 5 minutes refactor(parameters): increase default max_age (cache) to 5 minutes May 6, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label May 6, 2024
@heitorlessa heitorlessa merged commit c2d088e into aws-powertools:v3 May 6, 2024
20 checks passed
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests v3 Features that will be included in Powertools v3.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Change the default TTL (cache) to 5 minutes in the Parameters utility
3 participants