vduseev/opensearch-logger

How to use AWS4Auth with dictConfig

Closed this issue · 5 comments

I was wondering if there was an example of how to pass aws authentication to a dictConfig I tried the following

LOGGING_CONFIG = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "opensearch": {
            "level": "DEBUG",
            "class": "opensearch_logger.OpenSearchHandler",
            "index_name": index_name.lower(),
            "buffer_size": 1,
            "raise_on_index_exc": True,
            "hosts": [aws_host],
            "http_auth": AWS4Auth(region=region, service=service, refreshable_credentials=creds),
            "http_compress": True,
            "use_ssl": True,
            "verify_certs": False,
            "ssl_assert_hostname": False,
            "ssl_show_warn": False,
            "connection_class": "opensearchpy.RequestsHttpConnection"
        }
    },
    "loggers": {
        "insights.routers.users": {
            "handlers": ["opensearch"],
            "level": "DEBUG",
            "propagate": True
        }
    }
}

but got an exception when trying to send a log to opensearch

Hi! There is an example in the main Readme file. Does that work for your use case?

Ahh, sorry my bad! I see now that you are tying to do that inside the configuration dictionary.

I haven't tried that. Might require a bit of the modification to the library. Will take a look at this in the coming couple of weeks

I actually had a mistake, it works as is, just the connection class cannot be wrapped in a string, it should just be "connection_class": RequestsHttpConnection

thanks for the quick response

Happy it worked for you! Thank you so much for the follow up!

Could you please be so kind as to paste the full example of the dict config that worked for you? I would be happy to add it to the documentation

from requests_aws4auth import AWS4Auth
from opensearchpy import RequestsHttpConnection

LOGGING_CONFIG = {
    "version": 1,
    "disable_existing_loggers": False,
    "handlers": {
        "opensearch": {
            "level": "DEBUG",
            "class": "opensearch_logger.OpenSearchHandler",
            "index_name": index_name.lower(),
            "raise_on_index_exc": True,
            "hosts": [aws_host],
            "http_auth": AWS4Auth(region=region, service=service, refreshable_credentials=creds),
            "http_compress": True,
            "use_ssl": True,
            "verify_certs": False,
            "ssl_assert_hostname": False,
            "ssl_show_warn": False,
            "connection_class": RequestsHttpConnection
        }
    },
    "loggers": {
        "my_logger": {
            "handlers": ["opensearch"],
            "level": "DEBUG",
            "propagate": True
        }
    }
}