I have a list of AWS arns that I am iterating through.
I am trying to catch if the arn is in a list:
user_name = 'bluethundr'
for policy_arn in policy_arn_list:
print("Policy ARN: ", policy_arn)
if policy_arn == ('pol-aws-secrets-manager-' + user_name):
policy_exists = True
print("Policy exists is true.")
But the if
test is not catching the fact that the ARN already exists. Here is my output:
Policy ARN: arn:aws:iam::849355752309:policy/pol-iam
Policy ARN: arn:aws:iam::849355752309:policy/pol-rds
Policy ARN: arn:aws:iam::849355752309:policy/pol-s3
Policy ARN: arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-bluethundr
The ARN I am looking for is:
arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-bluethundr
I can verify that that ARN exists on the cli:
aws iam list-policies --scope Local --profile=jf-dev | jq -r '.Policies[].PolicyName' | grep bluethundr
pol-aws-secrets-manager-bluethundr
This is the contents of policy_arn_list
:
['arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-user2',
'arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-user4',
'arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-bluethundr',
'arn:aws:iam::849355752309:policy/pol-s3',
'arn:aws:iam::849355752309:policy/pol-ec2',
'arn:aws:iam::849355752309:policy/pol-rds',
'arn:aws:iam::849355752309:policy/pol-iam',
'arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-user1',
'arn:aws:iam::849355752309:policy/pol-aws-secrets-manager-user3']
What am I doing wrong? Why is the if test not seeing that the ARN I am looking for is already in the list?