Your organization is running a database in different account which is present is zone with id eu-w3-az1. You are also asked to create an ec2 instance in the same AZ. We need to figure out matching zone name
Now we are asked to delete all the policies which are customer managed Refer Here
We need policy arns
Consider the following script
#!/bin/bash
policy_arn=$(aws iam list-policies --scope Local --query 'Policies[].Arn|[0]' --output text)
echo "found ${policy_arn}"
while [[ ! -z "$policy_arn" ]]
do
# lets get first arn
echo "The policy arn to be deleted is ${policy_arn}"
aws iam delete-policy --policy-arn ${policy_arn} --output text
echo "The policy arn is successfully deleted"
policy_arn=$(aws iam list-policies --scope Local --query 'Policies[].Arn|[0]' --output text)
done
The problem with above approach is it might never end.
other approach: Get all the policy arns into an array and write a while or foreach loop over array. This will never be infinite loop.
Activity 3 – Tagging and filtering the resources based on tags
Resource Tags
helps in filtering the resources
filter the bills based on tags.
Lets create an ec2 instance and then add the following tags
Project = qtworkshop
Env = test
team = qtaws
release = v1.0
From cli
Now try using aws ec2 create-tag for tagging your ec2 instance with the above tags.
Activity 7: Delete all the security groups in all regions
Delete all the security groups in all regions in all vpcs except default
* Get vpc ids of the current region
* for each vpc id get all security group ids
* delete the security group if the name is not default or it is not default
* Then do this activity for all the active regions in your account.