Skip to content

Instantly share code, notes, and snippets.

@timmow
Created March 17, 2016 16:08
Show Gist options
  • Save timmow/c955f5fbc9d08ef8848c to your computer and use it in GitHub Desktop.
Save timmow/c955f5fbc9d08ef8848c to your computer and use it in GitHub Desktop.
Create aws users password / key and encrypt
#!/bin/bash
set -euo pipefail
function create_user {
USERNAME=$1
RECIPIENT=$2
aws iam create-user --user-name $USERNAME
ACCESS_KEY_JSON=$(aws iam create-access-key --user-name $USERNAME)
ACCESS_KEY_ID=$(echo $ACCESS_KEY_JSON | jq -r '.[] | .AccessKeyId')
SECRET_ACCESS_KEY=$(echo $ACCESS_KEY_JSON | jq -r '.[] | .SecretAccessKey')
aws iam add-user-to-group --user-name $USERNAME --group-name Contractors
gpg --output $USERNAME-$AWS_ACCOUNT.gpg --encrypt --recipient $RECIPIENT <<EOF
ACCESS_KEY_ID: $ACCESS_KEY_ID
SECRET_ACCESS_KEY: $SECRET_ACCESS_KEY
EOF
}
function create_password {
USERNAME=$1
RECIPIENT=$2
PASSWORD=$(apg -a1 -n1 -m10)
aws iam create-login-profile --user-name $USERNAME --password $PASSWORD --password-reset-required
gpg --output $USERNAME-$AWS_ACCOUNT-password.gpg --encrypt --recipient $RECIPIENT <<EOF
Password: $PASSWORD
EOF
}
export AWS_ACCOUNT=dev
create_user test [email protected]
create_password test [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment