Comprehensive developer toolkit implementing serverless best practices for AWS Lambda functions in Python
89
Build a Lambda function that retrieves application configuration from multiple AWS parameter stores and provides a unified configuration object. The service should efficiently retrieve parameters with caching, handle different data types, and support both single and batch retrieval operations.
Multiple Parameter Sources: Support retrieving configuration from:
Single Parameter Retrieval: Implement a function that retrieves a single parameter by name from any of the supported sources.
Batch Parameter Retrieval: Implement a function that retrieves multiple parameters in a single operation. The function should accept a list of parameter names and return a dictionary mapping names to values.
Value Transformation: Support automatic JSON parsing for parameters that contain JSON-formatted strings. The transformation should be applied automatically based on parameter content or naming convention.
Caching: Enable caching for retrieved parameters to reduce API calls. Cache entries should have a reasonable time-to-live (TTL) to balance between freshness and performance.
Error Handling: Handle cases where parameters don't exist gracefully. The system should allow retrieving parameters with a default value if the parameter is not found.
Create the following functions in config_service.py:
get_parameter(name: str, source: str) -> str: Retrieves a single parameter from the specified sourceget_parameters_batch(names: list, source: str) -> dict: Retrieves multiple parameters from the specified sourceget_json_parameter(name: str, source: str) -> dict: Retrieves and automatically parses a JSON parameterget_parameter_with_default(name: str, source: str, default: str) -> str: Retrieves a parameter with fallback to default valueThe source parameter should accept values: "ssm", "secrets", "dynamodb"
Create test file test_config_service.py:
Input:
Expected behavior:
Input:
Expected behavior:
Input:
{"debug": true, "timeout": 30}Expected behavior:
Input:
Expected behavior:
Python toolkit for implementing serverless best practices in AWS Lambda.
Install with Tessl CLI
npx tessl i tessl/pypi-aws-lambda-powertoolsdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10