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

Missing RequestId From mocked S3 service API response #3442

Closed
NathanielRN opened this issue Nov 6, 2020 · 2 comments · Fixed by #3836
Closed

Missing RequestId From mocked S3 service API response #3442

NathanielRN opened this issue Nov 6, 2020 · 2 comments · Fixed by #3836

Comments

@NathanielRN
Copy link

This was using botocore at 1.19.12 and moto at 1.3.16

What Actually Happened

When I use moto to mock s3, I expected to see RequestId in the ResponseMetadata. This was my setup:

@mock_s3
def test_s3_put(self):
    params = dict(Key="foo", Bucket="mybucket", Body=b"bar")
    s3 = self.session.create_client("s3", region_name="us-west-2")
    location = {"LocationConstraint": "us-west-2"}
    s3.create_bucket(Bucket="mybucket", CreateBucketConfiguration=location)
    s3.put_object(**params)
    response = s3.get_object(Bucket="mybucket", Key="foo")
    print('Response to S3 GetObject: ', response)

However, when I printed out the response, I only saw the following:

{
    'ResponseMetadata': {
        'HTTPStatusCode': 200, 
        'HTTPHeaders': {
            'content-md5': 'N7UdGUp1E+RbVvZSTy1R8g==',
            'etag': '"37b51d194a7513e45b56f6524f2d51f2"',
            'last-modified': 'Fri, 06 Nov 2020 23:29:30 GMT',
            'content-length': '3'
        },
        'RetryAttempts': 0
    }, 
    'LastModified': datetime.datetime(2020,11,6,23,29,30,tzinfo=tzutc()), 
    'ContentLength': 3, 
    'ETag': '"37b51d194a7513e45b56f6524f2d51f2"', 
    'Metadata': {}, 
    'Body': <botocore.response.StreamingBody object at 0x10722f460>
}

What I Expected to Happen

This is compared to my sample application where I do this:

s3_client = boto3.client('s3')
response = s3_client.get_object(Bucket='mybucket', Key='my_file')
print(response)

And I get a response like this from S3:

{
    'ResponseMetadata': {
        'RequestId': 'FF5D971A11D3B6D6',
        'HostId': 'jiUP1wkSGUjx2OyXDfOzhNZhfxjYUW91FI+V1pURh8QeDCMj+9bsxRhUXLANylOlkHh4llr/COU=',
        'HTTPStatusCode': 200,
        'HTTPHeaders': {
            'x-amz-id-2': 'jiUP1wkSGUjx2OyXDfOzhNZhfxjYUW91FI+V1pURh8QeDCMj+9bsxRhUXLANylOlkHh4llr/COU=',
            'x-amz-request-id': 'FF5D971A11D3B6D6',
            'date': 'Fri,
            06 Nov 2020 23:24:12 GMT',
            'last-modified': 'Fri,
            09 Oct 2020 04:36:48 GMT',
            'etag': '"e336233045ad091013c89ed3d6463de1"',
            'accept-ranges': 'bytes',
            'content-type': 'binary/octet-stream',
            'content-length': '63',
            'server': 'AmazonS3'
        },
        'RetryAttempts': 0
    },
    'AcceptRanges': 'bytes',
    'LastModified': datetime.datetime(2020, 10, 9, 4, 36, 48, tzinfo=tzutc()),
    'ContentLength': 63,
    'ETag': '"e336233045ad091013c89ed3d6463de1"',
    'ContentType': 'binary/octet-stream',
    'Metadata': {},
    'Body': <botocore.response.StreamingBody object at 0x10e380e20>
}

Please let me know if I'm missing something here.

@bblommers
Copy link
Collaborator

Hi @NathanielRN, thanks for raising this!
In other services we tend to use the @amzn_request_id-annotation to automatically add a RequestId to every response, but that doesn't happen in S3. Marking it as an enhancement!

@NathanielRN
Copy link
Author

@bblommers Awesome! Thank you for your quick and helpful answer :) Really appreciate it!

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

Successfully merging a pull request may close this issue.

2 participants