Getting S3 Bucket Size
Long story short you can use one of the following methods:
aws s3api --profile PROFILE_NAME list-objects --bucket BUCKET_NAME --output json \
--query "[sum(Contents[].Size), length(Contents[])]"
or some existing tool such as
s3cmd du s3://bucket-name
But it may be instructive to study in detail how to work with the AWS api:
Listing the Buckets
s3 ls or s3api list-buckets
and
s3api list-objects
we also need two related permissions:
s3:ListAllMyBuckets
- for seeing the bucket namess3:ListBucket
- for listing the objects (this permission does not allow us to read the content)A new user without any permissions returns:
petr@petr-VirtualBox:~$ aws --profile demo s3 ls An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied
with the policy following IAM policy:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "awss3ls", "Effect": "Allow", "Action": "s3:ListAllMyBuckets", "Resource": "*" } ] }
we can get the list of our S3 buckets:
2018-11-04 21:06:24 cf-templates-1he2i9kkenjwe-eu-central-1 2018-01-20 13:49:55 elasticbeanstalk-us-east-2-588956854787 2018-11-17 23:13:08 test-userfiles-mobilehub-927286690
This output is fine, but if we need only the bucket name we need to play with it a little bit more:
We can filter the third column with AWK:
aws --profile demo s3 ls | awk '{print $3}'
or we can call directly s3api list-buckets:
aws --profile demo s3api list-buckets --query "Buckets[].Name" [ "cf-templates-1he2i9kkenjwe-eu-central-1", "elasticbeanstalk-us-east-2-588956854787", "test-userfiles-mobilehub-927286690" ]
For using this in a bash loop it is more useful to work with the text output:
aws --profile demo s3api list-buckets --query "Buckets[].Name" --output text
Listing the Objects
petr@petr-VirtualBox:~$ aws --profile demo s3api list-objects --bucket cf-templates-1he2i9kkenjwe-eu-central-1 --output json An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied
If we modify the 'Action' of our policy to:
"Action": ["s3:ListAllMyBuckets","s3:ListBucket"]
we would now be able to see the the bucket content:
petr@petr-VirtualBox:~$ aws --profile demo s3api list-objects --bucket cf-templates-1he2i9kkenjwe-eu-central-1 --output json
{
"Contents": [
{
"ETag": "\"7b6127c13b5d833d1632c081e46ad5f2\"",
"StorageClass": "STANDARD",
"Size": 2859,
"LastModified": "2018-11-04T20:06:24.000Z",
"Key": "2018308Opv-rds-and-lambda.template"
},
{
"ETag": "\"4b20b9c1dc2ae1522c51cdad5c6009ce\"",
"StorageClass": "STANDARD",
"Size": 2857,
"LastModified": "2018-11-04T20:08:29.000Z",
"Key": "2018308Ugb-rds-and-lambda.template"
},
Now we can modify the output with a query parameter. The query parameter supports the
petr@petr-VirtualBox:~$ aws --profile demo s3api list-objects --bucket cf-templates-1he2i9kkenjwe-eu-central-1 --output json --query "[sum(Contents[].Size), length(Contents[])]" [ 22833, 8 ]
Finally, we can put it all together:
for I in `aws --profile demo s3api list-buckets --query "Buckets[].Name" --output text`;
do aws s3api --profile demo list-objects --bucket $I --output json
--query "{\"$I\":{\"size\":sum(Contents[].Size), \"count\":length(Contents[])}}";
done
{
"cf-templates-1he2i9kkenjwe-eu-central-1": {
"count": 22833,
"size": 8
}
}{
"elasticbeanstalk-us-east-2-588956854787": {
"count": 6,
"size": 84688741
}
}
{
"test-userfiles-mobilehub-927286690": {
"size": 211857,
"count": 4
}
}
Maybe the last tweak can be to use the
jq -s
command to create a valid json output:
[
{
"cf-templates-1he2i9kkenjwe-eu-central-1": [
22833,
8
]
},
{
"elasticbeanstalk-us-east-2-588956854787": [
84688741,
6
]
},
{
"test-userfiles-mobilehub-927286690": [
211857,
4
]
}
]
The result is a valid json object which can be easily processed further.
Wanna bet on casino games?
ReplyDeleteWhen the wall street bets casino launches in 2021, it m 2 슬롯 will 마틴게일전략 offer many advantages over 넷마블바카라 the competition. To get the most out of your Rating: 7/10 · Review by Wooricasinos 프라그마틱 슬롯
A profitable mixture will be fashioned if you play independently. Bonus features will be activated if you land three or more 우리카지노 아벤카지노 scatters. Online slots can use scatters as both a trigger and wild symbol for bonus features. This is what is going on in Play n GO's Book of Dead on-line slot.
ReplyDeleteFirst depositors can take a spin of their wheel and earn a lot as} $1400 in bonus cash. When choosing an internet roulette site, it is important to look out for a site with an excellent catalog of roulette games and different on line casino games if attainable. This is outcome of|as a end result of} it's easier to maintain your funds in a particular on line 클레오카지노 casino you belief and like.
ReplyDeleteVerify your e mail handle with Bitstarz to assert 20 free spins – no deposit required. You’ll need to fund your account with $25 in cash or $20 via crypto to assert every portion of their nine-tiered welcome bundle. They accept Bitcoin, Litecoin, 먹튀검증 abc-1111 Ethereum, Tether, Flexepin, NeoSurf, and credit card payments. You’ll have 3 weeks to satisfy their playthrough and cash out a maximum of 30x your unique deposit. If you propose to go massive or go house, Red Dog places serious money on the desk. With Roulette Russia, players get to work together with dealers who speak their language and luxuriate in a localised environment.
ReplyDeleteFor instance, if the tenjō is 1,500, and the number of games performed for the reason that} final bonus is 1,490, the player is assured to launch a bonus within simply 10 games. Embrace the successful second and let your unforgettable journey unfold. Slots {are now|at the second are|are actually} out there on stage 2 and three including our new excessive restrict slots salon on stage 3. According to the playing professional, casinos declare to reward players with bonuses or free spins simply to encourage them to play at the slot machines longer. "These bonuses, nevertheless, usually have wagering necessities that have to be met before any winnings could be withdrawn," Good says. "This signifies that players will need to|might need to} wager a certain sum of money before they will xn--2q1br8z.com entry their winnings."
ReplyDeleteWith the improvement of know-how, the construction of the primary more powerful computer systems, and the event of programming languages, right now's slot games emerge. In the start, the most common fruits include a minimal number of lines, but over time, the machines are modernized, and increasingly more innovative designs are launched. 카지노 가입쿠폰 The most notable leap for slot machines comes in the 21st century when they are transferred to the webspace.
ReplyDeleteTo make deposits even simpler, you can to|you probably can} choose from a spread of payment strategies similar to financial institution switch, e-wallets, pay as you go cards and credit cards. Your deposits and withdrawals get processed shortly in a 1xbet korea safe digital surroundings, and the latest SSL knowledge encryption technology retains every thing safe and sound. JackpotCity is powered by award-winning software program from Microgaming, the world’s most progressive on-line game builders. Every game is graphic-rich and packed filled with exciting features, promising a superior, realistic expertise each time. The JackpotCity Casino Android APK has all the identical games, features, promotions, and banking options because the desktop website and is even simpler to use.
ReplyDeleteFaerie Spells and Caesar’s Empire 카지노사이트 are a number of the} online slots that pay the most. Real money mobile slots help a majority of the web casino market. They are tailor-made for phones and tablets with controls designed especially for touchscreens.
ReplyDelete