Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
aws cli commands for day to day work

IAM

List users

aws iam list-users

Current user

aws iam get-user

List access key

aws iam list-access-keys

Crate new user

aws iam create-user --user-name username

Create policy

aws iam create-policy  --policy-name $POLICYNAME --policy-document file://${POLICY_JSON_FILE}

List policy attached to the role

aws iam list-attached-role-policies --role-name $role_name | jq -r .AttachedPolicies[].PolicyArn

Create Role

aws iam create-role --role-name $ROLENAME  --assume-role-policy-document file://${ACCESS POLICY JSON DOC}

Attach Role policy

aws iam attach-role-policy --role-name $ROLENAME --policy-arn $POLICY_ARN

To get details about the current IAM identity

aws sts get-caller-identity

S3

# list existing S3 buckets
aws s3 ls

# check if bucket exists or not 
aws s3api head-bucket  --bucket  $bucketname 
or
aws s3 ls | grep $bucket_name


# create a  bucket
aws s3api create-bucket  --bucket $bucket --region $region 

# put object 
aws s3api put-object  --bucket $bucket --key logs/

#### copy a object 
aws s3 cp file.txt s3://my-bucket/ 

#### copy to local 
aws s3 cp s3://bucketname/somefile.txt .  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment