Replies: 3 comments 2 replies
-
Hello @dobeerman! Thank you so much for opening this discussion and allowing us to help you with the adoption of Powertools for AWS Lambda. I'll try to cover as much as possible all your questions and let me know if I miss something.
One of our tenants says: "AWS Lambda only. We optimise for AWS Lambda function environments and supported runtimes only. Utilities might work with web frameworks and non-Lambda environments, though they are not officially supported." I started by bringing this statement to explain that you can use Powertools for AWS Lambda outside of the Lambda runtime, but it may have some limitations and unsupported features. This is because some functionality is closely linked to how AWS Lambda works and we can't modify these behaviours. Questions:Logger
You can use the Metrics
Yes, you can use An important point here is that the Parameters
I don't see any limitations on using the utility Example:I created an example of a Flask application running in a container that we can use as a starting point for you to verify the viability of adopting Powertools for AWS Lambda in your Fargate containers. Dockerfile:FROM python:3.10
COPY ./* ./app/
WORKDIR /app/
RUN pip install -r requirements.txt
EXPOSE 3000
CMD ["python", "app.py"] requirements.txt
app.py:from flask import Flask
from aws_lambda_powertools import Logger
from aws_lambda_powertools.metrics.provider.datadog import DatadogProvider
from aws_lambda_powertools.utilities import parameters
logger = Logger(service="PowertoolsAPP")
# Appending persistent keys across all future log messages
# See: https://docs.powertools.aws.dev/lambda/python/latest/core/logger/#appending-additional-keys
logger.append_keys(environment="Fargate")
# Using Datadog Forwarder method
# See: https://docs.powertools.aws.dev/lambda/python/latest/core/metrics/datadog/#integrating-with-datadog-forwarder
metrics = DatadogProvider(flush_to_log=True)
app = Flask(__name__)
@app.route('/')
def index():
# Getting parameter
powertools_hello: str = parameters.get_parameter("/lambda-powertools/powertools_hello")
logger.info(powertools_hello)
# Logging info log with ephemeral metadadata
# See: https://docs.powertools.aws.dev/lambda/python/latest/core/logger/#ephemeral-metadata
logger.info("Hello world", route="default", customer="dobeerman")
# Adding a custom metric with additional tags
# https://docs.powertools.aws.dev/lambda/python/latest/core/metrics/datadog/#adding-tags
metrics.add_metric(name="HelloWorldPowertools", value=1, tag1="tag")
# Flushing metrics manually
# See:https://docs.powertools.aws.dev/lambda/python/latest/core/metrics/datadog/#flushing-metrics-manually
metrics.flush_metrics()
return 'Hello World PowertoolsAPP'
app.run(host='0.0.0.0', port=3000) Output:❯ docker rm fargate-beyond; docker run --name fargate-beyond -p 3000:3000 fargate-beyond
fargate-beyond
* Serving Flask app 'app'
* Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:3000
* Running on http://172.17.0.2:3000
Press CTRL+C to quit
{"level":"INFO","location":"index:25","message":"Hello world parameter","timestamp":"2023-08-27 21:04:51,569+0000","service":"PowertoolsAPP","environment":"Fargate"}
{"level":"INFO","location":"index:30","message":"Hello world","timestamp":"2023-08-27 21:04:51,685+0000","service":"PowertoolsAPP","environment":"Fargate","route":"default","customer":"dobeerman"}
172.17.0.1 - - [27/Aug/2023 21:04:51] "GET / HTTP/1.1" 200 -
{"m":"HelloWorldPowertools","v":1,"e":1693170291,"t":["tag1:tag"]} Please let me know if you have any questions and we can evolve this scenario. Thanks |
Beta Was this translation helpful? Give feedback.
-
Hey @leandrodamascena, Thanks a lot for such a detailed breakdown! Logger: Having no Datadog Metrics: I guess we can have the BTW, in Lambda, if I add Parameters: No roadblocks? Awesome! Any ETA on Datadog getting its act together with METRIC_TYPE and INTERVAL? Just fishing for some insider info. 😄 Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hello @dobeerman! I am glad that this explanation can help you to clarify your questions.
Good idea, so you make it generic.
I tried to simulate here and it's working perfectly. Can you show me the code and Pylance warning?
Not yet, but we'll create an issue as soon as we start adding this feature, so stay tuned to the Powertools repository 😄 Let me know if I can help with any other requests, and if possible, let us know about your experience using our new Datadog Metric provider. It is very important for us to know from our customers what they think of the experience. |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
We're interested in using the Logger, Parameters and Datadog provider utilities across different environments.
Context
We have a mixed environment of Lambda functions (Python/TypeScript) and Fargate containers written in Python. We're currently integrating Datadog into our applications and migrating most of our Python/TypeScript Lambda loggers to aws-powertools.
In our containerized Lambdas, we're using code from our main application, which currently utilizes the standard Python logger. This raises questions about unifying our logging solution across different environments.
Goals:
Questions:
Looking forward to your insights and suggestions!
Beta Was this translation helpful? Give feedback.
All reactions