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

A way to add custom HTTP headers to S3 calls #2889

Closed
arainchik opened this issue Jun 3, 2021 · 11 comments
Closed

A way to add custom HTTP headers to S3 calls #2889

arainchik opened this issue Jun 3, 2021 · 11 comments
Labels
feature-request This issue requests a feature.

Comments

@arainchik
Copy link

Is your feature request related to a problem? Please describe.
We need a way to add custom HTTP headers to S3 calls without using global variables

Describe the solution you'd like
Current implementation allows you to add custom HTTP headers using event system as described in #2251 but it does not allow you to pass headers from the application making such calls. The only possible way I see right now is to use global variables, which is not a good practice.

My suggestion is to add new parameter CustomHTTPHeaders for S3 calls in boto, which will be passed to S3 target.

An example would be:

import boto3
s3 = boto3.client('s3')

s3.put_object(Bucket='BUCKET', Body=b'foo bar', CustomHTTPHeaders={'foo': 'bar'} )
print('Done')

@arainchik arainchik added feature-request This issue requests a feature. needs-triage This issue or PR still needs to be triaged. labels Jun 3, 2021
@stobrien89 stobrien89 self-assigned this Jun 4, 2021
@stobrien89
Copy link
Contributor

Hi @arainchik,

Thanks for the feature request! Would you mind elaborating on what your particular use case would be for this?

@arainchik
Copy link
Author

There are multiple uses for this kind of feature. One example would be to pass special authentication token in HTTP headers to HTTPS proxy.

@stobrien89 stobrien89 removed the needs-triage This issue or PR still needs to be triaged. label Jun 7, 2021
@stobrien89
Copy link
Contributor

Hi @arainchik,

Thanks for clarifying! I'll pass this along to the team.

@andyalbert
Copy link

Hi @stobrien89
Can I pick this one up?

@stobrien89
Copy link
Contributor

Hi @andyalbert,

My apologies for the delay. Let me double-check with the team that we'll accept a change like this before you put in the effort. I'll probably have an update sometime next week.

@stobrien89
Copy link
Contributor

Hi all,

Just to confirm, the main issue here is that you're unable to dynamically pass headers to the event system, correct?

@stobrien89 stobrien89 added the response-requested Waiting on additional information or feedback. label Sep 22, 2021
@arainchik
Copy link
Author

arainchik commented Sep 22, 2021

@stobrien89 you are correct, there is no way to pass custom data to event handlers, currently we have to do it in a non-pythonic way using global variables/queues.

@github-actions github-actions bot removed the response-requested Waiting on additional information or feedback. label Sep 22, 2021
@stobrien89 stobrien89 removed their assignment Jan 7, 2022
@bradhill99
Copy link

Found possible solution from https://stackoverflow.com/questions/58828800/adding-custom-headers-to-all-boto3-requests

def _add_header(request, **kwargs):
    request.headers.add_header('x-trace-id', 'trace-trace')
    print(request.headers)  # for debug

some_client = boto3.client(service_name=SERVICE_NAME)
event_system = some_client.meta.events
event_system.register_first('before-sign.*.*', _add_header)

@arainchik
Copy link
Author

Found possible solution from https://stackoverflow.com/questions/58828800/adding-custom-headers-to-all-boto3-requests

def _add_header(request, **kwargs):
    request.headers.add_header('x-trace-id', 'trace-trace')
    print(request.headers)  # for debug

some_client = boto3.client(service_name=SERVICE_NAME)
event_system = some_client.meta.events
event_system.register_first('before-sign.*.*', _add_header)

It works, but as I mintioned earlier:

there is no way to pass custom data to event handlers, currently we have to do it in a non-pythonic way using global variables/queues.

@kdaily
Copy link
Member

kdaily commented Feb 25, 2022

Hi all, closing this in favor of a duplicate opened at botocore:

boto/botocore#2050

@kdaily kdaily closed this as completed Feb 25, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue requests a feature.
Projects
None yet
Development

No branches or pull requests

5 participants