Skip to content

Instantly share code, notes, and snippets.

@rajkrrsingh
Last active March 3, 2021 05:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajkrrsingh/5380ef6fb7c81cdfb947c7259d84b93d to your computer and use it in GitHub Desktop.
Save rajkrrsingh/5380ef6fb7c81cdfb947c7259d84b93d to your computer and use it in GitHub Desktop.
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