Hereβs a full step-by-step guide to:
- Create an IAM user in AWS
- Set up AWS CLI on a Windows computer
- Create a Python virtual environment and install boto3
- Create an S3 bucket
- Upload a file
- Set permissions using AWS CLI
π§βπ» Step 1: Create an IAM User (from AWS Console)
- Go to the IAM Console
- Click Users > Add users
- Set User name: e.g.,
aws-cli-user
- Check Programmatic access
- Click Next: Permissions
- Attach policies:
- Choose Attach existing policies directly
- Select
AmazonS3FullAccess
- Click Next > Create user
- Download or copy:
- Access key ID
- Secret access key
βοΈ Step 2: Install and Configure AWS CLI on Windows
- Download AWS CLI from: https://aws.amazon.com/cli/
- Install it and open Command Prompt
- Run: bashCopyEdit
aws configure
- Enter the credentials from IAM:
- AWS Access Key ID
- AWS Secret Access Key
- Region (e.g.,
us-east-1
) - Output format (e.g.,
json
)
π Step 3: Create Python Virtual Environment & Install boto3
- Open Command Prompt in your project directory.
- Run: bashCopyEdit
python -m venv venv .\venv\Scripts\activate pip install boto3
βοΈ Step 4: Create an S3 Bucket Using AWS CLI
S3 bucket names must be globally unique.
aws s3api create-bucket --bucket my-unique-bucket-name-123 --region us-east-1
For other regions:
aws s3api create-bucket --bucket my-unique-bucket-name-123 --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2
π Step 5: Upload a File to the S3 Bucket
aws s3 cp myfile.txt s3://my-unique-bucket-name-123/
π Step 6: Set Permissions (Make Public or Set Bucket Policy)
Option 1: Make the object public
aws s3api put-object-acl --bucket my-unique-bucket-name-123 --key myfile.txt --acl public-read
Option 2: Add a bucket policy (e.g., allow public read to all files in the bucket)
Create a file bucket-policy.json
:
jsonCopyEdit{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-unique-bucket-name-123/*"
}
]
}
Apply it:
aws s3api put-bucket-policy --bucket my-unique-bucket-name-123 --policy file://bucket-policy.json