Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Hot answers tagged

18 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' ...
user avatar
14 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 ...
user avatar
  • 708
10 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 ...
user avatar
  • 5,607
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. ...
user avatar
  • 601
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 ...
user avatar
  • 11k
5 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-...
user avatar
  • 7,021
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 ...
user avatar
  • 650
5 votes

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 ...
user avatar
  • 151
4 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.
user avatar
  • 708
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.
user avatar
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;...
user avatar
  • 7,021
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 ...
user avatar
3 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. ...
user avatar
  • 7,021
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 ...
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 ...
user avatar
3 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[...
user avatar
  • 7,021
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 ...
user avatar
  • 5,607
3 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 ...
user avatar
  • 2,973
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 ...
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 ...
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 ...
user avatar
3 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/...
user avatar
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 ...
user avatar
  • 1,082
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 --...
user avatar
  • 1,073
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.
user avatar
  • 343
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 ...
user avatar
  • 136
2 votes

Configure AWS cli inside chef cookbook

Have you tried setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables? By setting these variables before you run your cli commands, you should not have to run the aws configure ...
user avatar
  • 2,973
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 --...
user avatar
2 votes

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

There currently is no method using SDKs for the AWS CLI to get the last accessed time of an IAM role. Currently, the only way is to use the AWS Management Console. Select your IAM role and explore ...
user avatar
  • 1,341
2 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 ...
user avatar
  • 277

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