0

Im trying to change S3 file's metadata from python, and test with chalice server locally (need the chalice for other things). When running (without chalice server):

# change file metadata in s3:
s3 = boto3.resource('s3')
s3_object = s3.Object(bucket, key)
s3_object.metadata.update({'metadata-key': 'something'})
s3_object.copy_from(CopySource={'Bucket': bucket, 'Key': key}, Metadata=s3_object.metadata,
                        MetadataDirective='REPLACE')

In python locally (with aws configured locaclly) everything is fine and the metadata is changing in S3.

The problem is when using chalice python local server, Im getting this error:

An error occurred (404) when calling the HeadObject operation: Not Found

(I need the chalice to simulate a lambda, and the s3 metadata part is in there)

Any ideas why this happenes?

Thanks :-)

Idan Rotbart
  • 93
  • 1
  • 5
  • Not familiar with Chalice. Is the code running under Chalice talking to the real AWS S3 service? If so and your credentials have s3:ListBucket permission then you'll get a 404 if a) the bucket does not exist or b) the bucket exists but the key does not. I'd double-check the bucket and key. Also, do you have any special characters in the key? If you put extra logs in the code, which operation triggers the 404 response? – jarmod Oct 27 '22 at 11:05
  • Yes it talks to AWS S3 service, and the bucket and key that I gave it are the same as I tested locally (it worked locally) – Idan Rotbart Oct 27 '22 at 12:27
  • I'd consider enabling [DEBUG logging](https://yellowdesert.consulting/2019/02/20/python-boto3-logging/) for boto3. – jarmod Oct 27 '22 at 12:57

1 Answers1

0

An error occurred (404) when calling the HeadObject operation: Not Found

If the object exists, this error usually means the role you are using to make the request doesn't have the required permissions.

Your local tests with Python work because they are using your default AWS profile. But that key is not passed to the Chalice APP.

You need to add read/write permissions to that bucket for that Lambda in Chalice.

  • 404 does not mean that you are missing the correct permissions. That would be 403. In fact, 404 actually indicates that you do have some relevant permissions (s3:ListBucket at least) and that the object does not exist. – jarmod Oct 27 '22 at 01:01
  • Thank you for your answers. the file does exist is S3 (I can access it regularly locally) but still getting 404 when using chalice. So I'm not sure what is happening there @jarmod – Idan Rotbart Oct 27 '22 at 04:10