Skip to content

Aws

Rotate Access keys


You can have 2 access keys created. When I need to rotate my key I usually create a new one, make it active and test that it works. I'll then disable the old key and leave it there until next time I need to rotate my keys, then I delete the disabled key.

Create a new access key

aws iam create-access-key

Delete a access key

aws iam delete-access-key --access-key-id <access_key_id>

List an access key

aws iam list-access-keys

Disable old access key

aws iam update-access-key --access-key-id <access-key-id> --status Inactive

Script (work in progress)

aws iam delete-access-key --access-key-id $old_aws_access_key_id # delete old Inactive key
aws iam create-access-key | jq . # TODO: store access key and secret in env var.
aws configure set aws_access_key_id $new_aws_access_key_id
aws configure set aws_secret_access_key $new_aws_secret_access_key
aws iam update-access-key --access-key-id $old_aws_access_key_id --status Inactive
unset $old_aws_access_key_id $new_aws_access_key_id $new_aws_secret_access_key

Create ebs snapshot from instance ID

aws ec2 create-snapshots --copy-tags-from-source volume --instance-specification InstanceId=${InstanceID},ExcludeBootVolume=fals e