How to delete aws s3 bucket in aws cli - amazon-web-services

I have the ff s3 bucket, see image below:
I know how to delete them on the page but how can i delete them using aws cli?
I tried using
aws s3api delete-objects --bucket
elasticbeanstalk-ap-southeast-1-613285248276
but it wont work.

You can use 'rb' option
E.g. aws s3 rb s3://elasticbeanstalk-ap-southeast-1-613285248276
For more details click here
If the bucket is not empty then use the --force flag

The following commands deletes the Bucket from S3
aws s3api delete-bucket --bucket "your-bucket-name" --region "your-region".

I am deleting S3 bucket from following command without any extra hustle of emptying it first
aws s3 rb s3://<BUCKATE-NAME> --force
for example
aws s3 rb s3://alok.guha.myversioningbucket --force
PS : Make sure you have programmatic access with policy "AmazonS3FullAccess"

Related

How do you create an AWS S3 bucket with versioning enabled from the cli?

How do you create a private S3 bucket with versioning enabled?
I can't quite figure it out from https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3/mb.html nor https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/create-bucket.html
There is scant documentation from the cli too:
$ aws s3 mb help
$ aws --version
aws-cli/2.7.25 Python/3.9.11 Linux/5.18.16-arch1-1 exe/x86_64.arch prompt/off
There is no parameter to request the bucket to be created with Versioning enabled.
However, if ObjectLock is specified, then this forces Versioning to also be enabled:
aws s3api create-bucket --bucket MY-BUCKET --object-lock-enabled-for-bucket --create-bucket-configuration LocationConstraint=ap-southeast-2
However the S3 management console then says:
Once Amazon S3 Object Lock is enabled, you can't disable Object Lock or suspend Bucket Versioning for the bucket.
The alternative is to create the bucket and THEN enable Versioning.

Get the CLI Config for an AWS S3 Bucket

I want to see the existing configuration for a S3 Bucket, so that I can steal and tweak it for my own purposes, in a variety of cases. However, I am not seeing an option I would expect:
aws s3api describe-bucket --bucket BucketName
Akin to the EMR describe cluster option that does exist:
aws emr describe-cluster --cluster-id j-1PGB1J30TZHQF
There is no single API call or CLI invocation to return the configuration of an S3 bucket, that I'm aware of.
You'd need to query a number of different things, for example its bucket policy, its CORS configuration, any ACLs, transfer acceleration configuration, tags, and more.
All of these things are available from the awscli, for example:
aws s3api get-bucket-policy --bucket X
aws s3api get-bucket-cors --bucket X
aws s3api get-bucket-location --bucket X
aws s3api get-bucket-versioning --bucket X

AWS S3 Bucket counts

I have tried to run these commands:
aws s3api list-objects --bucket bucket --profile key --output json --query "[length(Contents[])]"
and
aws s3 --profile=key ls s3://bucket/ --recursive --summarize
but what I'm curious about is that some of the objects have been marked for deletion. Do these commands count the objects marked for deletion or are they excluded?
commands shared here will list objects/files given in a specified path. these commands will not display any of the deleted objects. for details refer S3 ls

How do I use the aws cli to set permissions on files in an S3 bucket?

I am new to the aws cli and I've spent a fair amount of time in the documentation but I can't figure out how to set permissions on files after I've uploaded them. So if I uploaded a file with:
aws s3 cp assets/js/d3-4.3.0.js s3://example.example.com/assets/js/
and didn't set access permissions, I need a way to set them. Is there an equivalent to chmod 644 in the aws cli?
And for that matter is there a way to view access permission?
I know I could use the --acl public-read flag with aws s3 cp but if I didn't, can I set access without repeating the full copy command?
The awscli supports two groups of S3 actions: s3 and s3api.
You can use aws s3api put-object-acl to set the ACL permissions on an existing object.
The logic behind there being two sets of actions is as follows:
s3: high-level abstractions with file system-like features such as ls, cp, sync
s3api: one-to-one with the low-level S3 APIs such as put-object, head-bucket
In your case, the command to execute is:
aws s3api put-object-acl --bucket example.example.com --key assets/js/d3-4.3.0.js --acl public-read

How to grantee a open/download permission for an amazon s3 object in large bucket?

I have an amazon bucket with hundreds of thousands of objects. I just uploaded new file using their AWS console, but I can't get it in their console as I must scroll down for thousand times!
I tried to make the folder public, but it loops over all objects. I also downloaded BucketExplorer, but it downloads the index of all objects which take much time!
So, is there anyway to edit the permission for a specific object on Amazon S3 remotely?!
You can upload the objects again with the AWS CLI S3 and add the ACL in the options to public read. OR if that is not an option and you know the key of the new objects you can use the AWS CLI s3api command to edit the ACL with the s3api put-object-acl command.
S3 cp Example
Copies test.txt file to the S3 bucket mybucket with the name of test2.txt and sets the ACL to public-read
aws s3 cp test.txt s3://mybucket/test2.txt --acl public-read
--acl (string) Sets the ACL for the object when the command is performed. If you use this parameter you must have the "s3:PutObjectAcl" permission included in the list of actions for your IAM policy. Only accepts values of private, public-read, public-read-write, authenticated-read, aws-exec-read, bucket-owner-read, bucket-owner-full-control and log-delivery-write. See Canned ACL for details
S3api Example
Sets the ACL to public read for objet file.txt in bucket MyBuckey
aws s3api put-object-acl --bucket MyBucket --key file.txt --acl public-read
AWS CLI S3 CP command
http://docs.aws.amazon.com/cli/latest/reference/s3/cp.html
AWS CLI s3api command
http://docs.aws.amazon.com/cli/latest/reference/s3api/put-object-acl.html
Have you looked into granting GetObject permissions via bucket policy? The policy would apply to objects where the the bucket owner is also the object owner.
http://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html