Skip to main content
20 votes
Accepted

View all AWS S3 buckets and list each buckets storage used

Resolution 1 So I solved this with the following script. I originally posted the question just in case there was an easier way that I was not aware of. #!/bin/bash aws_profile=('profile1' 'profile2' '...
Kyle Steenkamp's user avatar
15 votes
Accepted

How to run a script or a command on EC2 instance via AWS CLI?

To run ipconfig from the AWS Systems Manager Run Command: $ aws ssm send-command --document-name "AWS-RunPowerShellScript" --instance-ids "<your instance id>" --parameters commands=ipconfig ...
swysocki's user avatar
  • 838
11 votes
Accepted

How to get environment variables in ECS container?

Environment variables are defined inside the container and some are passed in the task definition. So you can use describe-task-definition to see the extra variables. To get the default environment ...
Jiri Klouda's user avatar
  • 5,837
10 votes
Accepted

Running a command as a specific user on an ec2 using ssm

I didn't find anything on AWS or boto3 docs that allows for that, but I was able to execute as a different user using the runuser command. In theory, you could do the same thing with a combination of ...
M. Gleria's user avatar
  • 216
7 votes
Accepted

How to find out the used Key pair name via AWS CLI?

For a given instance, you would first use aws ec2 describe-instances to get the information JSON for your instance. The information also contains the keypair name used to create that instance. E.g. ...
Vish's user avatar
  • 601
7 votes

How to run a script or a command on EC2 instance via AWS CLI?

Here is a helper Bash script which uses aws ssm send-command to run the commands: #/usr/bin/env bash -x # Script to run PowerShell script on the Windows instance. instanceId="$1" cmdId=$(aws ssm send-...
kenorb's user avatar
  • 7,981
7 votes

How to set up AWS Trusted Advisor alert for Service Limit warnings?

That's on my backlog but still on early stage, I just surfaced the idea, so here's are my findings so far: Using Trusted Advisor as a Web Service Mainly: Poll a Trusted Advisor Check for Status ...
Tensibai's user avatar
  • 11.4k
6 votes
Accepted

How to avoid output being truncated when running AWS SSM command?

According to this ssm tutorial, SSM send-command output is truncated at 2500 characters. To work around that, you must send your output to an S3 bucket using the --output-s3-bucket-name parameter.
swysocki's user avatar
  • 838
5 votes

View all AWS S3 buckets and list each buckets storage used

You will need to write a script that parses and queries this data because as far as I'm aware, there is not a tool or cli function that performs this. Luckily, you can gather all of this information ...
Preston Martin's user avatar
  • 3,278
5 votes

How to list security groups for the specific instance via CLI?

The following one-liner in shell works for me: aws ec2 describe-security-groups --group-ids $(aws ec2 describe-instances --instance-id $id --query "Reservations[].Instances[].SecurityGroups[].GroupId[...
kenorb's user avatar
  • 7,981
5 votes

How to avoid output being truncated when running AWS SSM command?

Here is a helper Bash script which uses aws ssm send-command with --output-s3-bucket-name parameter to run the command and the result is stored in the S3 bucket, then displayed to the standard output. ...
kenorb's user avatar
  • 7,981
5 votes

How to see when an AWS IAM role was last used?

Amazon CloudTrail tracks all API use In CloudTrail create a new trail You can configure each trail to send log events to CloudWatch: Edit the trail and choose to send Logs to CloudWatch. It will ...
jdog's user avatar
  • 650
4 votes

How to find out the used Key pair name via AWS CLI?

Based on @Vish answer, I've created the following shell script: #/usr/bin/env bash # Script to show password data of the EC2 instance. [ $# -eq 0 ] && { echo "Usage: $0 instance_id ..."; exit;...
kenorb's user avatar
  • 7,981
4 votes
Accepted

How to export EC2 snapshot into S3 bucket?

EBS Snapshots aren't really disk image files. They're logical containers of pointers to chunks of compressed and deduplicated backup data that EBS stores in S3 when you create snapshots -- but these ...
Michael - sqlbot's user avatar
4 votes
Accepted

How to list security groups for the specific instance via CLI?

You can use aws ec2 describe-instances instead, you can specify the id --instance-ids <value> and it will output the security group.
MonkeyMagic's user avatar
4 votes
Accepted

Was AWS Secrets Manager removed from AWS CLI commands?

AWS secrets are still accessible via the CLI. The link you provided goes to an old version of the AWS CLI. Check out the latest version and commands here: https://awscli.amazonaws.com/v2/...
Wesley Rolnick's user avatar
3 votes

How to run a script or a command on EC2 instance via AWS CLI?

Here is something super cool I do with AWS SSM Send-Command! Using Apache Airflow I create a brand new EC2-Instance using a Cloud Formation Template (or CFT for short) that's just a JSON file with ...
Kyle Bridenstine's user avatar
3 votes

How to run a script or a command on EC2 instance via AWS CLI?

Yes, you can do this with AWS Systems manager. AWS Systems Manager Run Command allows you to remotely and securely run set of commands on EC2 as well on-premise server. Below are high-level steps to ...
ExploringApple's user avatar
3 votes

List encrypted RDS snapshots using CLI

Either use the --query attribute aws rds describe-db-snapshots --query "DBSnapshots[?Encrypted].DBSnapshotIdentifier" If the [?Encrypted] does not work, try [?Encrypted == 'true'] as the first is ...
Jiri Klouda's user avatar
  • 5,837
3 votes

View all AWS S3 buckets and list each buckets storage used

Easiest way to see this information nowadays is using S3 Storage Lens. S3 dashboard > S3 storage lens (left navigation pane) > default-account-dashboard > Buckets tab Scroll down to the "...
A. Kendall's user avatar
3 votes
Accepted

How to see when an AWS IAM role was last used?

I've been meaning to come back to this. After consulting with AWS support it would seem that this is possible using some functions of the AWS CLI, that I was not aware of. Specifically they ...
Uberhumus's user avatar
  • 297
3 votes

How to see when an AWS IAM role was last used?

This is possible using AWS SDKs. I was cleaning my tabs after finishing this task and decided I would write an answer to help other people. Versions: aws-cli/2.0.61 go1.15.3 linux/amd64 Let's do ...
alban boitier's user avatar
3 votes
Accepted

Cross account access from ec2 to other accounts

Supposing the scenario with two accounts A & B the explanatory steps should be: In account A, I created a role (e.g RoleForB) to trust account B, and attach to the before created role a IAM ...
Chan Nyein Ko Ko's user avatar
3 votes

How to install aws cli on a self-hosted azure DevOps Windows agent?

The best way to have AWS CLI tooling installed to your custom agent is by installing from Visual Studio Marketplace. AWS CLI is part of AWS Tools for Azure DevOps Service and Azure DevOps Server (the ...
Eriawan Kusumawardhono's user avatar
3 votes

Get tagging to work on AWS CLI

I think this is because your ECS service was created before tagging was available for ECS services. See this blog post by AWS on how to migrate to the new ARN format. https://aws.amazon.com/blogs/...
Levi's user avatar
  • 1,064
2 votes

View all AWS S3 buckets and list each buckets storage used

You're going to have to write a script to do this unless there's a tool to do it that I can't find. If you're working with multiple aws accounts you'll need to be switching between accounts to get ...
Briansbum's user avatar
  • 1,112
2 votes
Accepted

How can I get a list of encrypted disks for instances that are running on the AWS CLI?

Here is what I ended up using. Enjoy. for instance in $instances; do count=`aws ec2 describe-volumes --filters Name=attachment.status,Values=attached Name=attachment.instance-id,Values=$instance --...
hawkeye's user avatar
  • 1,153
2 votes

Amazon EKS from local kubectl does not cache MFA token/session

Btw: I managed to fix this problem by using aws-mfa (https://github.com/broamski/aws-mfa), which I have configured to cache my aws credentials for an hour.
Max N.'s user avatar
  • 413
2 votes
Accepted

Amazon EKS from local kubectl does not cache MFA token/session

Indeed, this is a pain. I've been fighting with it for the whole day yesterday, but managed to get it working, let's see if our cases are similar enough. My guess is that the usual aws configure ...
mrArias's user avatar
  • 136
2 votes
Accepted

AWS Security Group Creation Using AWS CLI

Ok I got the answer after exploring few things and looking at the error more attentively. Here is the way: aws ec2 authorize-security-group-ingress --group-id sg-07xxxx24d --protocol tcp --port 22 --...
Prashast's user avatar

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