Created
October 12, 2021 13:36
-
-
Save takakabe/4e6485b90cfa6ecb914e625a2bf38957 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
policy_arn='arn:aws:iam::account:policy/policy-name-with-path' | |
policy_file='iam_policy.json' | |
default_version_id=`aws iam get-policy --policy-arn ${policy_arn} | jq -r .Policy.DefaultVersionId` | |
policy_version_result=`aws iam list-policy-versions --policy-arn ${policy_arn}` | |
version_counts=`echo ${policy_version_result} | jq '.Versions | length'` | |
if [ ${version_counts} -eq 5 ]; then | |
aws iam delete-policy-version --policy-arn ${policy_arn} --version-id $(echo ${policy_version_result} \ | |
| jq -r '.Versions[-1].VersionId') | |
fi | |
aws iam create-policy-version --policy-arn ${policy_arn} --policy-document file://${policy_file} --set-as-default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment