Hot answers tagged

474 votes

How can I get the size of an Amazon S3 bucket?

This can now be done trivially with just the official AWS command line client: aws s3 ls --summarize --human-readable --recursive s3://bucket-name/ Official Documentation: AWS CLI Command Reference (...
  • 4,914
212 votes
Accepted

How can I get the size of an Amazon S3 bucket?

The AWS CLI now supports the --query parameter which takes a JMESPath expressions. This means you can sum the size values given by list-objects using sum(Contents[].Size) and count like length(...
179 votes

How can I get the size of an Amazon S3 bucket?

AWS Console: As of 28th of July 2015 you can get this information via CloudWatch. If you want a GUI, go to the CloudWatch console: (Choose Region > ) Metrics > S3 AWS CLI Command: This is much ...
  • 1,974
65 votes
Accepted

Download SSL certificate from aws certificate manager

You cannot download a SSL certificate from ACM.
  • 32.6k
33 votes

Elastic Beanstalk stuck for more than 12 hrs

If you know how to fix the source of problem (for example: change application settings in Beanstalk Environment variables or deploy fixed version of your application), then: Go to page Auto Scaling ...
32 votes
Accepted

Recursively changing the content-type for files of a given extension on Amazon S3

Here is an example how to do this with the aws cli tool. The cp tool allows the use of a recursive options, which I don't think the s3api tool can do. In this case, I'm fixing a bunch of SVGs. ...
  • 436
30 votes
Accepted

Deleting S3 files with a given prefix only

You can use aws s3 rm command using the --include and --exclude parameters to specify a pattern for the files you'd like to delete. So in your case, the command would be: aws s3 rm s3://bucket/ --...
  • 3,047
29 votes
Accepted

How to add a Tag when launching an ec2 instance using aws clis

As of 28 March 2017, you can specify tags for instances (and attached volumes) as part of the run-instances command. Example: aws ec2 run-instances --image-id ami-abc12345 --count 1 \ --instance-...
  • 566
28 votes

How would you go about listing instances using aws cli in certain VPC with the Tag Name, private IP address of instance and instance id?

You need to escape the backslashes in order to format the answer correctly. aws ec2 describe-instances --query 'Reservations[].Instances[].[PrivateIpAddress,Tags[?Key==`Name`].Value[]]' --output text ...
28 votes

How can I get the size of an Amazon S3 bucket?

If you want to get the size from AWS Console: Go to S3 and select the bucket Click on "Metrics" tab By default you should see Total bucket size metrics on the top
24 votes
Accepted

Is it possible to get aws ec2 instance id based on its IP address

aws ec2 describe-instances --filter Name=ip-address,Values=IP_1,..IP_N Should do what you need. use the filter name of private-ip-address to select using private address in your VPC. Pipe through ...
  • 366
24 votes
Accepted

How to find out an ec2 instance's private and public IP via aws cli?

Generally you can do it with --query filter. If you need the private IP address only: aws --region YOUR-AWS-REGION \ ec2 describe-instances \ --filters \ "Name=instance-state-name,Values=running" \ "...
22 votes

How can I get the size of an Amazon S3 bucket?

Using the official AWS s3 command line tools: aws s3 ls s3://bucket/folder --recursive | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}' This is a better command, just add the ...
  • 321
21 votes

Download SSL certificate from aws certificate manager

Note: While this can be used to fetch the (already public) certificate, it does not download the private key necessary to use that certificate outside Amazon's systems. It is now possible to download ...
21 votes

2 ELBs (ALBs) to 1 target group, possible?

I'm not sure if you can point two ALBs to a single TargetGroup. However since you mentioned AutoScaling you can have the ASG instances automatically registered in more than one TargetGroups, therefore ...
  • 24k
18 votes

aws-cli describe-instances, find by date range

Found on Use filter "launch-time" to find all instances newer than X date? using JMESPath query: aws ec2 describe-instances --query 'Reservations[].Instances[?LaunchTime>=`2015-03-01`][].{id: ...
18 votes
Accepted

How to “switch role” in aws-cli?

Of course it's possible! Let's assume you've got your Login account credentials in ~/.aws/credentials, probably something like this: ~ $ cat ~/.aws/credentials [customer-login] aws_access_key_id = ...
  • 24k
16 votes

What is causing Access Denied when using the aws cli to download from Amazon S3?

When I faced the same issue it turned out that AWS required server-side encryption to be enabled. So the following command worked successfully for me: aws s3 cp test.txt s3://my-s3-bucket --sse ...
  • 261
15 votes

How can I get the size of an Amazon S3 bucket?

s4cmd is the fastest way I've found (a command-line utility written in Python): pip install s4cmd Now to calculate the entire bucket size using multiple threads: s4cmd du -r s3://bucket-name
15 votes
Accepted

The config profile (adminuser) could not be found

I finally succeed by using ~/.aws/config [default] region = us-east-1 output = json ~/.aws/credentials [adminuser] // <- here changes to adminuser aws_access_key_id = ************ ...
14 votes
Accepted

Access Denied when syncing between s3 buckets on different AWS accounts

The cause of your ListObjects error is that you assigned permission to access the contents of your bucket (arn:aws:s3:::bucket/*) but you did not give permissions to the bucket itself (arn:aws:s3:::...
14 votes

Deleting S3 files with a given prefix only

As a complement to @sippybear's excellent answer, I would recommend the following, if somebody has a bucket with a trillion objects and the pattern of the files one wants to delete includes "...
  • 323
13 votes

Export my whole AWS architecture into file?

You can use CloudFormer to export your existing AWS infrastructure into CloudFormation template. Alternatively you can use terraforming ruby gem to export your infrastructure as Terraform files.
  • 8,249
12 votes
Accepted

How to check via aws cli if a specific rds instance exists?

Notice the constraint in the docs when using --db-instance-indentifier: --db-instance-identifier (string) The user-supplied instance identifier. If this parameter is specified, information from ...
  • 7,425
11 votes

Search ec2 instance by its name from aws command line tool

You can further filter with name, instance id and private ip with below, aws ec2 describe-instances --filters "Name=tag:Name,Values=*myinstance*" --output json --query 'Reservations[*].Instances[*].[...
11 votes

How would you go about listing instances using aws cli in certain VPC with the Tag Name, private IP address of instance and instance id?

Try this aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value|[0],State.Name,PrivateIpAddress,PublicIpAddress]' --output text | column -t
  • 111
11 votes
Accepted

Why can't I capture AWS EC2 CLI Output in Bash?

The > operator only redirects stdout ("standard output"), or "file descriptor 1". Error messages are usually printed on a different file descriptor, 2, stderr, ("standard error"). On your terminal ...
  • 1,127
11 votes
Accepted

python boto3 allow ingress security groups

The 2 different classes are about different levels of abstraction. Client classes are low level wrappers around each API action. ie. AuthorizeSecurityGroupIngress Resource classes are object ...
  • 1,282
11 votes
Accepted

Download EBS volume or snapshot to file

AWS don't provide a way to download or extract the actual block device that makes up an EBS volume. The standard way to grab a copy is to use rsync, but as you're after a block level way of doing this,...
  • 963
11 votes
Accepted

How to set name in command line when running `aws ec2 run-instances

The Name that's displayed there is taken from the Name tag. To set the instance name e.g. to test01 and its volume name to test01-disk1 you'd run something like this: aws ec2 run-instances --tag-...
  • 24k

Only top scored, non community-wiki answers of a minimum length are eligible