Bug: Logger is not defined
See original GitHub issueExpected Behaviour
Logger to be used as always have been (same usagee as in below code snippet done in dozens of other lambdas)
Current Behaviour
Error from Lambda logs:
[ERROR] NameError: name 'Logger' is not defined Traceback (most recent call last): File "/var/lang/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 850, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/var/task/lambda.py", line 11, in <module> LOGGER = Logger(sampling_rate=float(os.environ["POWERTOOLS_LOGGER_SAMPLE_RATE"]))
Code snippet
# -*- coding: utf-8 -*-
"""Stop EC2 with Schedule tag name."""
import os
from typing import Any, Dict
import boto3
from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities.typing import LambdaContext
LOGGER = Logger(sampling_rate=float(os.environ["POWERTOOLS_LOGGER_SAMPLE_RATE"]))
REGION = os.environ["REGION"]
TAG_NAME = os.environ["TAG_NAME"]
TAG_VALUE = os.environ["TAG_VALUE"]
FILTERS = [{"Name": f"tag:{TAG_NAME}", "Values": [TAG_VALUE]}]
CLIENT = boto3.client("ec2", region_name=REGION)
# pylint: disable=W0613
@LOGGER.inject_lambda_context(log_event=True)
def lambda_handler(event: Dict[str, Any], context: LambdaContext) -> None:
"""Starting lambda."""
LOGGER.debug(f"Event: {event}")
reservations = CLIENT.describe_instances(Filters=FILTERS)
for r in reservations["Reservations"]:
for i in r["Instances"]:
CLIENT.stop_instances(InstanceIds=[i["InstanceId"]])
LOGGER.debug(f"Stopped {i['InstanceId']} successfully")
Possible Solution
No response
Steps to Reproduce
Deploy powertools 1.26.1 to lambda layer, lambda code to lambda service
AWS Lambda Powertools for Python version
1.26.1
AWS Lambda function runtime
3.9
Packaging format used
Lambda Layers
Debugging logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:14 (6 by maintainers)
Can confirm my custom layer is working, AWS lately is mehhh. Thx to all for reaching out!
Here you are whole powertools lib content 😃
aws_lambda_powertools.zip