s3cmd modify command
It would be super awesome to have something akin to a modify command that allowed changing the settings that are possible to set during upload but which don't seem to have a way to be modified later.
For instance, I'd like to be able to set headers, switch to reduced redundancy, make public, etc. for JPGs that are already uploaded:
s3cmd modify \
--add-header='Cache-Control: public, max-age=31536000' \
--reduced-redundancy \
--cf-invalidate \
--acl-public \
--recursive \
--exclude '*' \
--include '*.jpg' \
'foo' \
s3://foo
Unless I'm missing something these can be changed manually in the AWS Console, but not via s3cmd without a full delete and re-upload which may not be feasible.
Thanks in advance and keep up the great work!
You can copy (s3cmd cp) the file to itself with these new settings. That should do the trick for most changes. E.g. to make an already uploaded private file public do:
s3cmd cp --acl-public s3://bucket/blah.jpg s3://bucket/blah.jpg
Haven't tried recently but I believe it works.
Michal
On 03/09/2012 02:47 PM, Stephen McKamey wrote:
It would be super awesome to have something akin to a modify command that allowed changing the settings that are possible to set during upload but which don't seem to have a way to be modified later.
For instance, I'd like to be able to set headers, switch to reduced redundancy, make public, etc. for JPGs that are already uploaded:
s3cmd modify
--add-header='Cache-Control: public, max-age=31536000'
--reduced-redundancy
--cf-invalidate
--acl-public
--recursive
--exclude ''
--include '.jpg'
'foo'
s3://fooUnless I'm missing something these can be changed manually in the AWS Console, but not via s3cmd without a full delete and re-upload which may not be feasible.
Thanks in advance and keep up the great work!
Reply to this email directly or view it on GitHub: https://github.com/s3tools/s3cmd/issues/37
Is there a way to do that in bulk? If it has to be done one at a time, I can do that in the AWS Console. I'd really love at the least the ability to add a new header without having to re-upload everything.
Try --recursive (or -r), i.e.
s3cmd cp --acl-public s3://bucket/dir/ s3://bucket/dir/
Give it a try on a test bucket first and let me know :)
Michal
On 03/09/2012 02:52 PM, Stephen McKamey wrote:
Is there a way to do that in bulk? If it has to be done one at a time, I can do that in the AWS Console. I'd really love at the least the ability to set a new header without having to re-upload everything.
Reply to this email directly or view it on GitHub: https://github.com/s3tools/s3cmd/issues/37#issuecomment-4408435
The messaging implied that it worked but using mv appears to have deleted all of the files in the directory:
s3cmd mv --add-header='Cache-Control: public, max-age=31536000' --reduced-redundancy --cf-invalidate --acl-public --recursive s3://bucket/folder/ s3://bucket/folder/
I haven't tried cp yet...
You did s3cmd 'mv' which copies and then deletes the source. Try 's3cmd cp' instead.
M.
On 03/09/2012 03:04 PM, Stephen McKamey wrote:
The messaging implied that it worked but it appears to have deleted all of the files in the directory:
s3cmd mv --add-header='Cache-Control: public, max-age=31536000' --reduced-redundancy --cf-invalidate --acl-public --recursive s3://bucket/folder/ s3://bucket/folder/
Reply to this email directly or view it on GitHub: https://github.com/s3tools/s3cmd/issues/37#issuecomment-4408542
I'm finally getting back around to this. I just tried using cp and it doesn't look like it works. On the plus side though it looks like maintained the attributes that were already applied. I was wondering if I'd have to respecify them.
It's possible that S3 detects that the source and target are the same and does a NOOP.
Not sure to be honest, try to cp it to another prefix and see (e.g. s3://bucket/dir1/ -> s3://bucket/dir2/). If it still won't work I'll have to check the docs to see how it's supposed to work.
Michal
On 03/09/2012 05:21 PM, Stephen McKamey wrote:
I'm finally getting back around to this. I just tried using
cpand it doesn't look like it works. On the plus side though it looks like maintained the attributes that were already applied. I was wondering if I'd have to respecify them.It's possible that S3 detects that the source and target are the same and does a NOOP.
Reply to this email directly or view it on GitHub: https://github.com/s3tools/s3cmd/issues/37#issuecomment-4409699
Copying seems to work great, it even keeps the headers. But it doesn't seem to respect the --add-header option:
s3cmd cp --add-header='Cache-Control: public, max-age=31536000' --recursive s3://backet/dir1/ s3://bucket/dir2/
That could well be a bug in s3cmd. Keen to have a look at it? Or perhaps, should there be ";" instead of ","? I.e. "public; max-age=..." instead of "public, max-age=..."?
M.
On 03/09/2012 05:30 PM, Stephen McKamey wrote:
Copying seems to work great, it even keeps the headers. But it doesn't seem to respect the --add-header option:
s3cmd cp --add-header='Cache-Control: public, max-age=31536000' --recursive s3://backet/dir1/ s3://bucket/dir2/
Reply to this email directly or view it on GitHub: https://github.com/s3tools/s3cmd/issues/37#issuecomment-4409761
I am getting an S3 error when I attempt to "cp" an object to itself with or without an "--add-header" option:
$ s3cmd cp -P --add-header="Cache-Control: max-age=86400" s3://bucket/foo.jpg s3://bucket/foo.jpg
ERROR: S3 error: 400 (InvalidRequest): This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class or encryption attributes.
Oh, it will be painful if I have to re-install all of these gigabytes of content just because I didn't know to set a Cache-Control header the first time around. Thanks for s3cmd, though, it has otherwise been an INCREDIBLE timesaver and tool!
A bigger problem: even copying the resource to a new name does not make a new header appear.
$ s3cmd cp -P --add-header="Cache-Control: max-age=86400" s3://bucket/foo.jpg s3://bucket/foo2.jpg
Downloading foo2.jpg does not show any additional headers beyond the ones that Amazon provides by default. I should note that doing a completely fresh "put" to a non-existent URL does cause the header to appear, as does doing the "put" to the already-existing resource so that you overwrite it.
It sounds like @brandon-rhodes has the same use case I do. I haven't had a chance to dig into s3cmd code but it does seem like there needs to be a tweak in the s3cmd cp command to support this.
To answer the question @mludvig raised of a comma vs. semi-colon, the comma is correct syntax for extensions according to the HTTP/1.1 RFC:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.6
Regardless, I don't believe the content of the header shouldn't affect whether the header is set or not. I believe S3 filters by header name.
For some reason getting this to work via python subprocess took a lot of fiddling. I though it might be helpful to post what worked:
'--add-header=Cache-Control:public;max-age=31536000'
Note: semicolon, no spaces. Any other settings cause s3cmd to complain when called via subprocess (though it works fine from the command line).
I have the exact same use case as the other people here; I want to just add headers to files that are already in my bucket on s3. A modify command sounds like the cleanest approach from a usability perspective since the mental model for cp would not need to be changed ("oh, I can also modify a file's metadata with cp too if I copy a file to itself? Weird...").
+1 for this feature
here is a patch to make it work #94, you also have to define the content-type
I agree this feature is useful, and for those who need now, consider using a script like this: http://amix.dk/blog/post/19687
I think that one of the issues here is that s3cmd is hard coding in a header in line 414 of S3.py. This header sets the x-amz-metadata-directive to COPY (there is a TODO to turn this to a switch). From S3 documentation:
Constraints: Values other than COPY or REPLACE result in an immediate 400-based error response. You cannot copy an object to itself unless the MetadataDirective header is specified and its value set to REPLACE.
http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
So I don't think that the final request is actually configured correctly. Manually adding this header does not overwrite the default value.
I have hacked on that file, and successfully run a batch script that recursively changes 400,000 images from application/octet to application/jpeg. But the todo idea of adding a switch is needed for release code.
+1 for this as well
From website redirects, I used the following pattern:
s3cmd -c .s3cfg put dummy/index.html s3://bucket/from/ -P --add-header="x-amz-website-redirect-location:/to/"
Make a dummy file dummy/index.html and upload that - set a redirect on it boom!