Python + AWS Boto3 Complete Hands-on Guide
Iss lab guide me aap seekhenge ki Python aur boto3 library se AWS IAM Users kaise create karte hain. Simple English explanations aur lab ke saare original screenshots niche diye gaye hain!
1. Local Disk (E:) me
python/Create IAM folder setup karna.2. VS Code Terminal me
boto3 package install karna.3. Python script
createuser.py banana.4.
NoCredentialsError aur DNS Connection error fix karna.5. AWS Console me created users verify karna.
Create Folder & Open in VS Code
First, open Windows File Explorer on your computer. Go to Local Disk (E:), create a folder named python, and inside it create a folder called Create IAM[cite: 1].
This PC > Local Disk (E:) > python
Now open VS Code and open the Create IAM folder[cite: 1]. When VS Code asks: "Do you want to add containers for this workspace?", select No[cite: 1].
Check AWS Documentation & Install Boto3
Open official AWS Boto3 documentation page in Chrome browser (docs.aws.amazon.com/boto3/latest/guide/iam-example-managing-users.html)[cite: 1]:
Managing IAM users — Boto3 1.43.78 documentation
This Python example shows you how to create a user, list users, update a user name and delete a user using Amazon Web Services (AWS) SDK for Python[cite: 1].
Open VS Code terminal (`Ctrl + ~`) and type the command below to install Boto3 package[cite: 1]:
Create `createuser.py` & First Error
Create a new file named createuser.py in VS Code and write this simple Python code[cite: 1]:
⚠️ Error 1: NoCredentialsError
When you run python createuser.py in terminal, Python throws this error[cite: 1]:
Python cannot connect to AWS because AWS Access Key ID and AWS Secret Access Key are not configured on your computer yet[cite: 1].
Install AWS CLI v2 & Setup Credentials
To solve the error, download and install AWS Command Line Interface v2 Setup Wizard on Windows[cite: 1]:
Ready to install AWS Command Line Interface v2
Click Install to begin the installation on your computer[cite: 1].
Next, open AWS Console in Chrome. Go to IAM > Users > Create user to create user Sumit, attach policy IAMFullAccess, add tag Python_testing, and generate an Access Key selecting Local code option[cite: 1].
🔘 Local code: You plan to use this access key to enable application code in a local development environment to access your AWS account[cite: 1].
Python Boto3 IAM Lab | Access Key 1: JAQLULNYEYOKWMPJWI (Active)[cite: 1]
Now open PowerShell terminal and configure your keys[cite: 1]:
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: ap-south-1
Default output format [None]: json
{"UserId": "AIDAQLULNYEY...", "Account": "024988467504", "Arn": "arn:aws:iam::024988467504:user/Sumit"}
Fix DNS Error & Create User 'Python_lab'
When you update createuser.py to create user UserName='Python_lab' and run it, an internet DNS error might happen[cite: 1]:
Solution: Check network connection using nslookup iam.amazonaws.com and run the Python script again[cite: 1]:
Name: iam.amazonaws.com | Addresses: 64:ff9b::2cd8:ba56, 44.216.186.86
Verify in AWS Console & Run List Users Script
Open AWS IAM Console (us-east-1.console.aws.amazon.com/iam/home#/users). You can see both users Python_lab and Sumit created in your account[cite: 1]!
| User name | Path | Groups | Last activity |
|---|---|---|---|
| Python_lab | / | 0 | - |
| Sumit | / | 0 | 8 minutes ago |
Now create list_users.py to print all IAM users directly in your terminal[cite: 1]:
Complete AWS Boto3 DevOps Catalog (50 Projects)
Explore all 50 practical AWS Boto3 automation scripts covered in the document[cite: 1]: