Hello, I am tryng to do the following
$CHECK_IF_POLICY_EXISTS=`aws iam get-policy --policy-arn "${QUEUE_POLICY_ACCESS_ARN}"`
if [[ $CHECK_IF_POLICY_EXISTS == *"was not found"* ]]; then
echo "Creating Policy '${QUEUE_POLICY_ACCESS_ARN}'"
else
echo "Policy '${QUEUE_POLICY_ACCESS_ARN}' already exists"
fi
The problem is that the command aws iam get-policy can result in an 254 error with a string similar to:
An error occurred (NoSuchEntity) when calling the GetPolicy operation: Policy arn:aws:iam::123456789:policy/policy-name was not found.
With that, the pipeline will break but I do not want this. I always want the string result of the command.
I tried to do
$CHECK_IF_POLICY_EXISTS=`aws iam get-policy --policy-arn "${QUEUE_POLICY_ACCESS_ARN}"` || true
The pipeline will not break but $CHECK_IF_POLICY_EXISTS is not filled with the string result.