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

Injecting custom http headers in boto3 #2251

Closed
rjeyasekar1 opened this issue Jan 6, 2020 · 5 comments
Closed

Injecting custom http headers in boto3 #2251

rjeyasekar1 opened this issue Jan 6, 2020 · 5 comments
Assignees

Comments

@rjeyasekar1
Copy link

rjeyasekar1 commented Jan 6, 2020

I have a need to send a custom http header (x-amzn-logs-format: json/emf
)
as a part of boto put_log_events call to write embedded metrics to CloudWatch logs.
Does boto3 provide any method to inject custom headers?

Thanks.

@swetashre swetashre self-assigned this Jan 6, 2020
@swetashre
Copy link
Contributor

@rjeyasekar1 - Thank you for your post. You can inject custom headers to an api call by registering it with boto3 events. Here is the link to the documentation with example:
https://boto3.amazonaws.com/v1/documentation/api/latest/guide/events.html

Please let me know if you have any more concerns.

@swetashre swetashre added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 7, 2020
@rjeyasekar1
Copy link
Author

Thanks, let me try that out.
Cheers

@no-response no-response bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jan 10, 2020
@swetashre
Copy link
Contributor

I am closing this issue as this has been resolved. Please reopen if you have any more concerns.

@ntextreme3
Copy link

@rjeyasekar1 did this work for you, and do you have an example? I haven't used boto before but was looking into testing something.

@bmbeverst
Copy link

@ntextreme3 here is an example that I got to work:

def add_emf_header(request, **kwargs):
    request.headers.add_header('x-amzn-logs-format', 'json/emf')
    print(request.headers). # Remove this after testing of course.

# You can even do this with watchtower! Use this instead, client = watchtower_handler.cwl_client
client = boto3.client('logs')
client.meta.events.register_first('before-sign.cloudwatch-logs.PutLogEvents', add_emf_header)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants