Parameter validation failed: Invalid bucket name in aws s3api put-object-acl - amazon-web-services

I have tried to change the ACL configuration of a file in s3 through the command line, but it showed the error
Parameter validation failed:
Invalid bucket name
The problem is that the file I want to access has a structure such as follows:
data/folder1/folder2/folder3/file
I tried to access using the code
aws s3api put-object-acl --bucket s3://data/folder1/folder2/folder3/ --key file --acl public-read
How should I specify this?
Thank you very much!
Lluc

The bucket name doesn't need the s3:// prefix when using put-object-acl:
$ aws s3api put-object-acl --bucket flomics-public --key 'lluc/ext-controls/data/folder1/folder2/folder3/file' --acl public-read

Related

Apply multiple tags to an object during uploading via aws cli

What's the correct syntax to upload an object with multiple tags?
Following command with 1 tag works fine:
aws s3api put-object --bucket mybucket --key something/obj.txt --body obj.txt --tagging "mykeyname1=myvalue1"
But following command with multiple tags generates error:
aws s3api put-object --bucket mybucket --key something/obj.txt --body obj.txt --tagging "mykeyname1=myvalue1, mykeyname2=myvalue2"
Error
An error occurred (InvalidArgument) when calling the PutObject operation: The header 'x-amz-tagging' shall be encoded as UTF-8 then URLEncoded URL query parameters without tag name duplicates
Unfortunately the documentation is not the best in this case. You can have multiple tags using the following format: key1=value1&key2=value2
For example:
aws s3api put-object --bucket mybucket --key something/obj.txt --body obj.txt --tagging 'mykeyname1=myvalue1&mykeyname2=myvalue2'

Get the size of file from AWS Cloudian Object Store

I currently use AWS S3 to retrieve a whole text file from S3 using the following command:
aws --profile=cloudian --endpoint-url=https://s3-abc.abcstore.abc.net s3 cp s3://abc-store/STORE1/abc2/ABC/test_08.txt test.txt
How can I just get the file size?
If you just want the size, use head object operation.
aws --profile=cloudian --endpoint-url=https://s3-abc.abcstore.abc.net s3api head-object --bucket abc-store --key STORE1/abc2/ABC/test_08.txt --query 'ContentLength'

Delete multiple files through aws cli not work

I have to delete the several .tar files on my s3 bucket. I run the command for doing this through aws cli but getting the error i.e
Error parsing parameter '--delete': Expected: '=', received: ''' for input:
'{Objects:[{Key:2019-03-27T160001Z.tar},{Key:2019-03-27T170001Z.tar}]}'
My aws version is : aws-cli/1.16.136 Python/3.6.0 Windows/10 botocore/1.12.126
My command is:
aws s3api delete-objects --bucket mybucket --delete '{"Objects":[{"Key":"2019-03-27T160001Z.tar"},{"Key":"2019-03-27T170001Z.tar"}]}'
Is there anyone who can guide me on where I am doing mistake. Any help is really appreciated.
You command worked fine for me. As per delete-objects — AWS CLI Command Reference, you can also use:
aws s3api delete-objects --bucket mybucket --delete 'Objects=[{Key=2019-03-27T160001Z.tar},{Key=2019-03-27T170001Z.tar}]'

Make an S3 Bucket Permissions Public Access to 'Everyone' using CLI

How would I set the S3 Bucket Permissions for Public Access to 'Everyone' for Read Files using AWS CLI?
The documentation does not have clear specification of how to do this and have tried multiple variations. My end goal is to make the bucket a static site server bucket.
S3 Bucket ACL permission are set after the bucket is created - I achieved a public file read bucket using this command
aws s3api put-bucket-acl --bucket ${SITE_NAME} --acl public-read
After creating the bucket:
aws s3api create-bucket --bucket ${SITE_NAME} --region ap-southeast-2 --create-bucket-configuration LocationConstraint=ap-southeast-2
Hope the below command will help you to make the s3 object public through the AWS CLI command.
aws s3api put-object-acl --bucket <bucketname> --key <object name with extension> --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers

S3api CLI Put Command Issue

I'm using AWS CLI to apply ACL policy to an object in S3, this is the command I have used
aws s3api put-object-acl --bucket XXXX --key XXXX --acl bucket-owner-full-control --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers
This command gives an error in return
An error occurred (InvalidRequest) when calling the PutObjectAcl operation: Specifying both Canned ACLs and Header Grants is not allowed
How to apply both Canned and Header Grants to an object ?
I tried by giving only Canned ACL first time (aws s3api put-object-acl --bucket XXXX --key XXXX --acl bucket-owner-full-control) and it applied ,but when I ran second time (aws s3api put-object-acl --bucket XXXX --key XXXX --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers by excluding canned ACL) and including Header Grants changes got overridden. It was including only Header Grants
Can you please help me out on this issue ?
You cannot do that, either you have to use Canned ACL or the Header grants.
You can include email address of bucket owner to grant full control and for others read access.
I mean include the bucket owner details run the command something like below as stated in AWS documentation example.
aws s3api put-object-acl --bucket MyBucket --key file.txt --grant-full-control emailaddress=user1#example.com,emailaddress=user2#example.com --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers
See the Note in AWS documentation.
Note
You can either use a canned ACL or specify access permissions explicitly. You cannot do both.
https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html