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' '...
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
...
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 ...
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 ...
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. ...
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-...
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 ...
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.
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 ...
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[...
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.
...
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 ...
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;...
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 ...
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.
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/...
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 ...
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 ...
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 ...
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 "...
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 ...
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 ...
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 ...
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 ...
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/...
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 ...
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 --...
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.
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 ...
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 --...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
aws-cli × 47amazon-web-services × 22
amazon-ec2 × 11
amazon-s3 × 6
kubernetes × 3
terraform × 3
python × 3
amazon-ecs × 3
aws-iam × 3
chef × 2
amazon-sqs × 2
docker × 1
azure-devops × 1
gitlab × 1
deployment × 1
linux × 1
security × 1
azure-pipelines × 1
yaml × 1
autoscaling × 1
kubectl × 1
aws-cloudformation × 1
amazon-rds × 1
amazon-cloudwatch × 1
encryption × 1